Переглянути джерело

WIP calling ctkCLIModuleTour from DAH app

Ivo Wolf 13 роки тому
батько
коміт
7cf5c36ed2

+ 31 - 4
Libs/CommandLineModules/Core/Testing/CLIModules/Tour/ctkCLIModuleTour.cpp

@@ -21,18 +21,21 @@
 
 #include <ctkCommandLineParser.h>
 
-#include <QCoreApplication>
+#include <QApplication>
 #include <QTextStream>
 #include <QFile>
+#include <QPixmap>
+#include <QPainter>
 
 #include <cstdlib>
 
 int main(int argc, char* argv[])
 {
-  QCoreApplication app(argc, argv);
+  // QPixmap (used below) requires QApplication (instead of QCoreApplication)
+  QApplication app(argc, argv);
   // This is used by QSettings
-  QCoreApplication::setOrganizationName("CommonTK");
-  QCoreApplication::setApplicationName("CLIModuleTour");
+  QApplication::setOrganizationName("CommonTK");
+  QApplication::setApplicationName("CLIModuleTour");
 
   ctkCommandLineParser parser;
   // Use Unix-style argument names
@@ -42,6 +45,13 @@ int main(int argc, char* argv[])
   parser.addArgument("help", "h", QVariant::Bool, "Show this help text");
   parser.addArgument("xml", "", QVariant::Bool, "Print a XML description of this modules command line interface");
 
+  parser.addArgument("integer", "", QVariant::Int, "Show this help text");
+  parser.addArgument("", "b", QVariant::Bool, "Show this help text");
+  parser.addArgument("double", "d", QVariant::Double, "Show this help text");
+  parser.addArgument("floatVector", "f", QVariant::String, "Show this help text");
+  parser.addArgument("enumeration", "e", QVariant::String, "Show this help text");
+  parser.addArgument("", "p", QVariant::String, "Show this help text");
+
   // Parse the command line arguments
   bool ok = false;
   QHash<QString, QVariant> parsedArgs = parser.parseArguments(QCoreApplication::arguments(), &ok);
@@ -65,8 +75,25 @@ int main(int argc, char* argv[])
     xmlDescription.open(QIODevice::ReadOnly);
     QTextStream(stdout, QIODevice::WriteOnly) << xmlDescription.readAll();
   }
+  if(parsedArgs.contains("p"))
+  {
+    QTextStream(stdout, QIODevice::WriteOnly) << parsedArgs["p"].toString();
+  }
 
   // Do something
+  // do we have enough information (input/output)?
+  if(parser.unparsedArguments().count() >= 2) 
+  {
+    QString input = parser.unparsedArguments().at(0);
+    QString output = parser.unparsedArguments().at(1);
+
+    QPixmap pix(input);
+    QPainter painter(&pix);
+    painter.setPen(Qt::white);
+    painter.setFont(QFont("Arial", 15));
+    painter.drawText(pix.rect(),Qt::AlignBottom|Qt::AlignLeft,"Result image produced by ctkCLIModuleTour");
+    pix.save(output, "JPEG");
+  }
 
   return EXIT_SUCCESS;
 }

+ 4 - 0
Libs/CommandLineModules/Core/ctkCmdLineModuleInstance.cpp

@@ -30,6 +30,7 @@
 
 #include <QStringList>
 #include <QDebug>
+#include <QProcess>
 
 
 struct ctkCmdLineModuleInstancePrivate
@@ -153,6 +154,9 @@ void ctkCmdLineModuleInstance::run() const
 //  // TODO: manage memory
   QStringList args = commandLineArguments();
   qDebug() << args;
+  QProcess p;
+  p.start(location(), args);
+  p.waitForFinished();
 //  ctkCmdLineModuleProcessRunner* moduleProcess =
 //      new ctkCmdLineModuleProcessRunner(d->ModuleReference.location(), args);
 //  return moduleProcess->start();

+ 38 - 32
Plugins/org.commontk.dah.cmdlinemoduleapp/ctkCommandLineModuleAppLogic.cpp

@@ -267,10 +267,6 @@ void ctkCommandLineModuleAppLogic::onLoadDataClicked()
         DicomImage dcmtkImage(filename.toLatin1().data());
         ctkDICOMImage ctkImage(&dcmtkImage);
 
-        ModuleInstance->setValue("fileVar", filename);
-        ModuleInstance->setValue("dirVar", OutputLocation);
-        ModuleInstance->run();
-
         QPixmap pixmap = QPixmap::fromImage(ctkImage.frame(0),Qt::AvoidDither);
         if (pixmap.isNull())
         {
@@ -302,36 +298,46 @@ void ctkCommandLineModuleAppLogic::onCreateSecondaryCapture()
     QString templatefilename = QDir(OutputLocation).absolutePath();
     if(templatefilename.isEmpty()==false) templatefilename.append('/'); 
     templatefilename.append("ctkdahscXXXXXX.jpg");
-    QTemporaryFile *tempfile = new QTemporaryFile(templatefilename,this->AppWidget);
-
-    if(tempfile->open())
+    QString inputFileName, outputFileName;
     {
-      QString filename = QFileInfo(tempfile->fileName()).absoluteFilePath();
-      qDebug() << "Created file: " << filename;
-      tempfile->close();
-      QPixmap tmppixmap(*pixmap);
-      QPainter painter(&tmppixmap);
-      painter.setPen(Qt::white);
-      painter.setFont(QFont("Arial", 15));
-      painter.drawText(tmppixmap.rect(),Qt::AlignBottom|Qt::AlignLeft,"Secondary capture by ctkCommandLineModuleApp");
-     //painter.drawText(rect(), Qt::AlignCenter, "Qt");
-      tmppixmap.save(tempfile->fileName(), "JPEG");
-      qDebug() << "Created Uuid: " << getHostInterface()->generateUID();
-
-      ctkDicomAvailableDataHelper::addToAvailableData(*ResultData, 
-        objectLocatorCache(), 
-        tempfile->fileName());
-
-      bool success = publishData(*ResultData, true);
-      if(!success)
-      {
-        qCritical() << "Failed to publish data";
-      }
-      qDebug() << "  publishData returned: " << success;
+      QTemporaryFile inputtmp(templatefilename,this->AppWidget);
+      if(!inputtmp.open())
+        return;
+      inputFileName = inputtmp.fileName();
+      inputtmp.close();
+
+      QTemporaryFile outputtmp(templatefilename,this->AppWidget);
+      if(!outputtmp.open())
+        return;
+      outputFileName = outputtmp.fileName();
+      outputtmp.close();
+    }
+
+    pixmap->save(inputFileName);
 
+    ModuleInstance->setValue("fileVar", inputFileName);
+    ModuleInstance->setValue("dirVar", outputFileName);
+    ModuleInstance->run();
+
+    //if(tempfile->open())
+    //{
+    //  QString filename = QFileInfo(tempfile->fileName()).absoluteFilePath();
+    //  qDebug() << "Created file: " << filename;
+    //  tempfile->close();
+    //else
+    //  qDebug() << "Creating temporary file failed.";
+    //}
+    qDebug() << "Created Uuid: " << getHostInterface()->generateUID();
+
+    ctkDicomAvailableDataHelper::addToAvailableData(*ResultData, 
+      objectLocatorCache(), 
+      outputFileName);
+
+    bool success = publishData(*ResultData, true);
+    if(!success)
+    {
+      qCritical() << "Failed to publish data";
     }
-    else
-      qDebug() << "Creating temporary file failed.";
+    qDebug() << "  publishData returned: " << success;
   }
-
 }

+ 2 - 2
Plugins/org.commontk.dah.cmdlinemoduleapp/ctkCommandLineModuleAppWidget.ui

@@ -27,7 +27,7 @@
       <bool>false</bool>
      </property>
      <property name="text">
-      <string>Run!</string>
+      <string>Get Data from Host</string>
      </property>
     </widget>
    </item>
@@ -79,7 +79,7 @@
    <item>
     <widget class="QPushButton" name="CreateSecondaryCaptureButton">
      <property name="text">
-      <string>Create Secondary Capture</string>
+      <string>Run and send data to host</string>
      </property>
     </widget>
    </item>