Salome HOME
INT PAL 0052683: Parameter "Color group" in the "Create Group" dialog box is empty
[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 }
54
55 //=================================================================================
56 // function : ~SMESHGUI_PreviewDlg()
57 // purpose  : Destroys the object and frees any allocated resources
58 //=================================================================================
59 SMESHGUI_PreviewDlg::~SMESHGUI_PreviewDlg()
60 {
61   delete mySimulation;
62 }
63
64 //=================================================================================
65 // function : showPreview
66 // purpose  : Show preview in the viewer
67 //=================================================================================
68 void SMESHGUI_PreviewDlg::showPreview(){
69   if(mySimulation)
70     mySimulation->SetVisibility(true);
71 }
72
73 //=================================================================================
74 // function : hidePreview
75 // purpose  : Hide preview in the viewer
76 //=================================================================================
77 void SMESHGUI_PreviewDlg::hidePreview(){
78   if(mySimulation)
79     mySimulation->SetVisibility(false);
80 }
81
82 //=================================================================================
83 // function : connectPreviewControl
84 // purpose  : Connect the preview check box
85 //=================================================================================
86 void SMESHGUI_PreviewDlg::connectPreviewControl(){
87   connect(myPreviewCheckBox, SIGNAL(toggled(bool)), this, SLOT(onDisplaySimulation(bool)));
88 }
89
90
91 //=================================================================================
92 // function : toDisplaySimulation
93 // purpose  : 
94 //=================================================================================
95 void SMESHGUI_PreviewDlg::toDisplaySimulation() {
96   onDisplaySimulation(true);
97 }
98
99 //=================================================================================
100 // function : onDisplaySimulation
101 // purpose  : 
102 //=================================================================================
103 void SMESHGUI_PreviewDlg::onDisplaySimulation(bool toDisplayPreview) {
104   //Empty implementation here
105 }
106
107 //================================================================
108 // Function : setIsApplyAndClose
109 // Purpose  : Set value of the flag indicating that the dialog is
110 //            accepted by Apply & Close button
111 //================================================================
112 void SMESHGUI_PreviewDlg::setIsApplyAndClose( const bool theFlag )
113 {
114   myIsApplyAndClose = theFlag;
115 }
116
117 //================================================================
118 // Function : isApplyAndClose
119 // Purpose  : Get value of the flag indicating that the dialog is
120 //            accepted by Apply & Close button
121 //================================================================
122 bool SMESHGUI_PreviewDlg::isApplyAndClose() const
123 {
124   return myIsApplyAndClose;
125 }
126
127
128 //=================================================================================
129 // class    : SMESHGUI_SMESHGUI_MultiPreviewDlg()
130 // purpose  :
131 //=================================================================================
132 SMESHGUI_MultiPreviewDlg::SMESHGUI_MultiPreviewDlg( SMESHGUI* theModule ) :
133   mySMESHGUI( theModule ),
134   QDialog( SMESH::GetDesktop( theModule ) ),
135   myIsApplyAndClose( false )
136 {
137 }
138
139 //=================================================================================
140 // function : ~SMESHGUI_MultiPreviewDlg()
141 // purpose  : Destroys the object and frees any allocated resources
142 //=================================================================================
143 SMESHGUI_MultiPreviewDlg::~SMESHGUI_MultiPreviewDlg()
144 {
145   qDeleteAll( mySimulationList );
146 }
147
148 //=================================================================================
149 // function : showPreview
150 // purpose  : Show preview in the viewer
151 //=================================================================================
152 void SMESHGUI_MultiPreviewDlg::showPreview()
153 {
154   for ( int i = 0; i < mySimulationList.count(); i++ )
155     mySimulationList[i]->SetVisibility( true );
156 }
157
158 //=================================================================================
159 // function : hidePreview
160 // purpose  : Hide preview in the viewer
161 //=================================================================================
162 void SMESHGUI_MultiPreviewDlg::hidePreview()
163 {
164   for ( int i = 0; i < mySimulationList.count(); i++ )
165     mySimulationList[i]->SetVisibility( false );
166 }
167
168 //=================================================================================
169 // function : connectPreviewControl
170 // purpose  : Connect the preview check box
171 //=================================================================================
172 void SMESHGUI_MultiPreviewDlg::connectPreviewControl()
173 {
174   connect( myPreviewCheckBox, SIGNAL( toggled( bool ) ), this, SLOT( onDisplaySimulation( bool ) ) );
175 }
176
177
178 //=================================================================================
179 // function : toDisplaySimulation
180 // purpose  : 
181 //=================================================================================
182 void SMESHGUI_MultiPreviewDlg::toDisplaySimulation()
183 {
184   onDisplaySimulation( true );
185 }
186
187 //=================================================================================
188 // function : onDisplaySimulation
189 // purpose  : 
190 //=================================================================================
191 void SMESHGUI_MultiPreviewDlg::onDisplaySimulation( bool toDisplayPreview )
192 {
193   //Empty implementation here
194 }
195
196 //================================================================
197 // Function : setIsApplyAndClose
198 // Purpose  : Set value of the flag indicating that the dialog is
199 //            accepted by Apply & Close button
200 //================================================================
201 void SMESHGUI_MultiPreviewDlg::setIsApplyAndClose( const bool theFlag )
202 {
203   myIsApplyAndClose = theFlag;
204 }
205
206 //================================================================
207 // Function : isApplyAndClose
208 // Purpose  : Get value of the flag indicating that the dialog is
209 //            accepted by Apply & Close button
210 //================================================================
211 bool SMESHGUI_MultiPreviewDlg::isApplyAndClose() const
212 {
213   return myIsApplyAndClose;
214 }
215
216 //================================================================
217 // Function : setSimulationPreview
218 // Purpose  : 
219 //================================================================
220 void SMESHGUI_MultiPreviewDlg::setSimulationPreview( QList<SMESH::MeshPreviewStruct_var>& theMeshPreviewStruct )
221 {
222   hidePreview();
223   qDeleteAll( mySimulationList );
224   mySimulationList.clear();
225   for ( int i = 0; i < theMeshPreviewStruct.count(); i++ ) {
226     mySimulationList << new SMESHGUI_MeshEditPreview( SMESH::GetViewWindow( mySMESHGUI ) );
227     mySimulationList[i]->SetData( theMeshPreviewStruct[i].operator->() );
228   }
229 }