1 // Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE
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.
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.
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
17 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_Make2DFrom3DOp.cxx
21 // Author : Open CASCADE S.A.S.
24 #include "SMESHGUI_Make2DFrom3DOp.h"
27 #include "SMESHGUI_Utils.h"
28 #include "SMESHGUI_VTKUtils.h"
29 #include "SMESHGUI_MeshUtils.h"
30 #include "SMESHGUI_MeshInfosBox.h"
32 // SALOME GUI includes
33 #include <LightApp_SelectionMgr.h>
35 #include <SUIT_Desktop.h>
36 #include <SUIT_MessageBox.h>
37 #include <SUIT_ResourceMgr.h>
38 #include <SUIT_OverrideCursor.h>
40 #include <SALOME_ListIO.hxx>
42 // SALOME KERNEL includes
43 #include <SALOMEDS_SObject.hxx>
44 #include <SALOMEDSClient_SObject.hxx>
48 #include <SALOMEconfig.h>
49 #include CORBA_SERVER_HEADER(SMESH_Gen)
50 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
56 #include <QPushButton>
57 #include <QVBoxLayout>
60 #include "SMDSAbs_ElementType.hxx"
61 #include "SMDSAbs_ElementType.hxx"
67 // =========================================================================================
69 * \brief Dialog to show creted mesh statistic
71 //=======================================================================
73 SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
74 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
76 setWindowTitle( tr("CAPTION") );
77 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
78 aDlgLay->setMargin( 0 );
79 aDlgLay->setSpacing( SPACING );
80 QFrame* aMainFrame = createMainFrame(mainFrame());
81 aDlgLay->addWidget(aMainFrame);
82 aDlgLay->setStretchFactor(aMainFrame, 1);
85 // =========================================================================================
87 * \brief Dialog destructor
89 //=======================================================================
91 SMESHGUI_Make2DFrom3DDlg::~SMESHGUI_Make2DFrom3DDlg()
95 //=======================================================================
96 // function : createMainFrame()
97 // purpose : Create frame containing dialog's fields
98 //=======================================================================
100 QFrame* SMESHGUI_Make2DFrom3DDlg::createMainFrame (QWidget* theParent)
102 QFrame* aFrame = new QFrame(theParent);
104 SUIT_ResourceMgr* rm = resourceMgr();
105 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_2D_FROM_3D")));
108 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
109 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
110 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
111 myMeshName = new QLabel(nameBox);
112 nameBoxLayout->addWidget(myMeshName);
116 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
118 // add all widgets to aFrame
119 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
120 aLay->setMargin( 0 );
121 aLay->setSpacing( 0 );
122 aLay->addWidget( nameBox );
123 aLay->addWidget( myFullInfo );
125 ((QPushButton*) button( OK ))->setDefault( true );
129 //================================================================================
131 * \brief set name of the mesh
133 //================================================================================
135 void SMESHGUI_Make2DFrom3DDlg::SetMeshName(const QString& theName)
137 myMeshName->setText( theName );
140 //================================================================================
142 * \brief set mesh info
144 //================================================================================
146 void SMESHGUI_Make2DFrom3DDlg::SetMeshInfo(const SMESH::long_array& theInfo)
148 myFullInfo->SetMeshInfo( theInfo );
151 //================================================================================
155 //================================================================================
157 SMESHGUI_Make2DFrom3DOp::SMESHGUI_Make2DFrom3DOp()
158 : SMESHGUI_Operation()
160 myDlg = new SMESHGUI_Make2DFrom3DDlg(desktop());
163 //================================================================================
167 //================================================================================
169 SMESHGUI_Make2DFrom3DOp::~SMESHGUI_Make2DFrom3DOp()
173 //================================================================================
175 * \brief perform it's intention action: compute 2D mesh on 3D
177 //================================================================================
179 void SMESHGUI_Make2DFrom3DOp::startOperation()
181 myMesh = SMESH::SMESH_Mesh::_nil();
184 LightApp_SelectionMgr *Sel = selectionMgr();
185 SALOME_ListIO selected; Sel->selectedObjects( selected );
187 int nbSel = selected.Extent();
189 SUIT_MessageBox::warning(desktop(),
190 tr("SMESH_WRN_WARNING"),
191 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
196 Handle(SALOME_InteractiveObject) anIO = selected.First();
197 myMesh = SMESH::GetMeshByIO(anIO);
198 if (myMesh->_is_nil()) {
199 SUIT_MessageBox::warning(desktop(),
200 tr("SMESH_WRN_WARNING"),
201 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
206 SMESHGUI_Operation::startOperation();
209 // backup mesh info before 2D mesh computation
210 SMESH::long_array_var anOldInfo = myMesh->GetMeshInfo();
213 if (!compute2DMesh()) {
214 SUIT_MessageBox::warning(desktop(),
215 tr("SMESH_WRN_WARNING"),
216 tr("SMESH_WRN_COMPUTE_FAILED"));
220 // get new mesh statistic
221 SMESH::long_array_var aNewInfo = myMesh->GetMeshInfo();
222 // get difference in mesh statistic from old to new
223 for ( int i = SMDSEntity_Node; i < SMDSEntity_Last; i++ )
224 aNewInfo[i] -= anOldInfo[i];
226 // update presentation
227 SMESH::Update(anIO, SMESH::eDisplay);
229 // show computated result
230 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
232 myDlg->SetMeshName( aMeshSObj->GetName().c_str() );
233 myDlg->SetMeshInfo( aNewInfo );
234 myDlg->show(); /*exec();*/
236 SMESHGUI::Modified();
239 //================================================================================
241 * \brief compute 2D mesh on initial 3D
243 //================================================================================
245 bool SMESHGUI_Make2DFrom3DOp::compute2DMesh()
247 SUIT_OverrideCursor wc;
248 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
249 return aMeshEditor->Make2DMeshFrom3D();