Salome HOME
Merge branch 'agy/PortingPV512_2'
[modules/gui.git] / src / PVViewer / PVViewer_Behaviors.cxx
1 // Copyright (C) 2014-2016  CEA/DEN, EDF R&D, OPEN CASCADE
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, or (at your option) any later version.
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 // Author: Adrien Bruneton (CEA)
20
21 #include "PVViewer_Behaviors.h"
22
23 #include <QMainWindow>
24
25 #include <pqInterfaceTracker.h>
26 #include <pqApplicationCore.h>
27 #include <pqPluginManager.h>
28 #include <pqStandardPropertyWidgetInterface.h>
29 #include <pqStandardViewFrameActionsImplementation.h>
30 #include <pqPropertiesPanel.h>
31
32 #include <pqAlwaysConnectedBehavior.h>
33 #include <pqAutoLoadPluginXMLBehavior.h>
34 #include <pqCommandLineOptionsBehavior.h>
35 #include <pqCrashRecoveryBehavior.h>
36 #include <pqDataTimeStepBehavior.h>
37 #include <pqDefaultViewBehavior.h>
38 #include <pqObjectPickingBehavior.h>
39 #include <pqPersistentMainWindowStateBehavior.h>
40 #include <pqPipelineContextMenuBehavior.h>
41 #include <pqPluginActionGroupBehavior.h>
42 #include <pqPluginDockWidgetsBehavior.h>
43 #include <pqSpreadSheetVisibilityBehavior.h>
44 #include <pqUndoRedoBehavior.h>
45 #include <pqViewStreamingBehavior.h>
46 #include <pqCollaborationBehavior.h>
47 #include <pqVerifyRequiredPluginBehavior.h>
48 #include <pqPluginSettingsBehavior.h>
49 #include <pqFixPathsInStateFilesBehavior.h>
50 #include <pqApplyBehavior.h>
51
52 #include <pqPropertiesPanel.h>
53
54 int PVViewer_Behaviors::BehaviorLoadingLevel = 0;
55
56 PVViewer_Behaviors::PVViewer_Behaviors(QMainWindow * parent)
57   : QObject(parent)
58 {
59 }
60
61 /**! Instanciate minimal ParaView behaviors needed when using an instance of PVViewer.
62  * This method should be updated at each new version of ParaView with what is found in
63  *    Qt/ApplicationComponents/pqParaViewBehaviors.cxx
64  */
65 void PVViewer_Behaviors::instanciateMinimalBehaviors(QMainWindow * desk)
66 {
67   if (BehaviorLoadingLevel < 1)
68     {
69       // Register ParaView interfaces.
70       pqInterfaceTracker* pgm = pqApplicationCore::instance()->interfaceTracker();
71
72       // Register standard types of property widgets.
73       pgm->addInterface(new pqStandardPropertyWidgetInterface(pgm));
74       // Register standard types of view-frame actions.
75       pgm->addInterface(new pqStandardViewFrameActionsImplementation(pgm));
76
77       // Load plugins distributed with application.
78       pqApplicationCore::instance()->loadDistributedPlugins();
79
80       new pqDefaultViewBehavior(this);  // shows a 3D view as soon as a server connection is made
81       new pqAlwaysConnectedBehavior(this);  // client always connected to a server
82       new pqVerifyRequiredPluginBehavior(this);
83       new pqPluginSettingsBehavior(this);
84       new pqFixPathsInStateFilesBehavior(this);
85       new pqCrashRecoveryBehavior(this);
86       new pqCommandLineOptionsBehavior(this);
87
88       BehaviorLoadingLevel = 1;
89     }
90 }
91
92 /**! Instanciate usual ParaView behaviors.
93  * This method should be updated at each new version of ParaView with what is found in
94  *    Qt/ApplicationComponents/pqParaViewBehaviors.cxx
95  */
96 void PVViewer_Behaviors::instanciateAllBehaviors(QMainWindow * desk)
97 {
98   //    "new pqParaViewBehaviors(anApp->desktop(), this);"
99   // -> (which loads all standard ParaView behaviors at once) has to be replaced in order to
100   // exclude using of pqQtMessageHandlerBehaviour
101
102   // Define application behaviors.
103   if (BehaviorLoadingLevel < 1)
104     instanciateMinimalBehaviors(desk);
105
106   if (BehaviorLoadingLevel < 2)
107     {
108       //new pqQtMessageHandlerBehavior(this);   // THIS ONE TO EXCLUDE !! see comment above
109       new pqDataTimeStepBehavior(this);
110       new pqSpreadSheetVisibilityBehavior(this);
111       new pqPipelineContextMenuBehavior(this);
112       new pqUndoRedoBehavior(this);
113       new pqAutoLoadPluginXMLBehavior(this);  // auto load plugins GUI stuff
114       new pqPluginDockWidgetsBehavior(desk);
115       new pqPluginActionGroupBehavior(desk);
116       new pqPersistentMainWindowStateBehavior(desk);
117       new pqObjectPickingBehavior(desk);
118       new pqCollaborationBehavior(this);
119       new pqViewStreamingBehavior(this);
120
121       // Move instantiation of the pqApplyBehavior to the PVViewer_GUIElements::buildPVWidgets(),
122       // because without pqPropertiesPanel it doesn't make sense.      
123       /*
124       pqApplyBehavior* applyBehavior = new pqApplyBehavior(this);
125       foreach (pqPropertiesPanel* ppanel, desk->findChildren<pqPropertiesPanel*>())
126       {
127         applyBehavior->registerPanel(ppanel);
128       }
129       */
130       BehaviorLoadingLevel = 2;
131     }
132 }