Salome HOME
Merge from BR_PORTING_VTK6 01/03/2013
[modules/paravis.git] / src / Plugins / NavigationMode / pqSetModeStarter.cxx
1 // Copyright (C) 2010-2012  CEA/DEN, EDF R&D
2 //
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Lesser General Public
5 // License as published by the Free Software Foundation; either
6 // version 2.1 of the License.
7 //
8 // This library is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
11 // Lesser General Public License for more details.
12 //
13 // You should have received a copy of the GNU Lesser General Public
14 // License along with this library; if not, write to the Free Software
15 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 //
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
18 //
19
20 #include "pqSetModeStarter.h"
21
22 #include <pqServerManagerModel.h>
23
24 #include <pqApplicationCore.h>
25 #include <pqRenderView.h>
26 #include <pqSettings.h>
27
28
29 //-----------------------------------------------------------------------------
30 pqSetModeStarter::pqSetModeStarter(QObject* p/*=0*/)
31   : QObject(p)
32 {
33 }
34
35 //-----------------------------------------------------------------------------
36 pqSetModeStarter::~pqSetModeStarter()
37 {
38 }
39
40
41 //-----------------------------------------------------------------------------
42 void pqSetModeStarter::onStartup()
43 {
44   this->setStandardMode();
45 }
46
47 //-----------------------------------------------------------------------------
48 void pqSetModeStarter::setStandardMode()
49 {
50   pqSettings* settings = pqApplicationCore::instance()->settings();
51   settings->beginGroup("renderModule");
52   if (!settings->contains("InteractorStyle/CameraManipulators")) {
53     // Set Post-Pro-like settings
54     QStringList strs;
55     pqRenderView::ManipulatorType manips[9];
56     const pqRenderView::ManipulatorType* default3DManips = pqRenderView::getDefault3DManipulatorTypes();
57
58     // Copy default settings, make changes for Ctrl+MB and MB modes
59     for(int i=0; i<9; i++)
60       {
61         manips[i] = default3DManips[i];
62
63         // Ctrl+MB
64         if (manips[i].Shift == 0 && manips[i].Control == 1) {
65           if (manips[i].Mouse == 1)
66             manips[i].Name = QByteArray("Zoom");
67           else  if (manips[i].Mouse == 2)
68             manips[i].Name = QByteArray("Pan");
69           else  if (manips[i].Mouse == 3)
70             manips[i].Name = QByteArray("Rotate");
71         }
72
73         // MB only
74         if (manips[i].Shift == 0 && manips[i].Control == 0) {
75           if (manips[i].Mouse == 1)
76             manips[i].Name = QByteArray("Rotate");
77           else  if (manips[i].Mouse == 2)
78             manips[i].Name = QByteArray("Pan");
79           else  if (manips[i].Mouse == 3)
80             manips[i].Name = QByteArray("Zoom");
81         }
82       }
83
84     // Save settings
85     for(int i=0; i<9; i++)
86       {
87         strs << QString("Manipulator%1Mouse%2Shift%3Control%4Name%5")
88           .arg(i+1)
89           .arg(manips[i].Mouse)
90           .arg(manips[i].Shift)
91           .arg(manips[i].Control)
92           .arg(QString(manips[i].Name));
93       }
94       
95     settings->setValue("InteractorStyle/CameraManipulators", strs);
96   }
97   settings->endGroup();
98
99   // Loop through render views and apply the settings
100   QList<pqRenderViewBase*> views =
101     pqApplicationCore::instance()->getServerManagerModel()->
102     findItems<pqRenderViewBase*>();
103
104   foreach(pqRenderViewBase* view, views) {
105     view->restoreSettings(true);
106   }
107 }