Salome HOME
Update from BR_V5_DEV 13Feb2009
[modules/gui.git] / src / SPlot2d / SPlot2d_ViewModel.cxx
index 527a8a135209102df824e0c2c7442265b3444b83..10afaed7ce3984292f4aa1cb956daa46e522d64b 100644 (file)
@@ -1,25 +1,28 @@
-// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
-// 
-// This library is free software; you can redistribute it and/or
-// modify it under the terms of the GNU Lesser General Public
-// License as published by the Free Software Foundation; either 
-// version 2.1 of the License.
-// 
-// This library is distributed in the hope that it will be useful 
-// but WITHOUT ANY WARRANTY; without even the implied warranty of 
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
-// Lesser General Public License for more details.
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
 //
-// You should have received a copy of the GNU Lesser General Public  
-// License along with this library; if not, write to the Free Software 
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 //
-// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 //  File   : SPlot2d_Viewer.cxx
 //  Author : Sergey RUIN
 //  Module : SUIT
-
+//
 #include "SPlot2d_ViewModel.h"
 
 #include "SPlot2d_ViewWindow.h"
 #include "SPlot2d_Prs.h"
 #include "SUIT_Session.h"
 #include "SUIT_Application.h"
+#include "SUIT_ViewManager.h"
+
+#include "SALOME_ListIO.hxx"
 
-//#include "utilities.h"
-#include "qapplication.h"
-#include <qtoolbar.h>
-#include <qtoolbutton.h>
-#include <qcursor.h>
-#include <qcolordialog.h>
-#include <qwt_math.h>
+#include <QApplication>
+#include <QToolBar>
+#include <QToolButton>
+#include <QCursor>
+#include <QColorDialog>
+
+//#include <qwt_math>
 #include <qwt_plot_canvas.h>
+#include <qwt_plot_curve.h>
 #include <stdlib.h>
 
 using namespace std;
@@ -90,20 +97,19 @@ void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject,
   if( !aViewFrame )
     return;
 
-  QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
-  for( ; it.current(); ++it )
+  CurveDict aCurves = aViewFrame->getCurves();
+  CurveDict::Iterator it = aCurves.begin();
+  for( ; it != aCurves.end(); ++it )
   {
-    SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.current() );
+    SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.value() );
     if( aCurve && aCurve->hasIO() && aCurve->getIO()->isSame( IObject ) )
     {
       aCurve->setVerTitle( newName );
-      int key = aViewFrame->hasCurve( aCurve );
-      if( key )
-       aViewFrame->setCurveTitle( key, newName );
+      it.key()->setTitle( newName );
     }
 
     if( aCurve && aCurve->hasTableIO() && aCurve->getTableIO()->isSame( IObject ) )
-      aCurve->getTableIO()->setName( newName.latin1() );
+      aCurve->getTableIO()->setName( newName.toLatin1() );
   }
   aViewFrame->updateTitles();
 }
@@ -118,7 +124,8 @@ void SPlot2d_Viewer::renameAll( const Handle(SALOME_InteractiveObject)& IObj, co
   SUIT_ViewManager* vm = getViewManager();
   if ( vm )
   {
-    const QPtrVector<SUIT_ViewWindow>& wnds = vm->getViews();
+    const QVector<SUIT_ViewWindow*>& wnds = vm->getViews();
+
     for ( uint i = 0; i < wnds.size(); i++ )
     {
       Plot2d_ViewWindow* pwnd = dynamic_cast<Plot2d_ViewWindow*>( wnds.at( i ) );
@@ -139,10 +146,11 @@ bool SPlot2d_Viewer::isInViewer( const Handle(SALOME_InteractiveObject)& IObject
     return 1;
   else{
     if(!IObject.IsNull()){
-      QIntDictIterator<Plot2d_Curve> it(aViewFrame->getCurves());
-      for(; it.current();++it) {
-       SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current()); 
-       if(aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
+      CurveDict aCurves = aViewFrame->getCurves();
+      CurveDict::Iterator it = aCurves.begin();
+      for( ; it != aCurves.end(); ++it ) {
+        SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.value() );
+       if(aCurve && aCurve->hasIO() && aCurve->getTableIO()->isSame(IObject))
          return 1;
       }
     }
@@ -174,9 +182,10 @@ void SPlot2d_Viewer::DisplayOnly( const Handle(SALOME_InteractiveObject)& IObjec
   if(aViewFrame == NULL) return;
 
   Plot2d_Curve* curve = getCurveByIO( IObject );
-  QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
-  for ( ; it.current(); ++it ) {
-    if(it.current() != curve)
+  CurveDict aCurves = aViewFrame->getCurves();
+  CurveDict::Iterator it = aCurves.begin();
+  for( ; it != aCurves.end(); ++it ) {
+    if(it.value() != curve)
       aViewFrame->eraseCurve( curve );
     else
       aViewFrame->updateCurve( curve, false );
@@ -308,10 +317,11 @@ Handle(SALOME_InteractiveObject) SPlot2d_Viewer::FindIObject( const char* Entry
   Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
   if(aViewFrame == NULL) return anIO;
 
-  QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
-  for ( ; it.current(); ++it ) {
-    SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current()); 
-    if ( aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
+  CurveDict aCurves = aViewFrame->getCurves();
+  CurveDict::Iterator it = aCurves.begin();
+  for( ; it != aCurves.end(); ++it ) {
+    SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.value()); 
+    if ( aCurve && aCurve->hasIO() && !strcmp( aCurve->getIO()->getEntry(), Entry ) ) {
       anIO = aCurve->getIO();
       break;
     }
@@ -345,9 +355,10 @@ SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObje
   if ( !theIObject.IsNull() ) {
     Plot2d_ViewFrame* aViewFrame = fr ? fr : getActiveViewFrame();
     if(aViewFrame) {
-      QIntDictIterator<Plot2d_Curve> it( aViewFrame->getCurves() );
-      for ( ; it.current(); ++it ) {
-       SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>(it.current()); 
+      CurveDict aCurves = aViewFrame->getCurves();
+      CurveDict::Iterator it = aCurves.begin();
+      for( ; it != aCurves.end(); ++it ) {
+        SPlot2d_Curve* aCurve = dynamic_cast<SPlot2d_Curve*>( it.value() );
        if(aCurve) {
          if ( aCurve->hasIO() && aCurve->getIO()->isSame( theIObject ) )
            return aCurve;
@@ -358,30 +369,6 @@ SPlot2d_Curve* SPlot2d_Viewer::getCurveByIO( const Handle(SALOME_InteractiveObje
   return NULL;
 }
 
-/*!
-  SLOT: called when action "Clone view" is activated
-*/
-void SPlot2d_Viewer::onCloneView( Plot2d_ViewFrame* clonedVF, Plot2d_ViewFrame* newVF )
-{
-  if( !clonedVF || !newVF )
-    return;
-
-  // 1) Copy all properties of view
-
-  newVF->copyPreferences( clonedVF );
-
-  // 2) Display all curves displayed in cloned view
-
-  QList<Plot2d_Curve> aCurves;
-  clonedVF->getCurves( aCurves );
-  QList<Plot2d_Curve>::const_iterator anIt = aCurves.begin(), aLast = aCurves.end();
-
-  for( ; anIt!=aLast; anIt++ )
-    if( clonedVF->isVisible( *anIt ) )
-      newVF->displayCurve( *anIt, false );
-  newVF->Repaint();
-}
-
 /*!
   create SPlot2d_ViewWindow
 */
@@ -392,3 +379,29 @@ SUIT_ViewWindow* SPlot2d_Viewer::createView( SUIT_Desktop* theDesktop )
     aPlot2dView->getViewFrame()->Display(getPrs());
   return aPlot2dView;
 }
+
+/*!
+  SLOT: called when action "Legend Clicked" is activated.
+  override "onLegendClicked" method from Plot2d_ViewModel.
+*/
+void SPlot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem )
+{
+  Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
+  if(aViewFrame == NULL) return;
+
+  CurveDict aCurves = aViewFrame->getCurves();
+  SPlot2d_Curve* aSCurve;
+  CurveDict::Iterator it = aCurves.begin();
+  for( ; it != aCurves.end(); ++it )
+  {
+    if ( it.key() == plotItem ) {
+      aSCurve = dynamic_cast<SPlot2d_Curve*>( it.value() );
+      break;
+    }
+  }
+  // Highlight curve in Object Browser
+  if(aSCurve && aSCurve->hasIO()) {
+    QString anEntry = aSCurve->getIO()->getEntry();
+    emit legendSelected( anEntry );
+  }
+}