Salome HOME
Unicode support: correct handling of unicode on GUI level
[modules/gui.git] / src / SPlot2d / SPlot2d_ViewModel.cxx
index c811b9680b6d0d0bf30b865d25231c07ec76c06b..0d8250f24822a3322f53d1bee0caac6b8a493205 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2014  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
@@ -35,7 +35,6 @@
 #include "SUIT_ViewManager.h"
 
 #include "SALOME_ListIO.hxx"
-#include "SALOME_ListIteratorOfListIO.hxx"
 
 #include <QApplication>
 #include <QToolBar>
 #include <qwt_plot_curve.h>
 #include <stdlib.h>
 
-//ASL: Temporary commented in order to avoir dependency on SALOMEDS
-
-//#include "SALOMEDSClient.hxx"
-//#include "SALOMEDS_StudyManager.hxx"
-
-// in order NOT TO link with SalomeApp, here the code returns SALOMEDS_Study.
-// SalomeApp_Study::studyDS() does it as well, but -- here it is retrieved from
-// SALOMEDS::StudyManager - no linkage with SalomeApp.  
-
-/*static _PTR(Study) getStudyDS()
-{
-  SALOMEDSClient_Study* aStudy = NULL;
-  _PTR(StudyManager) aMgr( new SALOMEDS_StudyManager() );
-
-  // get id of SUIT_Study, if it's a SalomeApp_Study, it will return
-  //    id of its underlying SALOMEDS::Study
-  SUIT_Application* app = SUIT_Session::session()->activeApplication();
-  if ( !app )  return _PTR(Study)(aStudy);
-  SUIT_Study* stud = app->activeStudy();
-  if ( !stud ) return _PTR(Study)(aStudy);
-  const int id = stud->id(); // virtual method, must return SALOMEDS_Study id
-  // get SALOMEDS_Study with this id from StudyMgr
-  return aMgr->GetStudyByID( id );
-} */               
-
 /*!
   Constructor
 */
@@ -111,7 +85,7 @@ void SPlot2d_Viewer::rename( const Handle(SALOME_InteractiveObject)& IObject,
     }
 
     if( aCurve && aCurve->hasTableIO() && aCurve->getTableIO()->isSame( IObject ) )
-      aCurve->getTableIO()->setName( newName.toLatin1() );
+      aCurve->getTableIO()->setName( newName.toUtf8() );
   }
   aViewFrame->updateTitles();
 }
@@ -231,10 +205,11 @@ void SPlot2d_Viewer::Erase( const Handle(SALOME_InteractiveObject)& IObject, boo
 /*!
    Removes all curves from the view
 */
-void SPlot2d_Viewer::EraseAll(const bool /*forced*/
+void SPlot2d_Viewer::EraseAll(SALOME_Displayer* d, const bool forced
 {
   Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
   if(aViewFrame) aViewFrame->EraseAll();
+  SALOME_View::EraseAll(d, forced);
 }
 
 /*!
@@ -272,7 +247,7 @@ void SPlot2d_Viewer::Erase( const SALOME_Prs2d* prs, const bool )
 SALOME_Prs* SPlot2d_Viewer::CreatePrs( const char* entry )
 {
   Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
-  SPlot2d_Prs *prs = new SPlot2d_Prs();
+  SPlot2d_Prs *prs = new SPlot2d_Prs( entry );
   if(aViewFrame)
   {
     CurveDict aCurves = aViewFrame->getCurves();
@@ -400,22 +375,38 @@ SUIT_ViewWindow* SPlot2d_Viewer::createView( SUIT_Desktop* theDesktop )
   SLOT: called when action "Legend Clicked" is activated.
   override "onLegendClicked" method from Plot2d_ViewModel.
 */
-void SPlot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem )
+void SPlot2d_Viewer::onClicked( const QVariant& itemInfo, int index )
 {
   Plot2d_ViewFrame* aViewFrame = getActiveViewFrame();
   if(aViewFrame == NULL) return;
 
-  bool isAnalytical = false;
+  QwtPlotItem* plotItem = aViewFrame->getPlot()->infoToItem( itemInfo );
+
+  bool isCurveSelected = false;
+  CurveDict aCurves = aViewFrame->getCurves();
+  for( CurveDict::Iterator it = aCurves.begin(); it != aCurves.end(); ++it )
+  {
+    if(plotItem == it.key()) {
+      isCurveSelected = true;
+      it.value()->setSelected(true);
+    } else {
+      it.value()->setSelected(false);
+    }
+  }
+
   AnalyticalCurveList curves = aViewFrame->getAnalyticalCurves();
    foreach ( Plot2d_AnalyticalCurve* curve, curves ) {
           if(plotItem == curve->plotItem()) {
-                 isAnalytical = true;
+          isCurveSelected = true;
                  curve->setSelected(true);
           } else {
                  curve->setSelected(false);
           }
    }
-  if(isAnalytical) {
+  if(isCurveSelected) {
+    for( CurveDict::Iterator it = aCurves.begin(); it != aCurves.end(); ++it )
+      aViewFrame->updateCurve( it.value() );
+
        myDeselectAnalytical = false;
        emit clearSelected();
        aViewFrame->updateAnalyticalCurves();
@@ -424,7 +415,6 @@ void SPlot2d_Viewer::onLegendClicked( QwtPlotItem* plotItem )
   }
 
   Plot2d_Object* anObject = aViewFrame->getPlotObject(plotItem);
-  
   if(anObject) {
     
     // Highlight object in Object Browser