From f965ee7181f4d9a17ec0d96e0cad1b794aa66f3c Mon Sep 17 00:00:00 2001
From: Riccardo Maria Bianchi <riccardo.maria.bianchi@cern.ch>
Date: Wed, 11 Feb 2015 12:28:45 +0100
Subject: [PATCH] new batch mode. Details:
 https://its.cern.ch/jira/browse/ATLASVPONE-183 (VP1Base-00-20-00)

    * added VP1Msg: messageWarningRed() and prefix_warning()
    * fixed VP1Msg::messageDebug() output
    * added 'batch-mode': if VP1 run with "-b" or "-batch",
      the main window is not shown and a PNG file is automatically built
      Details: (https://its.cern.ch/jira/browse/ATLASVPONE-183)
---
 .../VP1/VP1Base/VP1Base/IVP13DChannelWidget.h |  2 +-
 .../VP1Base/IVP13DStandardChannelWidget.h     |  2 +-
 .../VP1/VP1Base/VP1Base/IVP1ChannelWidget.h   |  2 +-
 graphics/VP1/VP1Base/VP1Base/IVP1System.h     |  2 +-
 graphics/VP1/VP1Base/VP1Base/VP1Msg.h         |  4 +++
 .../VP1/VP1Base/src/IVP13DChannelWidget.cxx   |  4 +--
 .../src/IVP13DStandardChannelWidget.cxx       | 13 ++++++--
 .../VP1/VP1Base/src/IVP1ChannelWidget.cxx     | 12 ++++---
 graphics/VP1/VP1Base/src/IVP1System.cxx       |  7 +++-
 graphics/VP1/VP1Base/src/VP1Msg.cxx           | 33 +++++++++++++++++--
 10 files changed, 65 insertions(+), 16 deletions(-)

diff --git a/graphics/VP1/VP1Base/VP1Base/IVP13DChannelWidget.h b/graphics/VP1/VP1Base/VP1Base/IVP13DChannelWidget.h
index 5a7c468e82578..82e8d453c55a9 100755
--- a/graphics/VP1/VP1Base/VP1Base/IVP13DChannelWidget.h
+++ b/graphics/VP1/VP1Base/VP1Base/IVP13DChannelWidget.h
@@ -42,7 +42,7 @@ public:
   //We override this so we can also take care of the render areas.
   void setUpdatesEnabled ( bool enable );
 
-  virtual QPixmap getSnapshot(bool transp = false, int width = 0);
+  virtual QPixmap getSnapshot(bool transp = false, int width = 0, bool batch = false);
 
   virtual QByteArray saveState();
   virtual void restoreFromState(QByteArray);
diff --git a/graphics/VP1/VP1Base/VP1Base/IVP13DStandardChannelWidget.h b/graphics/VP1/VP1Base/VP1Base/IVP13DStandardChannelWidget.h
index 23d2da7dcc4f4..8dd1301d3de27 100755
--- a/graphics/VP1/VP1Base/VP1Base/IVP13DStandardChannelWidget.h
+++ b/graphics/VP1/VP1Base/VP1Base/IVP13DStandardChannelWidget.h
@@ -53,7 +53,7 @@ protected:
 public:
   void create();
   virtual ~IVP13DStandardChannelWidget();
-  virtual QPixmap getSnapshot(bool transp = false, int width = 0);
+  virtual QPixmap getSnapshot(bool transp = false, int width = 0, bool batch = false);
   //If overriding the following, remember to call this implementation:
   virtual void lastOfActiveSystemsRefreshed();
   virtual void systemRefreshed(IVP1System*);
diff --git a/graphics/VP1/VP1Base/VP1Base/IVP1ChannelWidget.h b/graphics/VP1/VP1Base/VP1Base/IVP1ChannelWidget.h
index 14f3d6fdb758a..99956faeb8d0f 100755
--- a/graphics/VP1/VP1Base/VP1Base/IVP1ChannelWidget.h
+++ b/graphics/VP1/VP1Base/VP1Base/IVP1ChannelWidget.h
@@ -100,7 +100,7 @@ public:
   const QString unique_name() const;
   const QString& information() const;
   const QString& contact_info() const;
-  virtual QPixmap getSnapshot(bool transp = false, int width = 0);
+  virtual QPixmap getSnapshot(bool transp = false, int width = 0, bool batch = false);
   virtual bool setAntiAliasing(bool aa) {VP1Msg::messageVerbose("You should not call this function directly, but one of its implementations in derived classes..."); return aa; };
   virtual bool isAntiAliasing() {VP1Msg::messageVerbose("You should not call this function directly, but one of its implementations in derived classes..."); return false; };
 
diff --git a/graphics/VP1/VP1Base/VP1Base/IVP1System.h b/graphics/VP1/VP1Base/VP1Base/IVP1System.h
index 085aaf047e4ee..f1b8b3496e414 100755
--- a/graphics/VP1/VP1Base/VP1Base/IVP1System.h
+++ b/graphics/VP1/VP1Base/VP1Base/IVP1System.h
@@ -75,7 +75,7 @@ public:
                          //window of the application (through emission of the sysmessage signal below).
   void messageDebug(const QString&) const;//Output only to stdout.
   static bool verbose() { return s_vp1verbose; }// Returns true if env var VP1_VERBOSE_OUTPUT=1
-  void messageVerbose(const QString&) const;//Only outputs when vp1verbose()
+  void messageVerbose(const QString&) const;//Only outputs when verbose()
 
   //Overloaded convenience methods, for outputting several lines:
   void message(const QStringList&, const QString& addtoend = "" ) const;
diff --git a/graphics/VP1/VP1Base/VP1Base/VP1Msg.h b/graphics/VP1/VP1Base/VP1Base/VP1Msg.h
index 4a7b368e5fba4..0142b59a5dd0e 100644
--- a/graphics/VP1/VP1Base/VP1Base/VP1Msg.h
+++ b/graphics/VP1/VP1Base/VP1Base/VP1Msg.h
@@ -39,7 +39,10 @@ public:
 
   static void message(const QString&, IVP1System*sys = 0);//Non-zero sys pointer to get message in GUI
   static void messageDebug(const QString&);
+  static void messageWarning(const QString&);
   static void messageVerbose(const QString&);//This outputs only if verbose() is true.
+  static void messageWarningRed( const QString& str );
+  static void messageWarningAllRed( const QString& str );
 
   //Overloaded convenience methods, for outputting several lines:
   static void message(const QStringList&, const QString& addtoend = "", IVP1System*sys = 0 );
@@ -51,6 +54,7 @@ public:
 
   static const char* prefix_msg() { return "VP1MESSAGE";}
   static const char* prefix_debug() { return "VP1MSG_DEBUG";}
+  static const char* prefix_warning() { return "VP1MSG_WARNING";}
   static const char* prefix_verbose() { return "VP1MSG_VERBOSE";}
 
 private:
diff --git a/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx b/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx
index 4a502f1d943d3..5dbc1ec6cd0df 100755
--- a/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx
+++ b/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx
@@ -127,9 +127,9 @@ void IVP13DChannelWidget::goingToNextEvent()
 }
 
 //_______________________________________________________
-QPixmap IVP13DChannelWidget::getSnapshot(bool transp, int width)
+QPixmap IVP13DChannelWidget::getSnapshot(bool transp, int width, bool batch)
 {
-	VP1Msg::messageVerbose("IVP13DChannelWidget::getSnapshot()");
+	VP1Msg::messageVerbose("IVP13DChannelWidget::getSnapshot() - transparent bkg: "+QString(transp)+" , width: "+QString::number(width)+" , batch: "+QString(batch));
 
 	//Unfortunately, the renderareas does not render properly by a
 	//simple grabWidget. We remedy this the hard way...
diff --git a/graphics/VP1/VP1Base/src/IVP13DStandardChannelWidget.cxx b/graphics/VP1/VP1Base/src/IVP13DStandardChannelWidget.cxx
index 6c1a134abf9c4..587aa560f8974 100755
--- a/graphics/VP1/VP1Base/src/IVP13DStandardChannelWidget.cxx
+++ b/graphics/VP1/VP1Base/src/IVP13DStandardChannelWidget.cxx
@@ -310,15 +310,24 @@ void IVP13DStandardChannelWidget::Imp::autoSnapshot()
 void IVP13DStandardChannelWidget::lastOfActiveSystemsRefreshed()
 {
   VP1Msg::messageVerbose("IVP13DStandardChannelWidget::lastOfActiveSystemsRefreshed() called.");
+
   if (d->need_initial_viewall) {
     d->viewer->viewAll();
     d->viewer->storeCameraParametersForReset();
     d->need_initial_viewall=false;
   }
+
   if(VP1QtUtils::environmentVariableIsSet("VP1_SCREENSHOTS_DIR"))
     d->autoSnapshot();
+
   if (d->viewer->startTourEachEvent())
     d->viewer->startTour();
+
+  // apparently this is the last method called when all systems have been drawn
+  // so we call here the renderPixmap() method is we are in "batch-mode"
+
+
+
 }
 
 //___________________________________________________________________________
@@ -410,9 +419,9 @@ void IVP13DStandardChannelWidget::stopSpinning()
 }
 
 //___________________________________________________________________________
-QPixmap IVP13DStandardChannelWidget::getSnapshot(bool transp, int width)
+QPixmap IVP13DStandardChannelWidget::getSnapshot(bool transp, int width, bool batch)
 {
-	VP1Msg::messageDebug("IVP13DStandardChannelWidget::getSnapshot()");
+	VP1Msg::messageDebug("IVP13DStandardChannelWidget::getSnapshot()  - transparent bkg: "+QString(transp)+" , width: "+QString::number(width)+" , batch: "+QString(batch));
   //   SoToVRML2Action tovrml2;
   //   tovrml2.apply(d->selection);
   //   SoVRMLGroup *newroot = tovrml2.getVRML2SceneGraph();
diff --git a/graphics/VP1/VP1Base/src/IVP1ChannelWidget.cxx b/graphics/VP1/VP1Base/src/IVP1ChannelWidget.cxx
index bb7ac25cf495c..5494e42932780 100755
--- a/graphics/VP1/VP1Base/src/IVP1ChannelWidget.cxx
+++ b/graphics/VP1/VP1Base/src/IVP1ChannelWidget.cxx
@@ -129,7 +129,8 @@ void IVP1ChannelWidget::systemRefreshed(IVP1System*s)
 {
 	assert(d->state==READY);
 	assert(s->state()==IVP1System::REFRESHED);
-	s = 0;//get rid of compile warning in opt mode
+//	s = 0;//get rid of compile warning in opt mode
+	VP1Msg::messageDebug("systemRefreshed: "+s->name());
 }
 
 //_______________________________________________________
@@ -137,7 +138,8 @@ void IVP1ChannelWidget::systemErased(IVP1System*s)
 {
 	assert(d->state==READY);
 	assert(s->state()==IVP1System::ERASED);
-	s = 0;//get rid of compile warning in opt mode
+//	s = 0;//get rid of compile warning in opt mode
+	VP1Msg::messageDebug("systemErased: "+s->name());
 }
 
 //_______________________________________________________
@@ -292,10 +294,10 @@ void IVP1ChannelWidget::setCanRegister(const bool&c,const bool&s)
 }
 
 //_______________________________________________________
-QPixmap IVP1ChannelWidget::getSnapshot(bool transp, int width)
+QPixmap IVP1ChannelWidget::getSnapshot(bool transp, int width, bool batch)
 {
-	VP1Msg::messageVerbose("IVP1ChannelWidget::getSnapshot() - using QPixmap::grabWidget()");
-	return QPixmap::grabWidget( this );
+	VP1Msg::messageVerbose("IVP1ChannelWidget::getSnapshot() - transparent bkg: "+QString(transp)+" , width: "+QString::number(width)+" , batch: "+QString(batch) );
+	return QPixmap::grabWidget ( this );
 }
 
 //_______________________________________________________
diff --git a/graphics/VP1/VP1Base/src/IVP1System.cxx b/graphics/VP1/VP1Base/src/IVP1System.cxx
index 7e471443b568d..c5b4ca63da24e 100755
--- a/graphics/VP1/VP1Base/src/IVP1System.cxx
+++ b/graphics/VP1/VP1Base/src/IVP1System.cxx
@@ -251,10 +251,15 @@ void IVP1System::allowUpdateGUI()
 
 //________________________________________________________
 void IVP1System::updateGUI() {
+//	messageDebug("IVP1System::updateGUI() - START");
   //assert(d->allowupdategui);
   //assert(d->state==ERASED);
-  if ( d->allowupdategui && qApp->hasPendingEvents() )
+
+  if ( d->allowupdategui && qApp->hasPendingEvents() ) {
     qApp->processEvents();
+  }
+
+//  messageDebug("IVP1System::updateGUI() - END");
 }
 
 //________________________________________________________
diff --git a/graphics/VP1/VP1Base/src/VP1Msg.cxx b/graphics/VP1/VP1Base/src/VP1Msg.cxx
index d357111c20c7b..278e6b77a6595 100644
--- a/graphics/VP1/VP1Base/src/VP1Msg.cxx
+++ b/graphics/VP1/VP1Base/src/VP1Msg.cxx
@@ -25,15 +25,44 @@ void VP1Msg::message( const QString& str, IVP1System*sys )
   if (sys)
     sys->message(str);
   else
-    std::cout<<prefix_msg()<<": "<<str.toStdString()<<std::endl;
+    std::cout << prefix_msg() << ": "<< str.toStdString()<<std::endl;
 }
 
 //____________________________________________________________________
 void VP1Msg::messageDebug( const QString& str )
 {
-  std::cout<<prefix_debug()<<": "<<str.toStdString()<<std::endl;
+  std::cout << prefix_debug() << ": "<< str.toStdString()<<std::endl;
 }
 
+//____________________________________________________________________
+void VP1Msg::messageWarning( const QString& str )
+{
+  std::cout << prefix_warning() << ": "<< str.toStdString()<<std::endl;
+}
+
+// only the 'Warning' label is printed in red
+//____________________________________________________________________
+void VP1Msg::messageWarningRed( const QString& str )
+{
+	// colors, see:
+	// - http://brianmilco.blogspot.ch/2011/11/color-debug-output-with-qt-and-qdebug.html
+	// - http://misc.flogisoft.com/bash/tip_colors_and_formatting
+	std::string msg = str.toStdString();
+	fprintf(stderr, "\033[1m\033[31mWarning:\033[21m\033[0m: %s\n", msg.c_str() );
+}
+
+// The whole 'Warning' message is printed in red
+//____________________________________________________________________
+void VP1Msg::messageWarningAllRed( const QString& str )
+{
+	// colors, see:
+	// - http://brianmilco.blogspot.ch/2011/11/color-debug-output-with-qt-and-qdebug.html
+	// - http://misc.flogisoft.com/bash/tip_colors_and_formatting
+	std::string msg = str.toStdString();
+	fprintf(stderr, "\033[1m\033[31mWarning:\033[21m %s\033[0m\n", msg.c_str() );
+}
+
+
 //____________________________________________________________________
 void VP1Msg::messageVerbose( const QString& str )
 {
-- 
GitLab