Back to index

salome-gui  6.5.0
Plot2d_ViewManager.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 #include "Plot2d_ViewManager.h"
00024 #include "Plot2d_ViewModel.h"
00025 #include "Plot2d_ViewWindow.h"
00026 #include "Plot2d_ViewFrame.h"
00027 
00028 #include "SUIT_PreferenceMgr.h"
00029 #include "SUIT_ResourceMgr.h"
00030 
00034 Plot2d_ViewManager::Plot2d_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) 
00035 : SUIT_ViewManager( study, desk, new Plot2d_Viewer() )
00036 {
00037   setTitle( tr( "PLOT2D_VIEW_TITLE" ) );
00038 }
00039 
00043 Plot2d_ViewManager::~Plot2d_ViewManager()
00044 {
00045 }
00046 
00050 Plot2d_Viewer* Plot2d_ViewManager::getPlot2dModel() const
00051 {
00052   return (Plot2d_Viewer*)myViewModel;
00053 }
00054 
00059 bool Plot2d_ViewManager::insertView( SUIT_ViewWindow* theView )
00060 {
00061   bool res = SUIT_ViewManager::insertView( theView );
00062   if ( res )
00063   {
00064     Plot2d_ViewWindow* view = (Plot2d_ViewWindow*)theView;
00065     connect( view, SIGNAL( cloneView() ), this, SLOT( onCloneView() ) );
00066 
00067     Plot2d_ViewFrame* aViewFrame = view->getViewFrame();
00068     Plot2d_Viewer* aViewer = getPlot2dModel();
00069     connect( aViewFrame, SIGNAL( legendClicked( QwtPlotItem* ) ), 
00070              aViewer, SLOT( onLegendClicked( QwtPlotItem* ) ) );
00071   }
00072   return res;
00073 }
00074 
00078 void Plot2d_ViewManager::createView()
00079 {
00080   createViewWindow();
00081 }
00082 
00086 void Plot2d_ViewManager::onCloneView()
00087 {
00088   if( sender() && sender()->inherits( "Plot2d_ViewWindow" ) )
00089   {
00090     Plot2d_ViewWindow* srcWnd = ( Plot2d_ViewWindow* )sender();
00091     cloneView( srcWnd );
00092   }
00093 }
00094 
00101 Plot2d_ViewWindow* Plot2d_ViewManager::cloneView( Plot2d_ViewWindow* srcWnd )
00102 {
00103   SUIT_ViewWindow* vw = createViewWindow();
00104 
00105   Plot2d_ViewWindow* newWnd = 0;
00106   if( vw && vw->inherits( "Plot2d_ViewWindow" ) )
00107     newWnd = ( Plot2d_ViewWindow* )vw;
00108   
00109   if( newWnd && srcWnd )
00110     emit cloneView( srcWnd->getViewFrame(), newWnd->getViewFrame() );
00111 
00112   return newWnd;
00113 }
00114 
00118 int Plot2d_ViewManager::fillPreferences( SUIT_PreferenceMgr* thePrefMgr, const int theId )
00119 {
00120   int aGrpId = thePrefMgr->addItem( tr( "PREF_GROUP_PLOT2DVIEWER" ), theId,
00121                                 SUIT_PreferenceMgr::GroupBox );
00122 
00123   thePrefMgr->addItem( tr( "PREF_SHOW_LEGEND" ), aGrpId,
00124                      SUIT_PreferenceMgr::Bool, "Plot2d", "ShowLegend" );
00125   
00126   int legendPosition = thePrefMgr->addItem( tr( "PREF_LEGEND_POSITION" ), aGrpId,
00127                                        SUIT_PreferenceMgr::Selector, "Plot2d", "LegendPos" );
00128   QStringList aLegendPosList;
00129   aLegendPosList.append( tr("PREF_LEFT") );
00130   aLegendPosList.append( tr("PREF_RIGHT") );
00131   aLegendPosList.append( tr("PREF_TOP") );
00132   aLegendPosList.append( tr("PREF_BOTTOM") );
00133 
00134   QList<QVariant> anIndexesList;
00135   anIndexesList.append(0);
00136   anIndexesList.append(1);
00137   anIndexesList.append(2);
00138   anIndexesList.append(3);
00139 
00140   thePrefMgr->setItemProperty( "strings", aLegendPosList, legendPosition );
00141   thePrefMgr->setItemProperty( "indexes", anIndexesList, legendPosition );
00142 
00143   int curveType = thePrefMgr->addItem( tr( "PREF_CURVE_TYPE" ), aGrpId,
00144                                    SUIT_PreferenceMgr::Selector, "Plot2d", "CurveType" );
00145   QStringList aCurveTypesList;
00146   aCurveTypesList.append( tr("PREF_POINTS") );
00147   aCurveTypesList.append( tr("PREF_LINES") );
00148   aCurveTypesList.append( tr("PREF_SPLINE") );
00149 
00150   anIndexesList.clear();
00151   anIndexesList.append(0);
00152   anIndexesList.append(1);
00153   anIndexesList.append(2);
00154 
00155   thePrefMgr->setItemProperty( "strings", aCurveTypesList, curveType );
00156   thePrefMgr->setItemProperty( "indexes", anIndexesList, curveType );
00157 
00158   int markerSize = thePrefMgr->addItem( tr( "PREF_MARKER_SIZE" ), aGrpId,
00159                                    SUIT_PreferenceMgr::IntSpin, "Plot2d", "MarkerSize" );
00160 
00161   thePrefMgr->setItemProperty( "min", 0, markerSize );
00162   thePrefMgr->setItemProperty( "max", 100, markerSize );
00163 
00164   QStringList aScaleModesList;
00165   aScaleModesList.append( tr("PREF_LINEAR") );
00166   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
00167 
00168   anIndexesList.clear();
00169   anIndexesList.append(0);
00170   anIndexesList.append(1);
00171 
00172   int horScale = thePrefMgr->addItem( tr( "PREF_HOR_AXIS_SCALE" ), aGrpId,
00173                                   SUIT_PreferenceMgr::Selector, "Plot2d", "HorScaleMode" );
00174 
00175   thePrefMgr->setItemProperty( "strings", aScaleModesList, horScale );
00176   thePrefMgr->setItemProperty( "indexes", anIndexesList, horScale );
00177 
00178   int verScale = thePrefMgr->addItem( tr( "PREF_VERT_AXIS_SCALE" ), aGrpId,
00179                                   SUIT_PreferenceMgr::Selector, "Plot2d", "VerScaleMode" );
00180 
00181   thePrefMgr->setItemProperty( "strings", aScaleModesList, verScale );
00182   thePrefMgr->setItemProperty( "indexes", anIndexesList, verScale );
00183 
00184   thePrefMgr->addItem( tr( "PREF_VIEWER_BACKGROUND" ), aGrpId,
00185                      SUIT_PreferenceMgr::Color, "Plot2d", "Background" );
00186 
00187   return aGrpId;
00188 }