Salome HOME
Updated copyright comment
[modules/gui.git] / src / Plot2d / Plot2d_ViewManager.cxx
1 // Copyright (C) 2007-2024  CEA, EDF, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 // Lesser General Public License for more details.
15 //
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 //
22
23 #include "Plot2d_ViewManager.h"
24 #include "Plot2d_ViewModel.h"
25 #include "Plot2d_ViewWindow.h"
26 #include "Plot2d_ViewFrame.h"
27
28 #include "SUIT_PreferenceMgr.h"
29 #include "SUIT_ResourceMgr.h"
30
31 /*!
32   Constructor
33 */
34 Plot2d_ViewManager::Plot2d_ViewManager( SUIT_Study* study, SUIT_Desktop* desk ) 
35 : SUIT_ViewManager( study, desk, new Plot2d_Viewer() )
36 {
37   setTitle( tr( "PLOT2D_VIEW_TITLE" ) );
38 }
39
40 /*!
41   Destructor
42 */
43 Plot2d_ViewManager::~Plot2d_ViewManager()
44 {
45 }
46
47 /*!
48   \return corresponding viewer
49 */
50 Plot2d_Viewer* Plot2d_ViewManager::getPlot2dModel() const
51 {
52   return (Plot2d_Viewer*)myViewModel;
53 }
54
55 /*!
56   Adds new view
57   \param theView - view to be added
58 */
59 bool Plot2d_ViewManager::insertView( SUIT_ViewWindow* theView )
60 {
61   bool res = SUIT_ViewManager::insertView( theView );
62   if ( res )
63   {
64     Plot2d_ViewWindow* view = (Plot2d_ViewWindow*)theView;
65     connect( view, SIGNAL( cloneView() ), this, SLOT( onCloneView() ) );
66
67     Plot2d_ViewFrame* aViewFrame = view->getViewFrame();
68     Plot2d_Viewer* aViewer = getPlot2dModel();
69     connect( aViewFrame, SIGNAL( clicked(const QVariant&, int) ),
70              aViewer, SLOT( onClicked(const QVariant&, int) ) );
71   }
72   return res;
73 }
74
75 /*!
76   Creates new view
77 */
78 void Plot2d_ViewManager::createView()
79 {
80   createViewWindow();
81 }
82
83 /*!
84   SLOT: called if action "Clone view" is activated, emits signal cloneView()
85 */
86 void Plot2d_ViewManager::onCloneView()
87 {
88   if( sender() && sender()->inherits( "Plot2d_ViewWindow" ) )
89   {
90     Plot2d_ViewWindow* srcWnd = ( Plot2d_ViewWindow* )sender();
91     cloneView( srcWnd );
92   }
93 }
94
95 /*!
96   \brief Creates clone of source window
97   \param srcWnd source window
98   \return Pointer on the new window
99   \sa onCloneView()
100 */
101 Plot2d_ViewWindow* Plot2d_ViewManager::cloneView( Plot2d_ViewWindow* srcWnd )
102 {
103   SUIT_ViewWindow* vw = createViewWindow();
104
105   Plot2d_ViewWindow* newWnd = 0;
106   if( vw && vw->inherits( "Plot2d_ViewWindow" ) )
107     newWnd = ( Plot2d_ViewWindow* )vw;
108   
109   if( newWnd && srcWnd )
110     emit cloneView( srcWnd->getViewFrame(), newWnd->getViewFrame() );
111
112   return newWnd;
113 }
114
115 /*!
116   Fills preference manager for viewer
117 */
118 int Plot2d_ViewManager::fillPreferences( SUIT_PreferenceMgr* thePrefMgr, const int theId )
119 {
120   int aGrpId = thePrefMgr->addItem( tr( "PREF_GROUP_PLOT2DVIEWER" ), theId,
121                                     SUIT_PreferenceMgr::GroupBox );
122
123   thePrefMgr->addItem( tr( "PREF_SHOW_LEGEND" ), aGrpId,
124                        SUIT_PreferenceMgr::Bool, "Plot2d", "ShowLegend" );
125   
126   int legendPosition = thePrefMgr->addItem( tr( "PREF_LEGEND_POSITION" ), aGrpId,
127                                             SUIT_PreferenceMgr::Selector, "Plot2d", "LegendPos" );
128   QStringList aLegendPosList;
129   aLegendPosList.append( tr("PREF_LEFT") );
130   aLegendPosList.append( tr("PREF_RIGHT") );
131   aLegendPosList.append( tr("PREF_TOP") );
132   aLegendPosList.append( tr("PREF_BOTTOM") );
133
134   QList<QVariant> anIndexesList;
135   anIndexesList.append(0);
136   anIndexesList.append(1);
137   anIndexesList.append(2);
138   anIndexesList.append(3);
139
140   thePrefMgr->setItemProperty( "strings", aLegendPosList, legendPosition );
141   thePrefMgr->setItemProperty( "indexes", anIndexesList, legendPosition );
142
143   int curveType = thePrefMgr->addItem( tr( "PREF_CURVE_TYPE" ), aGrpId,
144                                        SUIT_PreferenceMgr::Selector, "Plot2d", "CurveType" );
145   QStringList aCurveTypesList;
146   aCurveTypesList.append( tr("PREF_POINTS") );
147   aCurveTypesList.append( tr("PREF_LINES") );
148   aCurveTypesList.append( tr("PREF_SPLINE") );
149
150   anIndexesList.clear();
151   anIndexesList.append(0);
152   anIndexesList.append(1);
153   anIndexesList.append(2);
154
155   thePrefMgr->setItemProperty( "strings", aCurveTypesList, curveType );
156   thePrefMgr->setItemProperty( "indexes", anIndexesList, curveType );
157
158   int markerSize = thePrefMgr->addItem( tr( "PREF_MARKER_SIZE" ), aGrpId,
159                                         SUIT_PreferenceMgr::IntSpin, "Plot2d", "MarkerSize" );
160
161   thePrefMgr->setItemProperty( "min", 0, markerSize );
162   thePrefMgr->setItemProperty( "max", 100, markerSize );
163
164   QStringList aScaleModesList;
165   aScaleModesList.append( tr("PREF_LINEAR") );
166   aScaleModesList.append( tr("PREF_LOGARITHMIC") );
167
168   anIndexesList.clear();
169   anIndexesList.append(0);
170   anIndexesList.append(1);
171
172   int horScale = thePrefMgr->addItem( tr( "PREF_HOR_AXIS_SCALE" ), aGrpId,
173                                       SUIT_PreferenceMgr::Selector, "Plot2d", "HorScaleMode" );
174
175   thePrefMgr->setItemProperty( "strings", aScaleModesList, horScale );
176   thePrefMgr->setItemProperty( "indexes", anIndexesList, horScale );
177
178   int verScale = thePrefMgr->addItem( tr( "PREF_VERT_AXIS_SCALE" ), aGrpId,
179                                       SUIT_PreferenceMgr::Selector, "Plot2d", "VerScaleMode" );
180
181   thePrefMgr->setItemProperty( "strings", aScaleModesList, verScale );
182   thePrefMgr->setItemProperty( "indexes", anIndexesList, verScale );
183
184   thePrefMgr->addItem( tr( "PREF_VIEWER_BACKGROUND" ), aGrpId,
185                        SUIT_PreferenceMgr::Color, "Plot2d", "Background" );
186
187   return aGrpId;
188 }