summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Helfrich <helfrich9000@gmail.com>2008-02-07 03:24:17 +0000
committerBrian Helfrich <helfrich9000@gmail.com>2008-02-07 03:24:17 +0000
commitb7556e6693c14cea10a511ac88cb6d54a6721cb3 (patch)
treef1be044bb7613f94b0d70e7ba4fbce602553ed89
parent65cdce7e549a4a38dd5b2f368f2458c8f75b138b (diff)
downloadnanoengineer-theirix-b7556e6693c14cea10a511ac88cb6d54a6721cb3.tar.gz
nanoengineer-theirix-b7556e6693c14cea10a511ac88cb6d54a6721cb3.zip
NV1 can now be launched from NE1 with a growing data store which it shows in a TrajectoryGraphicsPane textually.
-rw-r--r--cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h2
-rw-r--r--cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h1
-rwxr-xr-xcad/plugins/NanoVision-1/include/Nanorex/Utility/NXCommandLine.h252
-rw-r--r--cad/plugins/NanoVision-1/include/Nanorex/Utility/NXLogger.h24
-rw-r--r--cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp2
-rw-r--r--cad/plugins/NanoVision-1/src/KDevelop/Utility/Utility.pro6
-rw-r--r--cad/plugins/NanoVision-1/src/LogHandlerWidget.cpp27
-rw-r--r--cad/plugins/NanoVision-1/src/ResultsWindow.cpp15
-rw-r--r--cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.cpp34
-rw-r--r--cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.h22
-rw-r--r--cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.ui9
-rwxr-xr-xcad/plugins/NanoVision-1/src/Utility/NXCommandLine.cpp334
-rw-r--r--cad/plugins/NanoVision-1/src/main.cpp2
-rw-r--r--cad/plugins/NanoVision-1/src/nv1.cpp21
-rw-r--r--cad/plugins/NanoVision-1/src/nv1.h3
15 files changed, 716 insertions, 38 deletions
diff --git a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h
index 1b20bef86..d743816c3 100644
--- a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h
+++ b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXDataStoreInfo.h
@@ -20,6 +20,8 @@ class NXDataStoreInfo {
public:
NXDataStoreInfo() { }
+ // TODO: check for existence in getters
+
// Filenames
const string& getFilename(int frameSetId) {
return _filenames[frameSetId];
diff --git a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h
index 4fa1596f0..b1955f355 100644
--- a/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h
+++ b/cad/plugins/NanoVision-1/include/Nanorex/Interface/NXEntityManager.h
@@ -121,7 +121,6 @@ public:
!dataStoreInfo->isLastFrame(frameSetId)) {
// See if there's a new frame
-printf(" x ");fflush(0);
result =
entityManager->importFromFile
(dataStoreInfo->getFilename(frameSetId), frameSetId,
diff --git a/cad/plugins/NanoVision-1/include/Nanorex/Utility/NXCommandLine.h b/cad/plugins/NanoVision-1/include/Nanorex/Utility/NXCommandLine.h
new file mode 100755
index 000000000..503c4fc52
--- /dev/null
+++ b/cad/plugins/NanoVision-1/include/Nanorex/Utility/NXCommandLine.h
@@ -0,0 +1,252 @@
+/*------------------------------------------------------
+ CCmdLine
+
+ A utility for parsing command lines.
+
+ Copyright (C) 1999 Chris Losinger, Smaller Animals Software.
+ http://www.smalleranimals.com
+
+ This software is provided 'as-is', without any express
+ or implied warranty. In no event will the authors be
+ held liable for any damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software
+ for any purpose, including commercial applications, and
+ to alter it and redistribute it freely, subject to the
+ following restrictions:
+
+ 1. The origin of this software must not be misrepresented;
+ you must not claim that you wrote the original software.
+ If you use this software in a product, an acknowledgment
+ in the product documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such,
+ and must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+
+ -------------------------
+
+ Example :
+*/
+/*! \class Nanorex::NXCommandLine
+
+ Note: This class is a derivative work of Chris Losinger's CCmdLine class
+ Copyright (C) 1999 Chris Losinger, Smaller Animals Software
+ (www.smalleranimals.com).
+ Nano-Hive added the
+ \code int SplitLine(const char *line); \endcode function and made the
+ documentation Doxygen friendly.
+
+ Our example application uses a command line that has two
+ required switches and two optional switches. The app should abort
+ if the required switches are not present and continue with default
+ values if the optional switches are not present.
+
+ Sample command line :
+ \code
+ MyApp.exe -p1 text1 text2 -p2 "this is a big argument" -opt1 -55 -opt2
+ \endcode
+
+ Switches -p1 and -p2 are required.
+ p1 has two arguments and p2 has one.
+
+ Switches -opt1 and -opt2 are optional.
+ opt1 requires a numeric argument.
+ opt2 has no arguments.
+
+ Also, assume that the app displays a 'help' screen if the '-h' switch
+ is present on the command line.
+
+ \code
+ #include "Nanorex/Utility/NXCommandLine.h"
+
+ void main(int argc, char **argv)
+ {
+ // our cmd line parser object
+ Nanorex::NXCommandLine cmdLine;
+
+ // parse argc,argv
+ if (cmdLine.SplitLine(argc, argv) < 1)
+ {
+ // no switches were given on the command line, abort
+ ASSERT(0);
+ exit(-1);
+ }
+
+ // test for the 'help' case
+ if (cmdLine.HasSwitch("-h"))
+ {
+ show_help();
+ exit(0);
+ }
+
+ // get the required arguments
+ StringType p1_1, p1_2, p2_1;
+ try
+ {
+ // if any of these fail, we'll end up in the catch() block
+ p1_1 = cmdLine.GetArgument("-p1", 0);
+ p1_2 = cmdLine.GetArgument("-p1", 1);
+ p2_1 = cmdLine.GetArgument("-p2", 0);
+
+ }
+ catch (...)
+ {
+ // one of the required arguments was missing, abort
+ ASSERT(0);
+ exit(-1);
+ }
+
+ // get the optional parameters
+
+ // convert to an int, default to '100'
+ int iOpt1Val = atoi(cmdLine.GetSafeArgument("-opt1", 0, 100));
+
+ // since opt2 has no arguments, just test for the presence of
+ // the '-opt2' switch
+ bool bOptVal2 = cmdLine.HasSwitch("-opt2");
+
+ .... and so on....
+
+ }
+ \endcode
+*/
+/*
+ If this class is used in an MFC application, StringType is CString, else
+ it uses the STL 'string' type.
+
+ If this is an MFC app, you can use the __argc and __argv macros from
+ you CYourWinApp::InitInstance() function in place of the standard argc
+ and argv variables.
+
+------------------------------------------------------*/
+#ifndef NH_CMDLINE_H
+#define NH_CMDLINE_H
+
+
+#define StringType std::string
+
+
+#ifdef WIN32
+# ifdef _MSC_VER
+# pragma warning(disable:4786)
+# endif
+#endif
+
+#include <iostream>
+#include <map>
+#include <string>
+#include <vector>
+
+namespace Nanorex {
+
+/* Container for the CmdLine argument vector. */
+/**
+ * Used internally by nanohive::CmdLine.
+ */
+struct CCmdParam
+{
+ std::vector<StringType> m_strings;
+};
+
+// this class is actually a map of strings to vectors
+typedef std::map<StringType, CCmdParam> _CCmdLine;
+
+/**
+ * Command-line parser class.
+ * @ingroup NanoHiveUtil
+ */
+class NXCommandLine : public _CCmdLine
+{
+
+public:
+ /**
+ Parse the command line into switches and arguments.
+
+ @return Number of switches found
+ */
+ int SplitLine(int argc, char **argv);
+
+ /**
+ Parse the given line into switches and arguments.
+
+ @return Number of switches found
+ */
+ int SplitLine(const char *line);
+
+ /**
+ Was the switch found on the command line ?
+
+ example :
+ \code
+ app.exe -a p1 p2 p3 -b p4 -c -d p5
+
+ call return
+ ---- ------
+ cmdLine.HasSwitch("-a") true
+ cmdLine.HasSwitch("-z") false
+ \endcode
+ */
+ bool HasSwitch(const char *pSwitch);
+
+ /**
+ Fetch an argument associated with a switch . if the parameter at
+ index iIdx is not found, this will return the default that you
+ provide.
+
+ example :
+ \code
+ app.exe -a p1 p2 p3 -b p4 -c -d p5
+
+ call return
+ ---- ------
+ cmdLine.GetSafeArgument("-a", 0, "zz") p1
+ cmdLine.GetSafeArgument("-a", 1, "zz") p2
+ cmdLine.GetSafeArgument("-b", 0, "zz") p4
+ cmdLine.GetSafeArgument("-b", 1, "zz") zz
+ \endcode
+ */
+ StringType GetSafeArgument(const char *pSwitch, int iIdx, const char *pDefault);
+
+ /**
+ Fetch a argument associated with a switch. throws an exception
+ of (int)0, if the parameter at index iIdx is not found.
+
+ example :
+ \code
+ app.exe -a p1 p2 p3 -b p4 -c -d p5
+
+ call return
+ ---- ------
+ cmdLine.GetArgument("-a", 0) p1
+ cmdLine.GetArgument("-b", 1) throws (int)0, returns an empty string
+ \endcode
+ */
+ StringType GetArgument(const char *pSwitch, int iIdx);
+
+ /**
+ @return The number of arguments found for a given switch. -1 if the
+ switch was not found
+ */
+ int GetArgumentCount(const char *pSwitch);
+
+protected:
+ /*------------------------------------------------------
+
+ protected member function
+ test a parameter to see if it's a switch :
+
+ switches are of the form : -x
+ where 'x' is one or more characters.
+ the first character of a switch must be non-numeric!
+
+ ------------------------------------------------------*/
+ bool IsSwitch(const char *pParam);
+};
+
+} // Nanorex::
+
+#endif
+
diff --git a/cad/plugins/NanoVision-1/include/Nanorex/Utility/NXLogger.h b/cad/plugins/NanoVision-1/include/Nanorex/Utility/NXLogger.h
index ce481a1a6..a7acbdc99 100644
--- a/cad/plugins/NanoVision-1/include/Nanorex/Utility/NXLogger.h
+++ b/cad/plugins/NanoVision-1/include/Nanorex/Utility/NXLogger.h
@@ -65,7 +65,7 @@ class NXLogHandler {
virtual void publish(LogRecord logRecord) = 0;
- private:
+ protected:
NXLogLevel logLevel;
};
@@ -157,15 +157,17 @@ class NXConsoleLogHandler : public NXLogHandler {
public:
NXConsoleLogHandler(NXLogLevel logLevel) : NXLogHandler(logLevel) { }
void publish(LogRecord logRecord) {
- mutex.lock();
- printf("%s [%-7s] %s %s\n",
- qPrintable(logRecord.getDateTime()
- .toString("yyyy-MM-dd hh:mm:ss.zzz")),
- LogLevelNames[logRecord.getLogLevel()],
- (logRecord.getSource().length() == 0 ?
- "" : logRecord.getSource().append(":").c_str()),
- logRecord.getMessage().c_str());
- mutex.unlock();
+ if (logRecord.getLogLevel() >= logLevel) {
+ mutex.lock();
+ printf("%s [%-7s] %s %s\n",
+ qPrintable(logRecord.getDateTime()
+ .toString("yyyy-MM-dd hh:mm:ss.zzz")),
+ LogLevelNames[logRecord.getLogLevel()],
+ (logRecord.getSource().length() == 0 ?
+ "" : logRecord.getSource().append(":").c_str()),
+ logRecord.getMessage().c_str());
+ mutex.unlock();
+ }
}
private:
@@ -200,7 +202,7 @@ class NXFileLogHandler : public NXLogHandler {
fclose(filehandle);
}
void publish(LogRecord logRecord) {
- if (filehandle != 0) {
+ if ((filehandle != 0) && (logRecord.getLogLevel() >= logLevel)) {
mutex.lock();
fprintf(filehandle,"%s [%-7s] %s %s\n",
qPrintable(logRecord.getDateTime()
diff --git a/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp b/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp
index e783c4111..82efcd9d5 100644
--- a/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp
+++ b/cad/plugins/NanoVision-1/src/Interface/NXEntityManager.cpp
@@ -155,6 +155,7 @@ NXCommandResult* NXEntityManager::importFromFile(const string& filename,
} else {
int idx = addFrame(frameSetId, moleculeSet);
if (inPollingThread) {
+ NXLOG_DEBUG("NXEntityManager", "emit newFrameAdded()");
emit newFrameAdded(frameSetId, frameIndex, moleculeSet);
}
}
@@ -172,6 +173,7 @@ NXCommandResult* NXEntityManager::importFromFile(const string& filename,
dataStoreInfo, filename,
frameSetId, frameIndex);
if (inPollingThread) {
+ NXLOG_DEBUG("NXEntityManager", "emit newFrameAdded()");
emit newFrameAdded(frameSetId, frameIndex,
getRootMoleculeSet(frameSetId,
frameIndex));
diff --git a/cad/plugins/NanoVision-1/src/KDevelop/Utility/Utility.pro b/cad/plugins/NanoVision-1/src/KDevelop/Utility/Utility.pro
index cb329d21f..fafaa7373 100644
--- a/cad/plugins/NanoVision-1/src/KDevelop/Utility/Utility.pro
+++ b/cad/plugins/NanoVision-1/src/KDevelop/Utility/Utility.pro
@@ -6,7 +6,8 @@ CONFIG += dll \
INCLUDEPATH += ../../../include
-HEADERS += ../../../include/Nanorex/Utility/NXCommandResult.h \
+HEADERS += ../../../include/Nanorex/Utility/NXCommandLine.h \
+../../../include/Nanorex/Utility/NXCommandResult.h \
../../../include/Nanorex/Utility/NXLogger.h \
../../../include/Nanorex/Utility/NXPluginGroup.h \
../../../include/Nanorex/Utility/NXPlugin.h \
@@ -16,7 +17,8 @@ HEADERS += ../../../include/Nanorex/Utility/NXCommandResult.h \
../../../include/Nanorex/Utility/NXPoint.h \
../../../include/Nanorex/Utility/NXRGBColor.h
-SOURCES += ../../../src/Utility/NXCommandResult.cpp \
+SOURCES += ../../../src/Utility/NXCommandLine.cpp \
+../../../src/Utility/NXCommandResult.cpp \
../../../src/Utility/NXLogger.cpp \
../../../src/Utility/NXPlugin.cpp \
../../../src/Utility/NXPluginGroup.cpp \
diff --git a/cad/plugins/NanoVision-1/src/LogHandlerWidget.cpp b/cad/plugins/NanoVision-1/src/LogHandlerWidget.cpp
index 32731b7fe..970e15f36 100644
--- a/cad/plugins/NanoVision-1/src/LogHandlerWidget.cpp
+++ b/cad/plugins/NanoVision-1/src/LogHandlerWidget.cpp
@@ -13,16 +13,19 @@ LogHandlerWidget::LogHandlerWidget(NXLogLevel logLevel, QWidget* parent)
/* FUNCTION: publish */
void LogHandlerWidget::publish(LogRecord logRecord) {
- mutex.lock();
- QString source =
- logRecord.getSource().length() == 0 ?
- "" : logRecord.getSource().append(": ").c_str();
- QString message =
- QString("%1 [%2] %3 %4")
- .arg(logRecord.getDateTime().toString("yyyy-MM-dd hh:mm:ss.zzz"))
- .arg(LogLevelNames[logRecord.getLogLevel()])
- .arg(source)
- .arg(logRecord.getMessage().c_str());
- textEdit->append(message);
- mutex.unlock();
+ if (logRecord.getLogLevel() >= logLevel) {
+ mutex.lock();
+ QString source =
+ logRecord.getSource().length() == 0 ?
+ "" : logRecord.getSource().append(": ").c_str();
+ QString message =
+ QString("%1 [%2] %3 %4")
+ .arg(logRecord.getDateTime()
+ .toString("yyyy-MM-dd hh:mm:ss.zzz"))
+ .arg(LogLevelNames[logRecord.getLogLevel()])
+ .arg(source)
+ .arg(logRecord.getMessage().c_str());
+ textEdit->append(message);
+ mutex.unlock();
+ }
}
diff --git a/cad/plugins/NanoVision-1/src/ResultsWindow.cpp b/cad/plugins/NanoVision-1/src/ResultsWindow.cpp
index 40f3e7402..42fbf0dd5 100644
--- a/cad/plugins/NanoVision-1/src/ResultsWindow.cpp
+++ b/cad/plugins/NanoVision-1/src/ResultsWindow.cpp
@@ -53,6 +53,21 @@ bool ResultsWindow::loadFile(const QString &fileName) {
} else {
setCurrentFile(fileName);
+ //
+ // Discover a store-not-complete trajectory frame set
+ NXDataStoreInfo* dataStoreInfo = entityManager->getDataStoreInfo();
+ int trajId = dataStoreInfo->getTrajectoryId("frame-set-1");
+ TrajectoryGraphicsPane* trajPane = new TrajectoryGraphicsPane();
+ trajPane->setEntityManager(entityManager);
+ workspace->addWindow(trajPane);
+ trajPane->show();
+ if (!dataStoreInfo->storeIsComplete(trajId)) {
+ QObject::connect(entityManager,
+ SIGNAL(newFrameAdded(int, int, NXMoleculeSet*)),
+ trajPane,
+ SLOT(newFrame(int, int, NXMoleculeSet*)));
+ }
+
/* MDI data window example
DataWindow *child = new DataWindow;
workspace->addWindow(child);
diff --git a/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.cpp b/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.cpp
index e99bd1e8f..f6de60b20 100644
--- a/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.cpp
+++ b/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.cpp
@@ -8,6 +8,8 @@ TrajectoryGraphicsPane::TrajectoryGraphicsPane(QWidget *parent)
: QWidget(parent), Ui_TrajectoryGraphicsPane() {
setupUi(this);
+
+ _frameIndex = 0;
}
@@ -16,3 +18,35 @@ TrajectoryGraphicsPane::~TrajectoryGraphicsPane() {
}
+/* FUNCTION: newFrame */
+void TrajectoryGraphicsPane::newFrame(int frameSetId, int frameIndex,
+ NXMoleculeSet* newMoleculeSet) {
+
+ // Start printing all frames available from the first render() call
+ unsigned int frameCount = 0;
+ QString line;
+ NXMoleculeSet* moleculeSet =
+ entityManager->getRootMoleculeSet(frameSetId, _frameIndex);
+ while (moleculeSet != 0) {
+ textEdit->insertPlainText("\n==========================\n");
+ line =
+ QString("storeComplete=%1 ").arg(entityManager->getDataStoreInfo()->storeIsComplete(frameSetId));
+ textEdit->insertPlainText(line);
+ frameCount = entityManager->getFrameCount(frameSetId);
+ line =
+ QString("frame: %1%2/%3\n")
+ .arg(_frameIndex+1)
+ .arg(moleculeSet == newMoleculeSet ? "*" : "")
+ .arg(frameCount);
+ textEdit->insertPlainText(line);
+
+ _frameIndex++;
+ moleculeSet =
+ entityManager->getRootMoleculeSet(frameSetId, _frameIndex);
+ }
+
+ // Stop once the data store is complete
+ //if (entityManager->getDataStoreInfo()->storeIsComplete(frameSetId))
+ // exit(0);
+}
+
diff --git a/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.h b/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.h
index c5ef60714..1092ee0a3 100644
--- a/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.h
+++ b/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.h
@@ -5,17 +5,33 @@
#include <QWidget>
+#include "Nanorex/Interface/NXEntityManager.h"
+using namespace Nanorex;
+
#include <ui_TrajectoryGraphicsPane.h>
/* CLASS: TrajectoryGraphicsPane */
class TrajectoryGraphicsPane
: public QWidget, private Ui_TrajectoryGraphicsPane {
+
Q_OBJECT
-public:
- TrajectoryGraphicsPane(QWidget *parent = 0);
- ~TrajectoryGraphicsPane();
+ public:
+ TrajectoryGraphicsPane(QWidget *parent = 0);
+ ~TrajectoryGraphicsPane();
+
+ void setEntityManager(NXEntityManager* entityManager) {
+ this->entityManager = entityManager;
+ }
+
+ public slots:
+ void newFrame(int frameSetId, int frameIndex,
+ NXMoleculeSet* newMoleculeSet);
+
+ private:
+ unsigned int _frameIndex;
+ NXEntityManager* entityManager;
};
#endif
diff --git a/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.ui b/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.ui
index fe0eea60d..e5ed321d4 100644
--- a/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.ui
+++ b/cad/plugins/NanoVision-1/src/TrajectoryGraphicsPane.ui
@@ -20,14 +20,7 @@
<number>6</number>
</property>
<item>
- <widget class="QLabel" name="label" >
- <property name="text" >
- <string>__ Graphics pane __</string>
- </property>
- <property name="alignment" >
- <set>Qt::AlignCenter</set>
- </property>
- </widget>
+ <widget class="QTextEdit" name="textEdit" />
</item>
<item>
<widget class="QFrame" name="frame" >
diff --git a/cad/plugins/NanoVision-1/src/Utility/NXCommandLine.cpp b/cad/plugins/NanoVision-1/src/Utility/NXCommandLine.cpp
new file mode 100755
index 000000000..729b339df
--- /dev/null
+++ b/cad/plugins/NanoVision-1/src/Utility/NXCommandLine.cpp
@@ -0,0 +1,334 @@
+/*------------------------------------------------------
+ CCmdLine
+
+ A utility for parsing command lines.
+
+ Copyright (C) 1999 Chris Losinger, Smaller Animals Software.
+ http://www.smalleranimals.com
+
+ This software is provided 'as-is', without any express
+ or implied warranty. In no event will the authors be
+ held liable for any damages arising from the use of this software.
+
+ Permission is granted to anyone to use this software
+ for any purpose, including commercial applications, and
+ to alter it and redistribute it freely, subject to the
+ following restrictions:
+
+ 1. The origin of this software must not be misrepresented;
+ you must not claim that you wrote the original software.
+ If you use this software in a product, an acknowledgment
+ in the product documentation would be appreciated but is not required.
+
+ 2. Altered source versions must be plainly marked as such,
+ and must not be misrepresented as being the original software.
+
+ 3. This notice may not be removed or altered from any source
+ distribution.
+
+ See SACmds.h for more info.
+------------------------------------------------------*/
+
+// if you're using MFC, you'll need to un-comment this line
+// #include "stdafx.h"
+
+#include "Nanorex/Utility/NXCommandLine.h"
+//#include "crtdbg.h"
+
+namespace Nanorex {
+
+/* FUNCTION: SplitLine */
+int NXCommandLine::SplitLine(const char *line) {
+
+ // Build atom array
+ std::string atom = "";
+ int index;
+ int lineLength = strlen(line);
+ bool inQuotedString = false;
+ std::vector<std::string> atomArray;
+ for (index = 0; index < lineLength; index++) {
+ if (line[index] == '"') {
+ inQuotedString = !inQuotedString;
+
+ } else if (line[index] != ' ') {
+ atom += line[index];
+
+ } else { // handle space
+ if (inQuotedString) {
+ atom += line[index];
+
+ } else {
+ inQuotedString = false;
+ if (atom != "") {
+ atomArray.push_back(atom);
+ }
+ atom = "";
+ }
+ }
+ }
+ if ((lineLength > 0) && (atom != "")) {
+ atomArray.push_back(atom);
+ }
+
+ // Build char* array
+ int arrayLength = atomArray.size();
+ char** argv = new char*[arrayLength];
+ for (index = 0; index < arrayLength; index++) {
+ char* buffer = new char[atomArray[index].size()+1];
+ buffer = strcpy(buffer, atomArray[index].c_str());
+ argv[index] = buffer;
+ }
+
+ int switchCount = 0;
+ if (arrayLength != 0)
+ switchCount = SplitLine(arrayLength, argv);
+
+ // Free memory
+ for (index = 0; index < arrayLength; index++)
+ delete argv[index];
+ delete argv;
+
+ return switchCount;
+}
+
+
+/*------------------------------------------------------
+ int CCmdLine::SplitLine(int argc, char **argv)
+
+ parse the command line into switches and arguments
+
+ returns number of switches found
+------------------------------------------------------*/
+int NXCommandLine::SplitLine(int argc, char **argv)
+{
+ clear();
+
+ StringType curParam; // current argv[x]
+
+ // skip the exe name (start with i = 1)
+ for (int i = 1; i < argc; i++)
+ {
+ // if it's a switch, start a new CCmdLine
+ if (IsSwitch(argv[i]))
+ {
+ curParam = argv[i];
+
+ StringType arg;
+
+ // look at next input string to see if it's a switch or an argument
+ if (i + 1 < argc)
+ {
+ if (!IsSwitch(argv[i + 1]))
+ {
+ // it's an argument, not a switch
+ arg = argv[i + 1];
+
+ // skip to next
+ i++;
+ }
+ else
+ {
+ arg = "";
+ }
+ }
+
+ // add it
+ CCmdParam cmd;
+
+ // only add non-empty args
+ if (arg != "")
+ {
+ cmd.m_strings.push_back(arg);
+ }
+
+ // add the CCmdParam to 'this'
+ std::pair<NXCommandLine::iterator, bool> res =
+ insert(NXCommandLine::value_type(curParam, cmd));
+
+ }
+ else
+ {
+ // it's not a new switch, so it must be more stuff for the last switch
+
+ // ...let's add it
+ NXCommandLine::iterator theIterator;
+
+ // get an iterator for the current param
+ theIterator = find(curParam);
+ if (theIterator!=end())
+ {
+ (*theIterator).second.m_strings.push_back(argv[i]);
+ }
+ else
+ {
+ // ??
+ }
+ }
+ }
+
+ return size();
+}
+
+/*------------------------------------------------------
+
+ protected member function
+ test a parameter to see if it's a switch :
+
+ switches are of the form : -x
+ where 'x' is one or more characters.
+ the first character of a switch must be non-numeric!
+
+------------------------------------------------------*/
+
+bool NXCommandLine::IsSwitch(const char *pParam)
+{
+ if (pParam==NULL)
+ return false;
+
+ // switches must non-empty
+ // must have at least one character after the '-'
+ int len = strlen(pParam);
+ if (len <= 1)
+ {
+ return false;
+ }
+
+ // switches always start with '-'
+ if (pParam[0]=='-')
+ {
+ // allow negative numbers as arguments.
+ // ie., don't count them as switches
+ return (!isdigit(pParam[1]));
+ }
+ else
+ {
+ return false;
+ }
+}
+
+/*------------------------------------------------------
+ bool CCmdLine::HasSwitch(const char *pSwitch)
+
+ was the switch found on the command line ?
+
+ ex. if the command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
+
+ call return
+ ---- ------
+ cmdLine.HasSwitch("-a") true
+ cmdLine.HasSwitch("-z") false
+------------------------------------------------------*/
+
+bool NXCommandLine::HasSwitch(const char *pSwitch)
+{
+ NXCommandLine::iterator theIterator;
+ theIterator = find(pSwitch);
+ return (theIterator!=end());
+}
+
+/*------------------------------------------------------
+
+ StringType CCmdLine::GetSafeArgument(const char *pSwitch, int iIdx, const char *pDefault)
+
+ fetch an argument associated with a switch . if the parameter at
+ index iIdx is not found, this will return the default that you
+ provide.
+
+ example :
+
+ command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
+
+ call return
+ ---- ------
+ cmdLine.GetSafeArgument("-a", 0, "zz") p1
+ cmdLine.GetSafeArgument("-a", 1, "zz") p2
+ cmdLine.GetSafeArgument("-b", 0, "zz") p4
+ cmdLine.GetSafeArgument("-b", 1, "zz") zz
+
+------------------------------------------------------*/
+
+StringType NXCommandLine::GetSafeArgument(const char *pSwitch, int iIdx, const char *pDefault)
+{
+ StringType sRet;
+
+ if (pDefault!=NULL)
+ sRet = pDefault;
+
+ try
+ {
+ sRet = GetArgument(pSwitch, iIdx);
+ }
+ catch (...)
+ {
+ }
+
+ return sRet;
+}
+
+/*------------------------------------------------------
+
+ StringType CCmdLine::GetArgument(const char *pSwitch, int iIdx)
+
+ fetch a argument associated with a switch. throws an exception
+ of (int)0, if the parameter at index iIdx is not found.
+
+ example :
+
+ command line is : app.exe -a p1 p2 p3 -b p4 -c -d p5
+
+ call return
+ ---- ------
+ cmdLine.GetArgument("-a", 0) p1
+ cmdLine.GetArgument("-b", 1) throws (int)0, returns an empty string
+
+------------------------------------------------------*/
+
+StringType NXCommandLine::GetArgument(const char *pSwitch, int iIdx)
+{
+ if (HasSwitch(pSwitch))
+ {
+ NXCommandLine::iterator theIterator;
+
+ theIterator = find(pSwitch);
+ if (theIterator!=end())
+ {
+ if ((*theIterator).second.m_strings.size() > iIdx)
+ {
+ return (*theIterator).second.m_strings[iIdx];
+ }
+ }
+ }
+
+ throw (int)0;
+
+ return "";
+}
+
+/*------------------------------------------------------
+ int CCmdLine::GetArgumentCount(const char *pSwitch)
+
+ returns the number of arguments found for a given switch.
+
+ returns -1 if the switch was not found
+
+------------------------------------------------------*/
+
+int NXCommandLine::GetArgumentCount(const char *pSwitch)
+{
+ int iArgumentCount = -1;
+
+ if (HasSwitch(pSwitch))
+ {
+ NXCommandLine::iterator theIterator;
+
+ theIterator = find(pSwitch);
+ if (theIterator!=end())
+ {
+ iArgumentCount = (*theIterator).second.m_strings.size();
+ }
+ }
+
+ return iArgumentCount;
+}
+
+} // nanohive::
diff --git a/cad/plugins/NanoVision-1/src/main.cpp b/cad/plugins/NanoVision-1/src/main.cpp
index 149f225b2..f18a0843c 100644
--- a/cad/plugins/NanoVision-1/src/main.cpp
+++ b/cad/plugins/NanoVision-1/src/main.cpp
@@ -71,6 +71,8 @@ int main(int argc, char *argv[]) {
mainWindow->show();
splash->repaint();
+ mainWindow->processCommandLine(argc, argv);
+
sleep(1);
splash->finish(mainWindow);
delete splash;
diff --git a/cad/plugins/NanoVision-1/src/nv1.cpp b/cad/plugins/NanoVision-1/src/nv1.cpp
index 31534cf0e..8d3459a24 100644
--- a/cad/plugins/NanoVision-1/src/nv1.cpp
+++ b/cad/plugins/NanoVision-1/src/nv1.cpp
@@ -26,7 +26,7 @@ nv1::nv1(NXEntityManager* entityManager, LogHandlerWidget* logHandlerWidget)
createStatusBar();
readSettings();
-
+
// Setup log dock widget
QDockWidget* dock = new QDockWidget(tr("Log"), this);
dock->setAllowedAreas(Qt::BottomDockWidgetArea);
@@ -40,6 +40,25 @@ nv1::~nv1() {
}
+/* FUNCTION: processCommandLine */
+void nv1::processCommandLine(int argc, char *argv[]) {
+
+ NXCommandLine commandLine;
+ if ((commandLine.SplitLine(argc, argv) > 0) &&
+ (commandLine.HasSwitch("-f"))) {
+ string filename = commandLine.GetArgument("-f", 0);
+
+ QString message = tr("Opening file: %1").arg(filename.c_str());
+ NXLOG_INFO("", qPrintable(message));
+
+ if (resultsWindow->loadFile(filename.c_str())) {
+ statusBar()->showMessage(tr("File loaded"), 2000);
+ resultsWindow->show();
+ }
+ }
+}
+
+
/* FUNCTION: closeEvent */
void nv1::closeEvent(QCloseEvent *event) {
if (resultsWindow != 0)
diff --git a/cad/plugins/NanoVision-1/src/nv1.h b/cad/plugins/NanoVision-1/src/nv1.h
index 2b7cd1987..22a7dabc9 100644
--- a/cad/plugins/NanoVision-1/src/nv1.h
+++ b/cad/plugins/NanoVision-1/src/nv1.h
@@ -8,6 +8,7 @@
#include <QFileDialog>
#include <QCloseEvent>
+#include "Nanorex/Utility/NXCommandLine.h"
#include "Nanorex/Interface/NXEntityManager.h"
using namespace Nanorex;
@@ -23,6 +24,8 @@ class nv1 : public QMainWindow {
public:
nv1(NXEntityManager* entityManager, LogHandlerWidget* logHandlerWidget);
~nv1();
+
+ void processCommandLine(int argc, char *argv[]);
protected:
void closeEvent (QCloseEvent *event);