diff --git a/graphics/VP1/VP1Base/CMakeLists.txt b/graphics/VP1/VP1Base/CMakeLists.txt
index 58e815266db19d2167c61d84a80ac1883a2d1ac6..1290e35d38f01fe8e6a27492e6bad0a913baf081 100644
--- a/graphics/VP1/VP1Base/CMakeLists.txt
+++ b/graphics/VP1/VP1Base/CMakeLists.txt
@@ -1,4 +1,4 @@
-# $Id: CMakeLists.txt 724584 2016-02-17 15:40:28Z krasznaa $
+# $Id: CMakeLists.txt 784633 2016-11-16 16:16:34Z rbianchi $
 
 # Set the name of the package:
 atlas_subdir( VP1Base )
@@ -22,11 +22,14 @@ set( CMAKE_AUTORCC TRUE )
 
 # Build the library. Remember that the auto-generated UI files are put under
 # CMAKE_CURRENT_BINARY_DIR, so it needs to be added explicitly to the
-# declaration.
+# declaration of PRIVATE_INCLUDE_DIRS.
 atlas_add_library( VP1Base VP1Base/*.h src/*.cxx src/*.qrc
    PUBLIC_HEADERS VP1Base
    INCLUDE_DIRS ${SOQT_INCLUDE_DIRS} ${COIN3D_INCLUDE_DIRS}
    PRIVATE_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}
-   LINK_LIBRARIES Qt4::QtCore Qt4::QtGui ${SOQT_LIBRARIES} ${COIN3D_LIBRARIES}
-   GeoPrimitives
+   LINK_LIBRARIES Qt4::QtCore Qt4::QtGui ${SOQT_LIBRARIES} ${COIN3D_LIBRARIES} GeoPrimitives
    PRIVATE_LINK_LIBRARIES Qt4::QtOpenGL VP1HEPVis )
+
+atlas_install_scripts( share/generate-vp1-factory-code-cmake )
+
+
diff --git a/graphics/VP1/VP1Base/VP1Base/VP1ExaminerViewer.h b/graphics/VP1/VP1Base/VP1Base/VP1ExaminerViewer.h
index ac116d790923b4062a770de9ff928a8c79c01724..7bbd1e6ffd3a65e05d0342c267b78b6cbde1660c 100644
--- a/graphics/VP1/VP1Base/VP1Base/VP1ExaminerViewer.h
+++ b/graphics/VP1/VP1Base/VP1Base/VP1ExaminerViewer.h
@@ -72,6 +72,7 @@ public:
 	bool startTourEachEvent() const;
 	void startCustomTour();
 	void dumpSceneToFile(QString filename="");//empty file names causes file dialog to be launched
+	void dumpSceneToVRMLFile(QString filename="");//empty file names causes file dialog to be launched
 	void produceSVGImage(QString filename="");//empty file names causes file dialog to be launched
 	void produceEPSImage(QString filename="");//empty file names causes file dialog to be launched
 
diff --git a/graphics/VP1/VP1Base/VP1Base/VP1QtInventorUtils.h b/graphics/VP1/VP1Base/VP1Base/VP1QtInventorUtils.h
index 85e155f3bc20ebb5e737f6919fb773dca024e8a7..64f9c90901a64462d025e0e923fba1356eece6d5 100644
--- a/graphics/VP1/VP1Base/VP1Base/VP1QtInventorUtils.h
+++ b/graphics/VP1/VP1Base/VP1Base/VP1QtInventorUtils.h
@@ -121,6 +121,8 @@ public:
   static bool writeGraphToFile(SoNode*root, const QString& filename);//returns false in case of errors
   static SoSeparator* readGraphFromFile(const QString& filename);//returns 0 in case of errors
 
+  static bool writeGraphToVRMLFile(SoNode*root, const QString& filename);//returns false in case of errors
+
   ///////////////////////////////////////////////////////////
   //    Simple materials (color/brightness/transparency)   //
   ///////////////////////////////////////////////////////////
diff --git a/graphics/VP1/VP1Base/cmake/VP1BasePluginBoilerplateConfig.cmake b/graphics/VP1/VP1Base/cmake/VP1BasePluginBoilerplateConfig.cmake
new file mode 100644
index 0000000000000000000000000000000000000000..713db445027fc28fabb89dc95027ad5a316ebe5f
--- /dev/null
+++ b/graphics/VP1/VP1Base/cmake/VP1BasePluginBoilerplateConfig.cmake
@@ -0,0 +1,44 @@
+# Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration
+
+############
+### The code below sets a custom command to create and build the Qt Plugin boilerplate code
+
+# set args for the 'generate-vp1-factory-plugin-cmake' script
+set( VP1_BUILDDIR "${CMAKE_BINARY_DIR}/${ATLAS_PLATFORM}" )
+set( VP1_SOURCEDIR ${CMAKE_CURRENT_SOURCE_DIR} )
+
+set( VP1_PLUGIN_HEADER_FILENAME "tmpqt_extraheaders/${pkgName}_VP1AutoFactory.h" )
+set( VP1_PLUGIN_SRC_FILENAME "tmpqt_extrasrc/${pkgName}_VP1AutoFactory.cxx" )
+
+set( VP1_PLUGIN_HEADERS "${VP1_BUILDDIR}/tmpqt_extraheaders/${VP1_PLUGIN_HEADER_FILENAME}")
+set( VP1_PLUGIN_SRC "${VP1_BUILDDIR}/tmpqt_extrasrc/${VP1_PLUGIN_SRC_FILENAME}")
+set( VP1_PLUGIN_SRC_DIR "${VP1_BUILDDIR}/tmpqt_extrasrc")
+set( VP1_PLUGIN_HEADERS_DIR "${VP1_BUILDDIR}/tmpqt_extraheaders")
+
+set( VP1_PLUGIN_HEADERS_IN_SOURCE "${VP1_SOURCEDIR}/tmpqt_extraheaders/${VP1_PLUGIN_HEADER_FILENAME}" )
+set( VP1_PLUGIN_SRC_IN_SOURCE "${VP1_SOURCEDIR}/tmpqt_extraheaders/${VP1_PLUGIN_HEADER_FILENAME}" )
+
+message( "package ${pkgName} - boiler-plate files to generate:" ${VP1_PLUGIN_HEADERS} " , " ${VP1_PLUGIN_SRC} )
+
+add_custom_command(
+    OUTPUT  ${VP1_PLUGIN_HEADERS} ${VP1_PLUGIN_SRC} ${VP1_PLUGIN_HEADERS_IN_SOURCE} ${VP1_PLUGIN_SRC_IN_SOURCE}
+    PRE_BUILD
+    COMMAND "${CMAKE_BINARY_DIR}/${ATLAS_PLATFORM}/bin/generate-vp1-factory-code-cmake" ${VP1_BUILDDIR} ${VP1_SOURCEDIR} ${pkgName}
+    COMMENT "Launching 'generate-vp1-factory-code' to build the plugin boiler-code for package ${pkgName}"
+)
+
+####
+# NOTE!!
+# The custom_target CANNOT BE USED here, because we want to run it for all plugin packages, while targets are built only once.
+# So we just add a dependency on teh output of the custom_command, so it is run for each plugin package
+###
+# the custom target has to be defined only by the first plugin using it, 
+# then the other plugins will use that definition. 
+# If not enclosed by "if...else", the target would be defined by all plugins, 
+# making CMake throw errors.
+#
+#if( NOT TARGET generatepluginboilercode )
+#    add_custom_target( generatepluginboilercode ALL DEPENDS ${VP1_PLUGIN_HEADERS} ${VP1_PLUGIN_SRC}  )
+#endif()
+###########
+
diff --git a/graphics/VP1/VP1Base/share/generate-vp1-factory-code-cmake b/graphics/VP1/VP1Base/share/generate-vp1-factory-code-cmake
new file mode 100755
index 0000000000000000000000000000000000000000..1ed36c544656be07a1805c11aeffe1f31d108bc8
--- /dev/null
+++ b/graphics/VP1/VP1Base/share/generate-vp1-factory-code-cmake
@@ -0,0 +1,167 @@
+#!/bin/bash
+
+# Script which generates the factory code needed for VP1 plugins
+#
+# Thomas Kittelmann, May 2007.
+
+echo "=====>"
+echo "=====>  Generating factory code for VP1 Plugin"
+echo "=====>"
+
+
+# get command-line args
+BINARYDIR=$1
+SOURCEDIR=$2
+PROJECTNAME=$3
+
+echo "PROJECTNAME:" $PROJECTNAME
+echo "BINARYDIR:" $BINARYDIR
+echo "SOURCEDIR:" $SOURCEDIR
+echo "PWD:" $PWD
+
+#if [ "x"`basename $PWD` != "xcmt" ]; then
+#    echo "$APPNAME: ERROR - must be invoked from cmt dir (pwd is: $PWD)"
+#    exit 1
+#fi
+
+if [ "x${CMTCONFIG}" == "x" ]; then
+    echo "$APPNAME: ERROR - CMTCONFIG not set"
+    exit 1
+fi
+
+#if [ "x"`basename $PWD` != "x${CMTCONFIG}" ]; then
+#    echo "$APPNAME: ERROR - this script must run in the build dir (pwd is: $PWD)"
+#    exit 1
+#fi
+
+#if [ "x${ATLAS_PLATFORM}" == "x" ]; then
+#    echo "$APPNAME: ERROR - ATLAS_PLATFORM not set"
+#    exit 1
+#fi
+
+#if [ ${CMTCONFIG} == ${ATLAS_PLATFORM} ]; then
+#    echo "$APPNAME: ERROR! CMTCONFIG != ATLAS_PLATFORM!!" ${CMTCONFIG} ${ATLAS_PLATFORM}
+#    exit 1
+#fi
+
+#if [ ! -d ../${CMTCONFIG}/ ]; then
+#    echo "$APPNAME: ERROR - did not find ../$CMTCONFIG/ directory"
+#    exit 1
+#fi
+
+declare -a VP1CLASSNAMES
+declare -a VP1STRINGS
+VP1N=0
+
+
+#echo "SOURCEDIR:" $SOURCEDIR
+for srcfile in $SOURCEDIR/src/*.cxx; do
+  TMP=`cat $srcfile|sed 's#//.*$##'|grep 'VP1CHANNELNAMEINPLUGIN *(.*)'`
+  if [ "x$TMP" == "x" ]; then
+      continue
+  fi
+  NLINES=`echo $TMP|wc -l|awk '{print $1}'`
+  if [ "x$NLINES" == "x0" ]; then
+      continue
+  fi
+  if [ "x$NLINES" != "x1" ]; then
+    echo "$APPNAME: ERROR - Source file $srcfile had suspicious number of VP1CHANNELNAMEINPLUGIN (or maybe the parsing simply failed)"
+    exit 1
+  fi
+  TMP=`echo $TMP|sed 's#^.*VP1CHANNELNAMEINPLUGIN *(##'|sed 's#).*$##'`
+  #We might as well look for illegal characters at compile time:
+  TEST=`echo $TMP|grep '\['|wc -l|awk '{print $1}'`
+  if [ "x$TEST" != "x0" ]; then
+    echo "$APPNAME: ERROR - found illegal character ([) in VP1CHANNELNAMEINPLUGIN macro"
+    exit 1
+  fi
+  TEST=`echo $TMP|grep '\]'|wc -l|awk '{print $1}'`
+  if [ "x$TEST" != "x0" ]; then
+    echo "$APPNAME: ERROR - found illegal character (]) in VP1CHANNELNAMEINPLUGIN macro"
+    exit 1
+  fi
+  #Add the found entries:
+  VP1CLASSNAMES[$VP1N]=`echo $TMP|sed 's#,.*$##'`
+  VP1STRINGS[$VP1N]=`echo $TMP|sed 's#^.*, *"#"#'`
+  VP1N=$((VP1N+1))
+done
+VP1N=$((VP1N-1))
+
+APPNAME=`basename $0` && \
+#PACKAGENAME=`cmt show macro_value package` && \
+PACKAGENAME=$PROJECTNAME
+mkdir -p ${BINARYDIR}/tmpqt_extraheaders && \
+mkdir -p ${BINARYDIR}/tmpqt_extrasrc && \
+FACTNAME="${PACKAGENAME}_VP1AutoFactory" && \
+FACTNAMELOWER=`echo $FACTNAME | tr "[:upper:]" "[:lower:]"` && \
+HEADERFILE="${BINARYDIR}/tmpqt_extraheaders/${FACTNAME}.h" && \
+SRCFILE="${BINARYDIR}/tmpqt_extrasrc/${FACTNAME}.cxx" && \
+rm -f $HEADERFILE && touch $HEADERFILE && \
+rm -f $SRCFILE && touch $SRCFILE && \
+GENTIME=`date` && \
+echo '//Autogenerated VP1 Factory Code Header File ('"${GENTIME}"')'>> $HEADERFILE && \
+echo '' >> $HEADERFILE && \
+echo '#ifndef '"${FACTNAME}"'_H' >> $HEADERFILE && \
+echo '#define '"${FACTNAME}"'_H' >> $HEADERFILE && \
+echo '' >> $HEADERFILE && \
+echo '#include <QObject>' >> $HEADERFILE && \
+echo '#include <QStringList>' >> $HEADERFILE && \
+echo '' >> $HEADERFILE && \
+echo '#include "VP1Base/IVP1ChannelWidgetFactory.h"' >> $HEADERFILE && \
+echo '' >> $HEADERFILE && \
+echo 'class '"${FACTNAME}"' : public QObject, public IVP1ChannelWidgetFactory' >> $HEADERFILE && \
+echo '{' >> $HEADERFILE && \
+echo '  Q_OBJECT' >> $HEADERFILE && \
+echo '  Q_INTERFACES(IVP1ChannelWidgetFactory)' >> $HEADERFILE && \
+echo '' >> $HEADERFILE && \
+echo 'public:' >> $HEADERFILE && \
+echo '  virtual QStringList channelWidgetsProvided() const;' >> $HEADERFILE && \
+echo '  virtual IVP1ChannelWidget * getChannelWidget(const QString & channelwidget);' >> $HEADERFILE && \
+echo '};' >> $HEADERFILE && \
+echo '' >> $HEADERFILE && \
+echo '#endif' >> $HEADERFILE && \
+GENTIME=`date` && \
+echo '//Autogenerated VP1 Factory Code Implementation File ('"${GENTIME}"')'>> $SRCFILE && \
+echo '' >> $SRCFILE && \
+echo '#include <QtPlugin>'>> $SRCFILE && \
+echo '#include "tmpqt_extraheaders/'"${FACTNAME}"'.h"' >> $SRCFILE && \
+ls -1 $SOURCEDIR/$PACKAGENAME/*.h | sed 's!^'${SOURCEDIR}'/!#include "!' | sed 's!$!"!' >> $SRCFILE && \
+echo ''>> $SRCFILE && \
+echo 'QStringList '"${FACTNAME}"'::channelWidgetsProvided() const'>> $SRCFILE && \
+echo '{'>> $SRCFILE && \
+echo '  return QStringList()'>> $SRCFILE && \
+i=0 && \
+while [ $i -le $VP1N ]; do
+    echo "        << "${VP1STRINGS[$i]} >> $SRCFILE && \
+    i=$((i+1))
+done && \
+echo '         ;'>> $SRCFILE && \
+echo '}'>> $SRCFILE && \
+echo ''>> $SRCFILE && \
+echo 'IVP1ChannelWidget * '"${FACTNAME}"'::getChannelWidget(const QString & channelwidget)'>> $SRCFILE && \
+echo '{'>> $SRCFILE && \
+i=0 && \
+while [ $i -le $VP1N ]; do
+    echo '  if (channelwidget == '${VP1STRINGS[$i]}')' >> $SRCFILE && \
+    echo '    return new '${VP1CLASSNAMES[$i]}'();'>> $SRCFILE && \
+    echo '' >> $SRCFILE && \
+    i=$((i+1))
+done && \
+echo '  return 0;'>> $SRCFILE && \
+echo '}'>> $SRCFILE && \
+echo ''>> $SRCFILE && \
+echo 'Q_EXPORT_PLUGIN2(pnp_'"${FACTNAMELOWER}"', '"${FACTNAME}"')'>> $SRCFILE
+
+
+
+# TEMP FIX!
+# in the end, we move the tmp files to the source dir
+# because I didn't find a way to make CMake digest the fact 
+# that we have generated new files in the binary folder, 
+# and we want to use them to complete the compilation. 
+# I get errors if I use the main 'binary' dir as input folder.
+echo "TEMP FIX!!! copying tmpqt_extraheaders/  and tmpqt_extrasrc/ to " ${SOURCEDIR} "..."
+rm -rf ${SOURCEDIR}/tmpqt_extraheaders ${SOURCEDIR}/tmpqt_extrasrc
+mkdir  ${SOURCEDIR}/tmpqt_extraheaders ${SOURCEDIR}/tmpqt_extrasrc
+mv   ${HEADERFILE}  ${SOURCEDIR}/tmpqt_extraheaders 
+mv   ${SRCFILE}     ${SOURCEDIR}/tmpqt_extrasrc 
diff --git a/graphics/VP1/VP1Base/src/AnimationSequencer.cxx b/graphics/VP1/VP1Base/src/AnimationSequencer.cxx
index 8f4ee4bf64e1c6c40dafcba3740fc6e4553b7833..90eaf4f53d07667e10dde8de399ca683890be4f1 100644
--- a/graphics/VP1/VP1Base/src/AnimationSequencer.cxx
+++ b/graphics/VP1/VP1Base/src/AnimationSequencer.cxx
@@ -192,7 +192,8 @@ SoSphere * AnimationSequencer::Clockwork::getRegionSphere(AnimationSequence::REG
   switch (region) {
   case AnimationSequence::VERTEX:
     VP1Msg::messageVerbose("set sphere dimensions for vertex");
-    r = perspective ? 0.5 : 0.5;
+    //r = perspective ? 0.5 : 0.5;
+    r=0.5;
     break;
   case AnimationSequence::INDET:
     VP1Msg::messageVerbose("set sphere dimensions for indet");
diff --git a/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx b/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx
index 7bf550587dd88484b774e5a611b869d786acea00..4feb55ee6fe65b7ee72b7bd5b6a758641fd8b0c8 100644
--- a/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx
+++ b/graphics/VP1/VP1Base/src/IVP13DChannelWidget.cxx
@@ -128,7 +128,7 @@ void IVP13DChannelWidget::goingToNextEvent()
 }
 
 //_______________________________________________________
-QPixmap IVP13DChannelWidget::getSnapshot(bool transp, int width, bool batch)
+QPixmap IVP13DChannelWidget::getSnapshot(bool transp, int width, bool /*batch*/)
 {
 	VP1Msg::messageVerbose("IVP13DChannelWidget::getSnapshot()");
 
diff --git a/graphics/VP1/VP1Base/src/IVP13DSystem.cxx b/graphics/VP1/VP1Base/src/IVP13DSystem.cxx
index 99397edf10f592f09ffc17ed1605f0a073e67b32..3711a20fe63c906d6036c8b7c107400c3f2fd8d4 100644
--- a/graphics/VP1/VP1Base/src/IVP13DSystem.cxx
+++ b/graphics/VP1/VP1Base/src/IVP13DSystem.cxx
@@ -314,7 +314,7 @@ void IVP13DSystem::setUserSelectionNotificationsEnabled( SoCooperativeSelection
     message("setUserSelectionNotificationsEnabled Error: Called for selection which was never registered!");
     return;
   }
-  if (!enabled == d->selectionsWithDisabledNotifications.contains(selection))
+  if (enabled != d->selectionsWithDisabledNotifications.contains(selection))
     return;
 
   if (enabled)
diff --git a/graphics/VP1/VP1Base/src/VP1CameraHelper.cxx b/graphics/VP1/VP1Base/src/VP1CameraHelper.cxx
index cd551f3667920166e27f2cfa008bc7f14563a709..170a1e8d1334a455f7aa0f3685008e2072192816 100644
--- a/graphics/VP1/VP1Base/src/VP1CameraHelper.cxx
+++ b/graphics/VP1/VP1Base/src/VP1CameraHelper.cxx
@@ -369,7 +369,7 @@ void VP1CameraHelper::Imp::actual_animatedZoomToCameraState( const QByteArray& c
 //____________________________________________________________________
 //STATIC:
 VP1CameraHelper*  VP1CameraHelper::animatedZoomToPath( SoCamera * camera, SoGroup * sceneroot,
-						       SoPath * path,double duration_in_secs, double clipVolPercent, double slack,
+						       SoPath * path,double duration_in_secs, double /*clipVolPercent*/, double slack,
 						       const SbVec3f& lookat, const SbVec3f& upvec, bool varySpeed,
 						       bool forceCircular )
 {  
@@ -411,7 +411,7 @@ void VP1CameraHelper::Imp::actual_animatedZoomToPath( SoPath * path,double durat
 //____________________________________________________________________
 //STATIC:
 VP1CameraHelper * VP1CameraHelper::animatedZoomToSubTree(SoCamera * camera, SoGroup * sceneroot,
-							 SoNode*subtreeroot,double duration_in_secs, double clipVolPercent, double lastClipVolPercent, double slack,
+							 SoNode*subtreeroot,double duration_in_secs, double /* clipVolPercent*/, double /*lastClipVolPercent*/, double slack,
 							 const SbVec3f& lookat, const SbVec3f& upvec, bool varySpeed,
 							 bool forceCircular )
 {  
@@ -458,7 +458,7 @@ void VP1CameraHelper::Imp::actual_animatedZoomToSubTree( SoNode*subtreeroot,doub
 //____________________________________________________________________
 //STATIC:
 VP1CameraHelper * VP1CameraHelper::animatedZoomToBBox(SoCamera * camera, SoGroup * sceneroot,
-						      const SbBox3f& box,double duration_in_secs, double clipVolPercent, double slack,
+						      const SbBox3f& box,double duration_in_secs, double /*clipVolPercent*/, double slack,
 						      const SbVec3f& lookat, const SbVec3f& upvec , bool varySpeed,
 						      bool forceCircular )
 {
@@ -590,7 +590,7 @@ void VP1CameraHelper::Imp::actual_animatedZoomToBBox( const SbBox3f& box,double
 //____________________________________________________________________
 //STATIC:
 VP1CameraHelper * VP1CameraHelper::animatedZoomToPoint(SoCamera * camera, SoGroup * sceneroot,
-						       SbVec3f targetpoint,double duration_in_secs, double clipVolPercent, bool varySpeed,
+						       SbVec3f targetpoint,double duration_in_secs, double /*clipVolPercent*/, bool varySpeed,
 						       bool forceCircular )
 {  
   VP1CameraHelper * helper = new VP1CameraHelper(camera,sceneroot);
diff --git a/graphics/VP1/VP1Base/src/VP1DrawOptionsWidget.cxx b/graphics/VP1/VP1Base/src/VP1DrawOptionsWidget.cxx
index 8dce7e4cab934f741859565e19b2e9ff92e00699..9ccf12e48fa38fe3438700a7dc4a7a5daf443619 100644
--- a/graphics/VP1/VP1Base/src/VP1DrawOptionsWidget.cxx
+++ b/graphics/VP1/VP1Base/src/VP1DrawOptionsWidget.cxx
@@ -219,11 +219,13 @@ void VP1DrawOptionsWidget::updateNodes()
   }
 
   // 3) Update fields
-  if (!d->complexityDisabled)
+  if (!d->complexityDisabled){
     //We avoid setting the complexity value exactly to 0:
     complexityval = std::min<double>(1.0,std::max<double>(0.0,0.01+0.991*complexityval));
-    if (d->complexity->value.getValue()!=complexityval)
+  }
+  if (d->complexity->value.getValue()!=complexityval){
       d->complexity->value.setValue(complexityval);
+  }
   if (!d->linewidthsDisabled||!d->pointsizesDisabled) {
     double val_lw = d->linewidthsDisabled ? 0 : VP1QtInventorUtils::getValueLineWidthSlider(d->ui.horizontalSlider_linewidths);
     double val_ps = d->pointsizesDisabled ? 0 : VP1QtInventorUtils::getValuePointSizeSlider(d->ui.horizontalSlider_pointsizes);
diff --git a/graphics/VP1/VP1Base/src/VP1ExaminerViewer.cxx b/graphics/VP1/VP1Base/src/VP1ExaminerViewer.cxx
index b1a11f8b5828e5f2590092525bf276c382517c7f..cdb2ed9525d968adca466073be81c5521d4e378c 100644
--- a/graphics/VP1/VP1Base/src/VP1ExaminerViewer.cxx
+++ b/graphics/VP1/VP1Base/src/VP1ExaminerViewer.cxx
@@ -78,7 +78,9 @@ public:
   popup_antiAliasAction(0),
   popup_bgdColAction(0),
   popup_ambientLightAction(0),
+  popup_focalLengthAction(0),
   popup_dumpSceneAction(0),
+  popup_dumpSceneVRMLAction(0),
   popup_toSVGAction(0),
   popup_toEPSAction(0),
   popup_resetCameraAction(0),
@@ -112,6 +114,8 @@ public:
   action_moviefps(0),
   action_movieoutdir(0),
   action_moviefadetocurrentview(0),
+  stereo_offset_value(0.0),
+  popup_focal_value_action(0),
   detectorViewButtons(dvb),
   animationSequencer(tc),
   tourLoopsForever(false),
@@ -210,6 +214,7 @@ public:
 	QAction* popup_ambientLightAction;
 	QAction* popup_focalLengthAction;
 	QAction* popup_dumpSceneAction;
+	QAction* popup_dumpSceneVRMLAction;
 	QAction* popup_toSVGAction;
 	QAction* popup_toEPSAction;
 	QAction* popup_resetCameraAction;
@@ -1174,7 +1179,8 @@ SoSphere * VP1ExaminerViewer::Imp::getRegionSphere(REGION region,bool perspectiv
   switch (region) {
   case VERTEX:
     VP1Msg::messageVerbose("set sphere dimensions for vertex");
-    r = perspective ? 0.5 : 0.5;
+    //r = perspective ? 0.5 : 0.5;
+    r=0.5;
     break;
   case INDET:
     VP1Msg::messageVerbose("set sphere dimensions for indet");
@@ -1186,7 +1192,8 @@ SoSphere * VP1ExaminerViewer::Imp::getRegionSphere(REGION region,bool perspectiv
     break;
   case FORWARDREGION:
     VP1Msg::messageVerbose("set sphere dimensions for forward region");
-    r = perspective ? 600 : 600;
+    //r = perspective ? 600 : 600;
+    r=600;
     break;
   case MUON:
   default:
@@ -1851,6 +1858,7 @@ bool VP1ExaminerViewer::Imp::ensureMenuInit()
 	popup_headLightAction = advancedmenu->addAction("&Headlight");
 	popup_ambientLightAction = advancedmenu->addAction("dummy");
 	popup_dumpSceneAction = advancedmenu->addAction("Dump &scene to file");
+	popup_dumpSceneVRMLAction = advancedmenu->addAction("Dump &scene to VRML file");
 	popup_toSVGAction = advancedmenu->addAction("Produce SV&G image");
 	popup_toEPSAction = advancedmenu->addAction("Produce &EPS image");
 
@@ -2211,6 +2219,41 @@ void VP1ExaminerViewer::dumpSceneToFile(QString filename)
 
 }
 
+void VP1ExaminerViewer::dumpSceneToVRMLFile(QString filename){
+	VP1Msg::messageVerbose("VP1ExaminerViewer::dumpSceneToVRMLFile()");
+
+	SoNode * rootnode = getSceneGraph();
+	if (!rootnode)
+		return;
+
+	QWidget * w = getWidget();
+	if (!w)
+		return;
+
+	if(filename.isEmpty()) {
+		if (isAnimating())
+			stopAnimating();
+		filename = QFileDialog::getSaveFileName(w, "Select output file",
+				(d->lastDumpFile.isEmpty()?VP1Settings::defaultFileSelectDirectory():d->lastDumpFile),
+				"VRML2.0/X3D files (*.wrl)",0,QFileDialog::DontResolveSymlinks);
+		if(filename.isEmpty())
+			return;
+		if (!filename.endsWith(".wrl"))
+			filename += ".wrl";
+		d->lastDumpFile=filename;
+	}
+
+	SoGroup * standardisedRoot(0);
+	if ( rootnode->getTypeId().isDerivedFrom(SoGroup::getClassTypeId()))
+		standardisedRoot = VP1HEPVisUtils::convertToStandardScene(static_cast<SoGroup*>(rootnode));
+
+	if (standardisedRoot&&VP1QtInventorUtils::writeGraphToVRMLFile(standardisedRoot, filename))
+		VP1Msg::messageDebug("VP1ExaminerViewer: Dumped scene to VRML file "+filename);
+	else
+		VP1Msg::messageDebug("VP1ExaminerViewer: Error: Problems dumping scene to VRML file "+filename);
+
+}
+
 //____________________________________________________________________
 void VP1ExaminerViewer::produceSVGImage(QString filename)
 {
@@ -2381,6 +2424,12 @@ void VP1ExaminerViewer::showPopupMenu()
 		dumpSceneToFile();
 		return;
 	}
+	
+	if ( selAct == d->popup_dumpSceneVRMLAction ) {
+		VP1Msg::messageVerbose("VP1ExaminerViewer::showPopupMenu Dump scene to file");
+		dumpSceneToVRMLFile();
+		return;
+	}
 
 	if ( selAct == d->popup_toSVGAction ) {
 		VP1Msg::messageVerbose("VP1ExaminerViewer::showPopupMenu Produce SVG image");
@@ -2676,7 +2725,7 @@ void VP1ExaminerViewer::showPopupMenu()
 		//		float old = d->popup_focal_value_action->data().toFloat();
 		bool ok;
 		SoPerspectiveCamera * camera = dynamic_cast<SoPerspectiveCamera*>(getCamera());
-		if (!camera==NULL) {
+		if (camera) {
 			float current_value = camera->focalDistance.getValue();
 			int newfocal = QInputDialog::getDouble(getWidget(),
 					"Change focal length", // title
diff --git a/graphics/VP1/VP1Base/src/VP1QtInventorUtils.cxx b/graphics/VP1/VP1Base/src/VP1QtInventorUtils.cxx
index 31f12357598df996e6e148385810b59e79ebb69a..146725cbfc58ee4f445a90b6111e9c55ac37c910 100644
--- a/graphics/VP1/VP1Base/src/VP1QtInventorUtils.cxx
+++ b/graphics/VP1/VP1Base/src/VP1QtInventorUtils.cxx
@@ -38,6 +38,8 @@
 #include <Inventor/actions/SoSearchAction.h>
 #include <Inventor/SoDB.h>
 #include <Inventor/actions/SoWriteAction.h>
+#include <Inventor/actions/SoToVRML2Action.h>
+#include <Inventor/VRMLnodes/SoVRMLGroup.h>
 
 #include <Inventor/nodes/SoLineSet.h>
 #include <Inventor/nodes/SoVertexProperty.h>
@@ -149,7 +151,7 @@ public:
 		} endianTest;
 		ImageRec *image;
 		int swapFlag;
-		int x;
+		//int x;
 
 		endianTest.testWord = 1;
 		if (endianTest.testByte[0] == 1) {
@@ -170,41 +172,44 @@ public:
 
 		int bytesRead = fread(image, 1, 12, image->file);
         
-        if (!bytesRead) {
-            fprintf(stderr, "fread failed!\n");
-        }
-        if (image == NULL) {
+    if (!bytesRead) {
+      fprintf(stderr, "fread failed!\n");
+    }
+        /**if (image == NULL) { //image cannot be null here, it has been used!
             fprintf(stderr, "image == NULL!\n");
             return (ImageRec *)malloc(sizeof(ImageRec));
-        }
+        } **/
 
 		if (swapFlag) {
 			ConvertShort(&image->imagic, 6);
 		}
 
-        if (image) {
-		    image->tmp = (unsigned char *)malloc(image->xsize*256);
-		    image->tmpR = (unsigned char *)malloc(image->xsize*256);
-		    image->tmpG = (unsigned char *)malloc(image->xsize*256);
-		    image->tmpB = (unsigned char *)malloc(image->xsize*256);
+        
+        const unsigned int colourBuffSize=image->xsize*256u;
+		    image->tmp = (unsigned char *)malloc(colourBuffSize);
+		    image->tmpR = (unsigned char *)malloc(colourBuffSize);
+		    image->tmpG = (unsigned char *)malloc(colourBuffSize);
+		    image->tmpB = (unsigned char *)malloc(colourBuffSize);
 		    if (image->tmp == NULL || image->tmpR == NULL || image->tmpG == NULL ||
 			    	image->tmpB == NULL) {
 			    fprintf(stderr, "Out of memory!\n");
 			    exit(1);
 		    }
-        }
-
+        
+    //should test upper limits on x here...but what is sensible? 1Mb? 100Mb?
 		if ((image->type & 0xFF00) == 0x0100) {
-			x = (image->ysize * image->zsize) * sizeof(unsigned);
+			size_t x = ((size_t)image->ysize * (size_t)image->zsize) * sizeof(unsigned);
 			image->rowStart = (unsigned *)malloc(x);
 			image->rowSize = (int *)malloc(x);
 			if (image->rowStart == NULL || image->rowSize == NULL) {
-				fprintf(stderr, "Out of memory!\n");
+				fprintf(stderr, "Out of memory!\n"); 
 				exit(1);
 			}
 			image->rleEnd = 512 + (2 * x);
-			fseek(image->file, 512, SEEK_SET);
-
+			const int fseekRetVal= fseek(image->file, 512, SEEK_SET);
+      if (fseekRetVal !=0){
+        fprintf(stderr, "Something very wrong with fseek near line 205 of VP1QtInventorUtils.cxx");
+      }
 			size_t bytesRead = 0;
 			bytesRead = fread(image->rowStart, 1, x, image->file);
 			VP1Msg::messageDebug("bytesRead(rowStart): " + QString::number(bytesRead));
@@ -269,8 +274,8 @@ public:
 					}
 				}
 			} else {
-			
-            int okstatus = fseek(image->file, 512+(y*image->xsize)+(z*image->xsize*image->ysize), SEEK_SET);
+			      const unsigned int yDim(y*image->xsize), zDim(z*image->xsize*image->ysize);
+            int okstatus = fseek(image->file, 512u+yDim+zDim, SEEK_SET);
             if (okstatus) { VP1Msg::messageDebug("fseek failed!!"); }
 
 			size_t bytesRead = 0;
@@ -299,11 +304,15 @@ public:
 		(*width)=image->xsize;
 		(*height)=image->ysize;
 		(*components)=image->zsize;
-		base = (unsigned *)malloc(image->xsize*image->ysize*sizeof(unsigned));
-		rbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char));
-		gbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char));
-		bbuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char));
-		abuf = (unsigned char *)malloc(image->xsize*sizeof(unsigned char));
+		const unsigned int imageWidth =  image->xsize;
+		const unsigned int imageHeight = image->ysize;
+		const unsigned int uintSize(sizeof(unsigned)), ucharSize(sizeof(unsigned char));
+		const unsigned int colourBufSize=imageWidth*ucharSize;
+		base = (unsigned *)malloc(imageWidth*imageHeight*uintSize);
+		rbuf = (unsigned char *)malloc(colourBufSize);
+		gbuf = (unsigned char *)malloc(colourBufSize);
+		bbuf = (unsigned char *)malloc(colourBufSize);
+		abuf = (unsigned char *)malloc(colourBufSize);
 		if(!base || !rbuf || !gbuf || !bbuf) {
 			ImageClose(image);
 			if (base) free(base);
@@ -353,6 +362,7 @@ public:
 	static size_t buffer_size;
 	static void * buffer_realloc(void * bufptr, size_t size);
 	static QString buffer_writeaction(SoNode * root);
+	static void buffer_vrmlwriteaction(SoNode * root, const QString& filename);
 
 	static bool lineWidthAndPointSizeNeedsInit;
 	static double allowedLineWidthMin;
@@ -1391,6 +1401,24 @@ QString VP1QtInventorUtils::Imp::buffer_writeaction(SoNode * root)
 	return s;
 }
 
+//_____________________________________________________________________________________
+void VP1QtInventorUtils::Imp::buffer_vrmlwriteaction(SoNode * root, const QString& filename)
+{
+	SoToVRML2Action vwa;
+	
+	vwa.apply(root);
+	SoVRMLGroup * newroot = vwa.getVRML2SceneGraph();
+
+    SoOutput out;
+    out.openFile(qPrintable(filename));
+    out.setHeaderString("#VRML V2.0 utf8");
+    SoWriteAction wra(&out);
+    wra.apply(newroot);
+    out.closeFile();
+	newroot->unref();
+	return;
+}
+
 //_____________________________________________________________________________________
 bool VP1QtInventorUtils::writeGraphToFile(SoNode*root, const QString& filename)
 {
@@ -1421,6 +1449,29 @@ SoSeparator* VP1QtInventorUtils::readGraphFromFile(const QString& filename)
 	return SoDB::readAll(&in);
 }
 
+
+//_____________________________________________________________________________________
+bool VP1QtInventorUtils::writeGraphToVRMLFile(SoNode*root, const QString& filename)
+{
+	if (!root)
+		return false;
+
+	root->ref();
+	Imp::buffer_vrmlwriteaction(root, filename);
+	root->unrefNoDelete();
+
+	// QFile data(filename);
+	// if (data.open(QFile::WriteOnly | QFile::Truncate)) {
+	// 	QTextStream out(&data);
+	// 	out << s << endl;
+	// 	return true;
+	// } else {
+	// 	return false;
+	// }
+	return true;
+}
+
+
 /////////////////// OBSOLETE /////////////////////
 #include "VP1Base/VP1MaterialButton.h"
 //_____________________________________________________________________________________
diff --git a/graphics/VP1/VP1Base/src/VP1Serialise.cxx b/graphics/VP1/VP1Base/src/VP1Serialise.cxx
index 50d8d51c3a1c3fe3dd11cbe51e0dbe1d2a0ebcb2..65f7072f0f678f77a88885fe493e1091138bd279 100644
--- a/graphics/VP1/VP1Base/src/VP1Serialise.cxx
+++ b/graphics/VP1/VP1Base/src/VP1Serialise.cxx
@@ -44,7 +44,7 @@
 //____________________________________________________________________
 class VP1Serialise::Imp {
 public:
-  Imp(VP1Serialise *tc) : theclass(tc), buffer(0), state(0),checkedUnused(false) {}
+  Imp(VP1Serialise *tc) : theclass(tc), buffer(0), state(0),checkedUnused(false),version(0) {}
   VP1Serialise * theclass;
   QByteArray byteArray;
   QBuffer * buffer;
diff --git a/graphics/VP1/VP1Base/src/VP1TabWidget.cxx b/graphics/VP1/VP1Base/src/VP1TabWidget.cxx
index 6f652c79991eff0027281cac8a4d1d547119405c..1393a0b9f50359ae3dece6a26017100a3040824f 100644
--- a/graphics/VP1/VP1Base/src/VP1TabWidget.cxx
+++ b/graphics/VP1/VP1Base/src/VP1TabWidget.cxx
@@ -260,9 +260,9 @@ bool VP1TabWidget::tabCloseActivatePrevious() const
 
 int VP1TabWidget::tabBarWidthForMaxChars( int /*maxLength*/ )
 {
-  int hframe, overlap;
+  int hframe /*, overlap*/;
   hframe  = tabBar()->style()->pixelMetric( QStyle::PM_TabBarTabHSpace, 0L, tabBar() );
-  overlap = tabBar()->style()->pixelMetric( QStyle::PM_TabBarTabOverlap, 0L, tabBar() );
+  //overlap = tabBar()->style()->pixelMetric( QStyle::PM_TabBarTabOverlap, 0L, tabBar() );
 
   QFontMetrics fm = tabBar()->fontMetrics();
   int x = 0;
@@ -273,11 +273,12 @@ int VP1TabWidget::tabBarWidthForMaxChars( int /*maxLength*/ )
 
     int lw = fm.width( newTitle );
     int iw = 0;
-    if ( !tabBar()->tabIcon( i ).isNull() )
+    if ( !tabBar()->tabIcon( i ).isNull() ){
       iw = tabBar()->tabIcon( i ).pixmap( style()->pixelMetric( QStyle::PM_SmallIconSize ), QIcon::Normal ).width() + 4;
-      x += ( tabBar()->style()->sizeFromContents( QStyle::CT_TabBarTab, 0L,
-           QSize( qMax( lw + hframe + iw, QApplication::globalStrut().width() ), 0 ),
-           this ) ).width();
+    }
+    x += ( tabBar()->style()->sizeFromContents( QStyle::CT_TabBarTab, 0L,
+      QSize( qMax( lw + hframe + iw, QApplication::globalStrut().width() ), 0 ),
+      this ) ).width();
   }
 
   return x;