Salome HOME
new method clearItems() to clear the scene
[modules/gui.git] / src / GraphicsView / GraphicsView_ViewPort.cxx
index 9f79d180aafc60147456effcdc53e72fa0fd3cf8..627a30cddbc796f981fafd5eaa0260bc5e31f44e 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2013-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2013-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -34,6 +34,8 @@
 #include <QRectF>
 #include <QRubberBand>
 #include <QScrollBar>
+#include <QPrinter>
+#include <QPainter>
 
 #include <math.h>
 
@@ -310,6 +312,15 @@ void GraphicsView_ViewPort::removeItem( QGraphicsItem* theItem )
   onBoundingRectChanged();
 }
 
+void GraphicsView_ViewPort::clearItems()
+{
+  myHighlightedObject = 0;
+  mySelectedObjects.clear();
+  myObjects.clear();
+  myScene->clear();
+  onBoundingRectChanged();
+}
+
 //================================================================
 // Function : getObjects
 // Purpose  : 
@@ -457,6 +468,31 @@ QImage GraphicsView_ViewPort::dumpView( bool theWholeScene,
   return anImage;
 }
 
+bool GraphicsView_ViewPort::dumpViewToPSFormat(const QString& fileName)
+{
+  QPrinter printer(QPrinter::ScreenResolution);
+  printer.setOutputFormat(QPrinter::PostScriptFormat);
+  printer.setOutputFileName(fileName);
+  QPainter painter;  
+  if (!painter.begin(&printer))
+    return false;
+
+  QRect view( 0, 0, printer.pageRect().width(), printer.paperRect().height() );
+  QRectF bounds = myScene->itemsBoundingRect();
+    
+  if( !view.isEmpty() && !bounds.isEmpty() )
+  {
+    float SCALE = 0.5;//qMin( view.width()/bounds.width(), view.height()/bounds.height() );
+    painter.setViewport( view );
+    painter.scale( SCALE, SCALE );
+  }
+  myScene->render( &painter, QRectF( view ), bounds );
+
+  if (!painter.end())
+    return false;
+  return true;
+}
+
 //================================================================
 // Function : setSceneGap
 // Purpose  :