1 // Copyright (C) 2007-2009 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
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.
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.
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
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // File : SMESHGUI_Make2DFrom3DOp.cxx
23 // Author : Open CASCADE S.A.S.
26 #include "SMESHGUI_Make2DFrom3DOp.h"
29 #include "SMESHGUI_Utils.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_MeshInfosBox.h"
34 // SALOME GUI includes
35 #include <LightApp_SelectionMgr.h>
37 #include <SUIT_Desktop.h>
38 #include <SUIT_MessageBox.h>
39 #include <SUIT_ResourceMgr.h>
40 #include <SUIT_OverrideCursor.h>
42 #include <SALOME_ListIO.hxx>
44 // SALOME KERNEL includes
45 #include <SALOMEDS_SObject.hxx>
46 #include <SALOMEDSClient_SObject.hxx>
50 #include <SALOMEconfig.h>
51 #include CORBA_SERVER_HEADER(SMESH_Gen)
52 #include CORBA_SERVER_HEADER(SMESH_MeshEditor)
58 #include <QPushButton>
59 #include <QVBoxLayout>
62 #include "SMDSAbs_ElementType.hxx"
63 #include "SMDSAbs_ElementType.hxx"
69 // =========================================================================================
71 * \brief Dialog to show creted mesh statistic
73 //=======================================================================
75 SMESHGUI_Make2DFrom3DDlg::SMESHGUI_Make2DFrom3DDlg( QWidget* parent )
76 : SMESHGUI_Dialog( parent, false, true, Close/* | Help*/ )
78 setWindowTitle( tr("CAPTION") );
79 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
80 aDlgLay->setMargin( 0 );
81 aDlgLay->setSpacing( SPACING );
82 QFrame* aMainFrame = createMainFrame(mainFrame());
83 aDlgLay->addWidget(aMainFrame);
84 aDlgLay->setStretchFactor(aMainFrame, 1);
87 // =========================================================================================
89 * \brief Dialog destructor
91 //=======================================================================
93 SMESHGUI_Make2DFrom3DDlg::~SMESHGUI_Make2DFrom3DDlg()
97 //=======================================================================
98 // function : createMainFrame()
99 // purpose : Create frame containing dialog's fields
100 //=======================================================================
102 QFrame* SMESHGUI_Make2DFrom3DDlg::createMainFrame (QWidget* theParent)
104 QFrame* aFrame = new QFrame(theParent);
106 SUIT_ResourceMgr* rm = resourceMgr();
107 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_2D_FROM_3D")));
110 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
111 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
112 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
113 myMeshName = new QLabel(nameBox);
114 nameBoxLayout->addWidget(myMeshName);
118 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
120 // add all widgets to aFrame
121 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
122 aLay->setMargin( 0 );
123 aLay->setSpacing( 0 );
124 aLay->addWidget( nameBox );
125 aLay->addWidget( myFullInfo );
127 ((QPushButton*) button( OK ))->setDefault( true );
131 //================================================================================
133 * \brief set name of the mesh
135 //================================================================================
137 void SMESHGUI_Make2DFrom3DDlg::SetMeshName(const QString& theName)
139 myMeshName->setText( theName );
142 //================================================================================
144 * \brief set mesh info
146 //================================================================================
148 void SMESHGUI_Make2DFrom3DDlg::SetMeshInfo(const SMESH::long_array& theInfo)
150 myFullInfo->SetMeshInfo( theInfo );
153 //================================================================================
157 //================================================================================
159 SMESHGUI_Make2DFrom3DOp::SMESHGUI_Make2DFrom3DOp()
160 : SMESHGUI_Operation()
162 myDlg = new SMESHGUI_Make2DFrom3DDlg(desktop());
165 //================================================================================
169 //================================================================================
171 SMESHGUI_Make2DFrom3DOp::~SMESHGUI_Make2DFrom3DOp()
175 //================================================================================
177 * \brief perform it's intention action: compute 2D mesh on 3D
179 //================================================================================
181 void SMESHGUI_Make2DFrom3DOp::startOperation()
183 myMesh = SMESH::SMESH_Mesh::_nil();
186 LightApp_SelectionMgr *Sel = selectionMgr();
187 SALOME_ListIO selected; Sel->selectedObjects( selected );
189 int nbSel = selected.Extent();
191 SUIT_MessageBox::warning(desktop(),
192 tr("SMESH_WRN_WARNING"),
193 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
198 Handle(SALOME_InteractiveObject) anIO = selected.First();
199 myMesh = SMESH::GetMeshByIO(anIO);
200 if (myMesh->_is_nil()) {
201 SUIT_MessageBox::warning(desktop(),
202 tr("SMESH_WRN_WARNING"),
203 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
208 SMESHGUI_Operation::startOperation();
211 // backup mesh info before 2D mesh computation
212 SMESH::long_array_var anOldInfo = myMesh->GetMeshInfo();
215 if (!compute2DMesh()) {
216 SUIT_MessageBox::warning(desktop(),
217 tr("SMESH_WRN_WARNING"),
218 tr("SMESH_WRN_COMPUTE_FAILED"));
222 // get new mesh statistic
223 SMESH::long_array_var aNewInfo = myMesh->GetMeshInfo();
224 // get difference in mesh statistic from old to new
225 for ( int i = SMDSEntity_Node; i < SMDSEntity_Last; i++ )
226 aNewInfo[i] -= anOldInfo[i];
228 // update presentation
229 SMESH::Update(anIO, SMESH::eDisplay);
231 // show computated result
232 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
234 myDlg->SetMeshName( aMeshSObj->GetName().c_str() );
235 myDlg->SetMeshInfo( aNewInfo );
236 myDlg->show(); /*exec();*/
240 //================================================================================
242 * \brief compute 2D mesh on initial 3D
244 //================================================================================
246 bool SMESHGUI_Make2DFrom3DOp::compute2DMesh()
248 SUIT_OverrideCursor wc;
249 SMESH::SMESH_MeshEditor_var aMeshEditor = myMesh->GetMeshEditor();
250 return aMeshEditor->Make2DMeshFrom3D();