Salome HOME
INT PAL 0052775: Any dialogue with the selector raises an exception for second viewer
[modules/smesh.git] / src / SMESHGUI / SMESHGUI_PreviewDlg.cxx
1 // Copyright (C) 2007-2015  CEA/DEN, EDF R&D, 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 // SMESH SMESHGUI : GUI for SMESH component
24 // File   : SMESHGUI_PreviewDlg.cxx
25 // Author : Roman NIKOLAEV, Open CASCADE S.A.S.
26 // SMESH includes
27 //
28
29 //SMESH includes
30 #include "SMESHGUI.h"
31 #include "SMESHGUI_PreviewDlg.h"
32 #include "SMESHGUI_MeshEditPreview.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_Utils.h"
35
36 //GUI includes
37 #include <SUIT_Desktop.h>
38
39 //QT includes
40 #include <QCheckBox>
41
42
43 //=================================================================================
44 // class    : SMESHGUI_SMESHGUI_PreviewDlg()
45 // purpose  :
46 //=================================================================================
47 SMESHGUI_PreviewDlg::SMESHGUI_PreviewDlg(SMESHGUI* theModule) :
48   mySMESHGUI(theModule),
49   QDialog(SMESH::GetDesktop( theModule )),
50   myIsApplyAndClose( false )
51 {
52   mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
53   connect(mySMESHGUI, SIGNAL(SignalCloseView()),            this, SLOT(onCloseView()));
54   connect(mySMESHGUI, SIGNAL(SignalActivatedViewManager()), this, SLOT(onOpenView()));
55 }
56
57 //=================================================================================
58 // function : ~SMESHGUI_PreviewDlg()
59 // purpose  : Destroys the object and frees any allocated resources
60 //=================================================================================
61 SMESHGUI_PreviewDlg::~SMESHGUI_PreviewDlg()
62 {
63   delete mySimulation;
64 }
65
66 //=================================================================================
67 // function : showPreview
68 // purpose  : Show preview in the viewer
69 //=================================================================================
70 void SMESHGUI_PreviewDlg::showPreview(){
71   if(mySimulation && mySimulation->GetActor())
72     mySimulation->SetVisibility(true);
73 }
74
75 //=================================================================================
76 // function : hidePreview
77 // purpose  : Hide preview in the viewer
78 //=================================================================================
79 void SMESHGUI_PreviewDlg::hidePreview(){
80   if(mySimulation && mySimulation->GetActor())
81     mySimulation->SetVisibility(false);
82 }
83
84 //=================================================================================
85 // function : connectPreviewControl
86 // purpose  : Connect the preview check box
87 //=================================================================================
88 void SMESHGUI_PreviewDlg::connectPreviewControl(){
89   connect(myPreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(onDisplaySimulation(bool)));
90 }
91
92 //=================================================================================
93 // function : toDisplaySimulation
94 // purpose  : 
95 //=================================================================================
96 void SMESHGUI_PreviewDlg::toDisplaySimulation() {
97   onDisplaySimulation(true);
98 }
99
100 //=================================================================================
101 // function : onDisplaySimulation
102 // purpose  : 
103 //=================================================================================
104 void SMESHGUI_PreviewDlg::onDisplaySimulation(bool toDisplayPreview) {
105   //Empty implementation here
106 }
107
108 //================================================================
109 // Function : setIsApplyAndClose
110 // Purpose  : Set value of the flag indicating that the dialog is
111 //            accepted by Apply & Close button
112 //================================================================
113 void SMESHGUI_PreviewDlg::setIsApplyAndClose( const bool theFlag )
114 {
115   myIsApplyAndClose = theFlag;
116 }
117
118 //================================================================
119 // Function : isApplyAndClose
120 // Purpose  : Get value of the flag indicating that the dialog is
121 //            accepted by Apply & Close button
122 //================================================================
123 bool SMESHGUI_PreviewDlg::isApplyAndClose() const
124 {
125   return myIsApplyAndClose;
126 }
127
128 //=================================================================================
129 // function : onCloseView()
130 // purpose  : SLOT called when close view
131 //=================================================================================
132 void SMESHGUI_PreviewDlg::onCloseView()
133 {
134   if ( mySimulation && mySimulation->GetActor())
135     mySimulation->SetVisibility(false);
136   delete mySimulation;
137   mySimulation=0;
138 }
139
140 //=================================================================================
141 // function : onOpenView()
142 // purpose  : SLOT called when open view
143 //=================================================================================
144 void SMESHGUI_PreviewDlg::onOpenView()
145 {
146   if ( !mySimulation)
147     mySimulation = new SMESHGUI_MeshEditPreview(SMESH::GetViewWindow( mySMESHGUI ));
148 }
149 //=================================================================================
150 // class    : SMESHGUI_SMESHGUI_MultiPreviewDlg()
151 // purpose  :
152 //=================================================================================
153 SMESHGUI_MultiPreviewDlg::SMESHGUI_MultiPreviewDlg( SMESHGUI* theModule ) :
154   mySMESHGUI( theModule ),
155   QDialog( SMESH::GetDesktop( theModule ) ),
156   myIsApplyAndClose( false )
157 {
158   mySimulationList.clear();
159   connect(mySMESHGUI, SIGNAL(SignalCloseView()), this, SLOT(onCloseView()));
160 }
161
162 //=================================================================================
163 // function : ~SMESHGUI_MultiPreviewDlg()
164 // purpose  : Destroys the object and frees any allocated resources
165 //=================================================================================
166 SMESHGUI_MultiPreviewDlg::~SMESHGUI_MultiPreviewDlg()
167 {
168   qDeleteAll( mySimulationList );
169 }
170
171 //=================================================================================
172 // function : showPreview
173 // purpose  : Show preview in the viewer
174 //=================================================================================
175 void SMESHGUI_MultiPreviewDlg::showPreview()
176 {
177   for ( int i = 0; i < mySimulationList.count(); i++ )
178     if(mySimulationList[i] && mySimulationList[i]->GetActor())
179       mySimulationList[i]->SetVisibility( true );
180 }
181
182 //=================================================================================
183 // function : hidePreview
184 // purpose  : Hide preview in the viewer
185 //=================================================================================
186 void SMESHGUI_MultiPreviewDlg::hidePreview()
187 {
188   for ( int i = 0; i < mySimulationList.count(); i++ )
189     if(mySimulationList[i] && mySimulationList[i]->GetActor())
190       mySimulationList[i]->SetVisibility( false );
191 }
192
193 //=================================================================================
194 // function : connectPreviewControl
195 // purpose  : Connect the preview check box
196 //=================================================================================
197 void SMESHGUI_MultiPreviewDlg::connectPreviewControl()
198 {
199   connect( myPreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onDisplaySimulation( bool ) ) );
200 }
201
202 //=================================================================================
203 // function : toDisplaySimulation
204 // purpose  : 
205 //=================================================================================
206 void SMESHGUI_MultiPreviewDlg::toDisplaySimulation()
207 {
208   onDisplaySimulation( true );
209 }
210
211 //=================================================================================
212 // function : onDisplaySimulation
213 // purpose  : 
214 //=================================================================================
215 void SMESHGUI_MultiPreviewDlg::onDisplaySimulation( bool toDisplayPreview )
216 {
217   //Empty implementation here
218 }
219
220 //================================================================
221 // Function : setIsApplyAndClose
222 // Purpose  : Set value of the flag indicating that the dialog is
223 //            accepted by Apply & Close button
224 //================================================================
225 void SMESHGUI_MultiPreviewDlg::setIsApplyAndClose( const bool theFlag )
226 {
227   myIsApplyAndClose = theFlag;
228 }
229
230 //================================================================
231 // Function : isApplyAndClose
232 // Purpose  : Get value of the flag indicating that the dialog is
233 //            accepted by Apply & Close button
234 //================================================================
235 bool SMESHGUI_MultiPreviewDlg::isApplyAndClose() const
236 {
237   return myIsApplyAndClose;
238 }
239
240 //================================================================
241 // Function : setSimulationPreview
242 // Purpose  : 
243 //================================================================
244 void SMESHGUI_MultiPreviewDlg::setSimulationPreview( QList<SMESH::MeshPreviewStruct_var>& theMeshPreviewStruct )
245 {
246   hidePreview();
247   qDeleteAll( mySimulationList );
248   mySimulationList.clear();
249   for ( int i = 0; i < theMeshPreviewStruct.count(); i++ ) {
250     mySimulationList << new SMESHGUI_MeshEditPreview( SMESH::GetViewWindow( mySMESHGUI ) );
251     mySimulationList[i]->SetData( theMeshPreviewStruct[i].operator->() );
252   }
253 }
254
255 //=================================================================================
256 // function : onCloseView()
257 // purpose  : SLOT called when close view
258 //=================================================================================
259 void SMESHGUI_MultiPreviewDlg::onCloseView()
260 {
261   qDeleteAll( mySimulationList );
262   mySimulationList.clear();
263 }