1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 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
24 // File : SMESHGUI_ComputeDlg.cxx
25 // Author : Edward AGAPOV
28 #include "SMESHGUI_ComputeDlg.h"
31 #include "SMESHGUI_GEOMGenUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_HypothesesUtils.h"
36 #include "SMESHGUI_MeshEditPreview.h"
37 #include "SMESH_ActorUtils.h"
39 #include "SMDS_SetIterator.hxx"
40 #include "SMDS_Mesh.hxx"
43 #include "GEOM_Actor.h"
45 #include "LightApp_SelectionMgr.h"
46 #include "LightApp_UpdateFlags.h"
47 #include "SALOMEDSClient_SObject.hxx"
48 #include "SALOME_ListIO.hxx"
49 #include "SVTK_ViewWindow.h"
50 #include "SVTK_ViewModel.h"
51 #include "SalomeApp_Tools.h"
52 #include "SalomeApp_Application.h"
53 #include "SUIT_ResourceMgr.h"
54 #include "SUIT_OverrideCursor.h"
55 #include "SUIT_MessageBox.h"
56 #include "SUIT_Desktop.h"
57 #include "SUIT_Study.h"
58 #include "OB_Browser.h"
61 #include <BRep_Tool.hxx>
63 #include <TopExp_Explorer.hxx>
64 #include <TopTools_IndexedMapOfShape.hxx>
67 #include <TopLoc_Location.hxx>
68 #include <Poly_Triangulation.hxx>
69 #include <Bnd_Box.hxx>
70 #include <BRepBndLib.hxx>
71 #include <BRepMesh_IncrementalMesh.hxx>
73 #include <Standard_ErrorHandler.hxx>
78 #include <qpushbutton.h>
80 #include <qbuttongroup.h>
81 #include <qradiobutton.h>
84 #include <qhgroupbox.h>
85 #include <qvgroupbox.h>
87 #include <vtkProperty.h>
90 #include <SALOMEconfig.h>
91 #include CORBA_SERVER_HEADER(SMESH_Gen)
92 #include CORBA_SERVER_HEADER(SMESH_Mesh)
103 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
105 #define _SEPARATOR(father) \
107 /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
108 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
109 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
110 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
111 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
115 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
118 using namespace SMESH;
122 //=============================================================================
124 * \brief Allocate some memory at construction and release it at destruction.
125 * Is used to be able to continue working after mesh generation or visualization
126 * break due to lack of memory
128 //=============================================================================
133 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
134 void release() { delete [] myBuf; myBuf = 0; }
135 ~MemoryReserve() { release(); }
138 // =========================================================================================
140 * \brief Class showing shapes without publishing
142 // =========================================================================================
144 class TShapeDisplayer
147 // -----------------------------------------------------------------------
148 TShapeDisplayer(): myViewWindow(0)
150 myProperty = vtkProperty::New();
151 myProperty->SetRepresentationToWireframe();
152 myProperty->SetColor( 250, 0, 250 );
153 myProperty->SetAmbientColor( 250, 0, 250 );
154 myProperty->SetDiffuseColor( 250, 0, 250 );
155 //myProperty->SetSpecularColor( 250, 0, 250 );
156 myProperty->SetLineWidth( 5 );
158 // -----------------------------------------------------------------------
162 myProperty->Delete();
164 // -----------------------------------------------------------------------
167 if ( hasViewWindow() ) {
168 TActorIterator actorIt = actorIterator();
169 while ( actorIt.more() )
170 if (VTKViewer_Actor* anActor = actorIt.next()) {
171 myViewWindow->RemoveActor( anActor );
175 myIndexToShape.Clear();
177 myShownActors.clear();
180 // -----------------------------------------------------------------------
181 void SetVisibility (bool theVisibility)
183 TActorIterator actorIt = shownIterator();
184 while ( actorIt.more() )
185 if (VTKViewer_Actor* anActor = actorIt.next())
186 anActor->SetVisibility(theVisibility);
187 SMESH::RepaintCurrentView();
189 // -----------------------------------------------------------------------
190 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
193 if ( !aMainShape->_is_nil() )
194 mainEntry = aMainShape->GetStudyEntry();
195 return ( myMainEntry == mainEntry &&
196 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
198 // -----------------------------------------------------------------------
199 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
201 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
203 if ( !aMainShape->_is_nil() )
204 mainEntry = aMainShape->GetStudyEntry();
205 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
208 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
209 checkTriangulation( aShape );
210 TopExp::MapShapes(aShape, myIndexToShape);
211 myActors.resize( myIndexToShape.Extent(), 0 );
212 myShownActors.reserve( myIndexToShape.Extent() );
214 myMainEntry = mainEntry;
215 myViewWindow = aViewWindow;
217 if ( only ) { // hide shown actors
218 TActorIterator actorIt = shownIterator();
219 while ( actorIt.more() )
220 if (VTKViewer_Actor* anActor = actorIt.next())
221 anActor->SetVisibility(false);
222 myShownActors.clear();
224 // find actors to show
225 TopoDS_Shape aShape = myIndexToShape( subShapeID );
226 if ( !aShape.IsNull() ) {
227 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
228 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
229 //checkTriangulation( exp.Current() );
230 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
231 myShownActors.push_back( anActor );
233 if ( type == TopAbs_FACE ) {
234 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
235 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
236 if ( !BRep_Tool::Degenerated( edge ))
237 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
238 myShownActors.push_back( anActor );
242 myBuiltSubs.insert( subShapeID );
245 // -----------------------------------------------------------------------
249 typedef std::vector<GEOM_Actor*> TActorVec;
251 TActorVec myShownActors;
252 TopTools_IndexedMapOfShape myIndexToShape;
254 SVTK_ViewWindow* myViewWindow;
255 vtkProperty* myProperty;
256 std::set<int> myBuiltSubs;
258 // -----------------------------------------------------------------------
259 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
260 TActorIterator actorIterator() {
261 return TActorIterator( myActors.begin(), myActors.end() );
263 TActorIterator shownIterator() {
264 return TActorIterator( myShownActors.begin(), myShownActors.end() );
266 // -----------------------------------------------------------------------
267 GEOM_Actor* getActor(const TopoDS_Shape& shape)
269 int index = myIndexToShape.FindIndex( shape ) - 1;
270 if ( index < 0 || index >= myActors.size() )
272 GEOM_Actor* & actor = myActors[ index ];
274 actor = GEOM_Actor::New();
276 actor->SetShape(shape,0,0);
277 actor->SetProperty(myProperty);
278 actor->SetShadingProperty(myProperty);
279 actor->SetWireframeProperty(myProperty);
280 actor->SetPreviewProperty(myProperty);
281 actor->PickableOff();
282 // if ( shape.ShapeType() == TopAbs_EDGE )
283 // actor->SubShapeOn();
284 myViewWindow->AddActor( actor );
289 // -----------------------------------------------------------------------
290 void checkTriangulation(const TopoDS_Shape& shape)
292 TopLoc_Location aLoc;
293 Standard_Boolean alreadymesh = Standard_True;
294 TopExp_Explorer ex(shape, TopAbs_FACE);
296 for (; ex.More(); ex.Next()) {
297 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
298 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
299 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
302 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
303 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
304 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
305 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
307 if (alreadymesh) return;
308 // Compute default deflection
310 BRepBndLib::Add(shape, B);
311 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
312 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
313 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
314 BRepMesh_IncrementalMesh MESH(shape,deflection);
316 // -----------------------------------------------------------------------
317 bool hasViewWindow() const
319 if ( !myViewWindow ) return false;
321 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
322 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
328 // =========================================================================================
330 * \brief Return text describing an error
332 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
333 QString errorText(int errCode, const char* comment)
337 CASE2TEXT( COMPERR_OK );
338 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
339 CASE2TEXT( COMPERR_STD_EXCEPTION );
340 CASE2TEXT( COMPERR_OCC_EXCEPTION );
341 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
342 CASE2TEXT( COMPERR_EXCEPTION );
343 CASE2TEXT( COMPERR_MEMORY_PB );
344 CASE2TEXT( COMPERR_BAD_SHAPE );
345 case SMESH::COMPERR_ALGO_FAILED:
346 if ( strlen(comment) == 0 )
347 text = QObject::tr("COMPERR_ALGO_FAILED");
350 text = QString("#%1").arg( -errCode );
352 if ( text.length() > 0 ) text += ". ";
353 return text + comment;
355 // -----------------------------------------------------------------------
357 * \brief Return SO of a subshape
359 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
361 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
362 if ( subShapeID == 1 || !so )
364 _PTR(ChildIterator) it;
365 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
366 it = study->NewChildIterator(so);
369 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
370 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
371 if ( !geom->_is_nil() ) {
372 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
373 if ( list->length() == 1 && list[0] == subShapeID )
380 // -----------------------------------------------------------------------
382 * \brief Return subshape by ID
384 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
386 GEOM::GEOM_Object_var aSubShape;
387 if ( subShapeID == 1 )
388 aSubShape = aMainShape;
389 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
390 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
392 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
393 return aSubShape._retn();
395 // -----------------------------------------------------------------------
397 * \brief Return shape type name
399 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
400 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
403 if ( !aShape->_is_nil() ) {
404 switch ( aShape->GetShapeType() ) {
411 CASE2NAME( COMPSOLID );
412 CASE2NAME( COMPOUND );
418 // -----------------------------------------------------------------------
420 * \brief Return text describing a subshape
422 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
425 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
426 text = aSO->GetName();
428 text = QString("#%1").arg( subShapeID );
429 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
430 if ( typeName.length() )
431 text += QString(" (%1)").arg(typeName);
435 // -----------------------------------------------------------------------
437 * \brief Return a list of selected rows
439 int getSelectedRows(QTable* table, list< int > & rows)
442 int nbSel = table->numSelections();
443 for ( int i = 0; i < nbSel; ++i )
445 QTableSelection selected = table->selection(i);
446 if ( !selected.isActive() ) continue;
447 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
448 rows.push_back( row );
450 if (rows.empty() && table->currentRow() > -1 )
451 rows.push_back( table->currentRow() );
459 // =========================================================================================
461 * \brief Box showing mesh info
463 // =========================================================================================
465 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
466 :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
469 QLabel* lab1 = new QLabel(this);
470 QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
471 QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
472 QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
474 QFont italic = lab1->font(); italic.setItalic(true);
475 QFont bold = lab1->font(); bold.setBold(true);
477 lab1->setMinimumWidth(100); lab1->setFont( italic );
478 lab2->setMinimumWidth(100); lab2->setFont( italic );
479 lab3->setMinimumWidth(100); lab3->setFont( italic );
480 lab4->setMinimumWidth(100); lab4->setFont( italic );
485 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
486 myNbNode = new QLabel( this );
493 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
494 myNbEdge = new QLabel( this );
495 myNbLinEdge = new QLabel( this );
496 myNbQuadEdge = new QLabel( this );
501 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
502 myNbFace = new QLabel( this );
503 myNbLinFace = new QLabel( this );
504 myNbQuadFace = new QLabel( this );
506 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
507 myNbTrai = new QLabel( this );
508 myNbLinTrai = new QLabel( this );
509 myNbQuadTrai = new QLabel( this );
511 new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
512 myNbQuad = new QLabel( this );
513 myNbLinQuad = new QLabel( this );
514 myNbQuadQuad = new QLabel( this );
516 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
517 myNbPolyg = new QLabel( this );
518 new QLabel("",this );
519 new QLabel("", this );
524 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
525 myNbVolum = new QLabel( this );
526 myNbLinVolum = new QLabel( this );
527 myNbQuadVolum = new QLabel( this );
529 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
530 myNbTetra = new QLabel( this );
531 myNbLinTetra = new QLabel( this );
532 myNbQuadTetra = new QLabel( this );
534 new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
535 myNbHexa = new QLabel( this );
536 myNbLinHexa = new QLabel( this );
537 myNbQuadHexa = new QLabel( this );
539 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
540 myNbPyra = new QLabel( this );
541 myNbLinPyra = new QLabel( this );
542 myNbQuadPyra = new QLabel( this );
544 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
545 myNbPrism = new QLabel( this );
546 myNbLinPrism = new QLabel( this );
547 myNbQuadPrism = new QLabel( this );
549 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
550 myNbPolyh = new QLabel( this );
551 new QLabel("", this );
552 new QLabel("", this );
557 new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
558 myNbNode = new QLabel( this );
563 new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
564 myNbEdge = new QLabel( this );
565 myNbLinEdge = new QLabel( this );
566 myNbQuadEdge = new QLabel( this );
569 new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
570 myNbFace = new QLabel( this );
571 myNbLinFace = new QLabel( this );
572 myNbQuadFace = new QLabel( this );
575 new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
576 myNbVolum = new QLabel( this );
577 myNbLinVolum = new QLabel( this );
578 myNbQuadVolum = new QLabel( this );
582 // =========================================================================================
584 * \brief Set mesh info
586 // =========================================================================================
588 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
590 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
594 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
597 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
598 myNbEdge ->setText( QString("%1").arg( nbTot ));
599 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
600 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
603 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
604 myNbFace ->setText( QString("%1").arg( nbTot ));
605 myNbLinFace ->setText( QString("%1").arg( nbLin ));
606 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
609 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
610 myNbVolum ->setText( QString("%1").arg( nbTot ));
611 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
612 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
617 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
618 myNbTrai ->setText( QString("%1").arg( nbTot ));
619 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
620 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
622 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
623 myNbQuad ->setText( QString("%1").arg( nbTot ));
624 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
625 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
627 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
630 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
631 myNbTetra ->setText( QString("%1").arg( nbTot ));
632 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
633 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
635 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
636 myNbHexa ->setText( QString("%1").arg( nbTot ));
637 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
638 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
640 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
641 myNbPyra ->setText( QString("%1").arg( nbTot ));
642 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
643 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
645 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
646 myNbPrism ->setText( QString("%1").arg( nbTot ));
647 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
648 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
650 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
654 // =========================================================================================
656 * \brief Dialog to compute a mesh and show computation errors
658 //=======================================================================
660 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, Close/* | Help*/ )
662 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
664 QFrame* aMainFrame = createMainFrame (mainFrame());
666 aDlgLay->addWidget(aMainFrame);
668 aDlgLay->setStretchFactor(aMainFrame, 1);
671 //=======================================================================
672 // function : createMainFrame()
673 // purpose : Create frame containing dialog's fields
674 //=======================================================================
676 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
678 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
680 QFrame* aFrame = new QFrame(theParent);
682 SUIT_ResourceMgr* rm = resourceMgr();
683 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
687 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
688 aPixGrp->setExclusive(TRUE);
689 QRadioButton* aRBut = new QRadioButton(aPixGrp);
690 aRBut->setPixmap(iconCompute);
691 aRBut->setChecked(TRUE);
695 QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
696 myMeshName = new QLabel(nameBox);
700 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
701 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
703 // Computation errors
705 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "myCompErrorGroup");
706 myTable = new QTable( 1, NB_COLUMNS, myCompErrorGroup, "myTable");
707 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup, "myShowBtn");
708 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup, "myPublishBtn");
709 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup, "myBadMeshBtn");
711 myTable->setReadOnly( TRUE );
712 myTable->hideColumn( COL_PUBLISHED );
713 myTable->hideColumn( COL_SHAPEID );
714 myTable->hideColumn( COL_BAD_MESH );
715 myTable->setColumnStretchable( COL_ERROR, 1 );
716 for ( int col = 0; col < NB_COLUMNS; ++col ) {
719 CASE2HEADER( COL_ALGO );
720 CASE2HEADER( COL_SHAPE );
721 CASE2HEADER( COL_ERROR );
722 CASE2HEADER( COL_SHAPEID );
723 CASE2HEADER( COL_PUBLISHED);
725 myTable->horizontalHeader()->setLabel( col, header );
728 myCompErrorGroup->setColumnLayout(0, Qt::Vertical);
729 myCompErrorGroup->layout()->setSpacing(0);
730 myCompErrorGroup->layout()->setMargin(0);
731 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup->layout());
732 grpLayout->setAlignment(Qt::AlignTop);
733 grpLayout->setSpacing(SPACING);
734 grpLayout->setMargin(MARGIN);
735 grpLayout->addMultiCellWidget( myTable, 0, 3, 0, 0 );
736 grpLayout->addWidget ( myShowBtn, 0, 1 );
737 grpLayout->addWidget ( myPublishBtn, 1, 1 );
738 grpLayout->addWidget ( myBadMeshBtn, 2, 1 );
739 grpLayout->setRowStretch( 3, 1 );
741 // Hypothesis definition errors
743 myHypErrorGroup = new QGroupBox(1,Qt::Vertical, tr("SMESH_WRN_MISSING_PARAMETERS"),aFrame);
744 myHypErrorLabel = new QLabel(myHypErrorGroup);
748 myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
749 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
750 QFont bold = memLackLabel->font(); bold.setBold(true);
751 memLackLabel->setFont( bold );
752 memLackLabel->setMinimumWidth(300);
754 // add all widgets to aFrame
755 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
756 aLay->addWidget( aPixGrp );
757 aLay->addWidget( nameBox );
758 aLay->addWidget( myBriefInfo );
759 aLay->addWidget( myFullInfo );
760 aLay->addWidget( myHypErrorGroup );
761 aLay->addWidget( myCompErrorGroup );
762 aLay->addWidget( myMemoryLackGroup );
763 aLay->setStretchFactor( myCompErrorGroup, 1 );
765 ((QPushButton*) button( OK ))->setDefault( true );
770 //================================================================================
774 //================================================================================
776 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
778 myDlg = new SMESHGUI_ComputeDlg;
779 myTShapeDisplayer = new TShapeDisplayer();
780 myBadMeshDisplayer = 0;
782 //myHelpFileName = "/files/about_meshes.htm"; // V3
783 myHelpFileName = "about_meshes_page.html"; // V4
785 // connect signals and slots
786 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
787 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
788 connect(myDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
789 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
790 connect(table(),SIGNAL(currentChanged(int,int)), SLOT(currentCellChanged()));
793 //=======================================================================
794 // function : startOperation()
795 // purpose : Init dialog fields, connect signals and slots, show dialog
796 //=======================================================================
798 void SMESHGUI_ComputeOp::startOperation()
800 SMESHGUI_Operation::startOperation();
804 myMesh = SMESH::SMESH_Mesh::_nil();
805 myMainShape = GEOM::GEOM_Object::_nil();
807 LightApp_SelectionMgr *Sel = selectionMgr();
808 SALOME_ListIO selected; Sel->selectedObjects( selected );
810 int nbSel = selected.Extent();
812 SUIT_MessageBox::warn1(desktop(),
813 tr("SMESH_WRN_WARNING"),
814 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
820 Handle(SALOME_InteractiveObject) IObject = selected.First();
821 myMesh = SMESH::GetMeshByIO(IObject);
822 if (myMesh->_is_nil()) {
823 SUIT_MessageBox::warn1(desktop(),
824 tr("SMESH_WRN_WARNING"),
825 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
833 MemoryReserve aMemoryReserve;
835 SMESH::compute_error_array_var aCompErrors;
838 bool computeFailed = true, memoryLack = false;
840 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
841 myMainShape = myMesh->GetShapeToMesh();
842 bool hasShape = myMesh->HasShapeToMesh();
843 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
844 if ( shapeOK && aMeshSObj )
846 myDlg->myMeshName->setText( aMeshSObj->GetName() );
847 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
848 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
849 if ( errors->length() > 0 ) {
850 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
852 SUIT_OverrideCursor aWaitCursor;
854 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
857 if (gen->Compute(myMesh, myMainShape))
858 computeFailed = false;
860 catch(const SALOME::SALOME_Exception & S_ex){
864 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
867 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
868 // check if there are memory problems
869 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
870 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
872 catch(const SALOME::SALOME_Exception & S_ex){
876 // NPAL16631: if ( !memoryLack )
878 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
879 update( UF_ObjBrowser | UF_Model );
882 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
883 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
886 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
889 SMESH::Update(IObject, true);
893 MESSAGE ( "Exception thrown during mesh visualization" );
895 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
896 SMESH::OnVisuException();
903 Sel->setSelectedObjects( selected );
908 aMemoryReserve.release();
910 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
911 myDlg->myMemoryLackGroup->hide();
915 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
916 bool noHypoError = ( aHypErrors.isEmpty() );
920 myDlg->myMemoryLackGroup->show();
921 myDlg->myFullInfo->hide();
922 myDlg->myBriefInfo->hide();
923 myDlg->myHypErrorGroup->hide();
924 myDlg->myCompErrorGroup->hide();
926 else if ( noCompError && noHypoError )
928 myDlg->myFullInfo->SetInfoByMesh( myMesh );
929 myDlg->myFullInfo->show();
930 myDlg->myBriefInfo->hide();
931 myDlg->myHypErrorGroup->hide();
932 myDlg->myCompErrorGroup->hide();
936 QTable* tbl = myDlg->myTable;
937 myDlg->myBriefInfo->SetInfoByMesh( myMesh );
938 myDlg->myBriefInfo->show();
939 myDlg->myFullInfo->hide();
942 myDlg->myHypErrorGroup->hide();
945 myDlg->myHypErrorGroup->show();
946 myDlg->myHypErrorLabel->setText( aHypErrors );
950 myDlg->myCompErrorGroup->hide();
953 myDlg->myCompErrorGroup->show();
956 myDlg->myPublishBtn->hide();
957 myDlg->myShowBtn->hide();
960 myDlg->myPublishBtn->show();
961 myDlg->myShowBtn->show();
964 // fill table of errors
965 tbl->setNumRows( aCompErrors->length() );
966 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
967 else tbl->showColumn( COL_SHAPE );
968 tbl->setColumnWidth( COL_ERROR, 200 );
970 bool hasBadMesh = false;
971 for ( int row = 0; row < aCompErrors->length(); ++row )
973 SMESH::ComputeError & err = aCompErrors[ row ];
974 tbl->setText( row, COL_ALGO, err.algoName.in() );
975 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
976 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
978 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
979 tbl->setText( row, COL_SHAPE, text );
981 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
982 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
984 text = err.hasBadMesh ? "hasBadMesh" : "";
985 tbl->setText( row, COL_BAD_MESH, text );
986 if ( err.hasBadMesh ) hasBadMesh = true;
988 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
989 tbl->adjustRow( row );
991 tbl->adjustColumn( COL_ALGO );
992 tbl->adjustColumn( COL_SHAPE );
995 myDlg->myBadMeshBtn->show();
997 myDlg->myBadMeshBtn->hide();
999 tbl->setCurrentCell(0,0);
1000 currentCellChanged(); // to update buttons
1006 //================================================================================
1008 * \brief Stops operation
1010 //================================================================================
1012 void SMESHGUI_ComputeOp::stopOperation()
1014 SMESHGUI_Operation::stopOperation();
1015 myTShapeDisplayer->SetVisibility( false );
1016 if ( myBadMeshDisplayer ) {
1017 myBadMeshDisplayer->SetVisibility( false );
1018 // delete it in order not to have problems at its destruction when the viewer
1019 // where it worked is dead due to e.g. study closing
1020 delete myBadMeshDisplayer;
1021 myBadMeshDisplayer = 0;
1025 //================================================================================
1027 * \brief publish selected subshape
1029 //================================================================================
1031 void SMESHGUI_ComputeOp::onPublishShape()
1033 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1034 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1037 list< int >::iterator row;
1038 getSelectedRows( table(), rows );
1039 for ( row = rows.begin(); row != rows.end(); ++row )
1041 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1042 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
1043 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
1045 if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
1047 QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1048 SALOMEDS::SObject_var so =
1049 geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
1050 // look for myMainShape in the table
1051 for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
1052 if ( table()->text(r, COL_SHAPEID) == "1" ) {
1053 if ( so->_is_nil() ) {
1054 table()->setText( r, COL_SHAPE, so->GetName() );
1055 table()->setText( r, COL_PUBLISHED, so->GetID() );
1060 if ( curSub == 1 ) continue;
1062 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
1063 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
1064 if ( !so->_is_nil() ) {
1065 table()->setText( *row, COL_SHAPE, so->GetName() );
1066 table()->setText( *row, COL_PUBLISHED, so->GetID() );
1070 getSMESHGUI()->getApp()->updateObjectBrowser();
1071 currentCellChanged(); // to update buttons
1074 //================================================================================
1076 * \brief show mesh elements preventing computation of a submesh of current row
1078 //================================================================================
1080 void SMESHGUI_ComputeOp::onShowBadMesh()
1082 myTShapeDisplayer->SetVisibility( false );
1084 if ( getSelectedRows( table(), rows ) == 1 ) {
1085 bool hasBadMesh = ( !table()->text(rows.front(), COL_BAD_MESH).isEmpty() );
1087 int curSub = table()->text(rows.front(), COL_SHAPEID).toInt();
1088 SMESHGUI* gui = getSMESHGUI();
1089 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1090 SVTK_ViewWindow* view = GetViewWindow( gui );
1091 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1092 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1093 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1094 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1095 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1096 // delete property !!!!!!!!!!
1097 vtkProperty* prop = vtkProperty::New();
1098 prop->SetLineWidth( aLineWidth * 3 );
1099 prop->SetPointSize( aPointSize * 3 );
1100 prop->SetColor( 250, 0, 250 );
1101 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1102 myBadMeshDisplayer->SetData( aMeshData._retn() );
1107 //================================================================================
1109 * \brief SLOT called when a selected cell in table() changed
1111 //================================================================================
1113 void SMESHGUI_ComputeOp::currentCellChanged()
1115 myTShapeDisplayer->SetVisibility( false );
1116 if ( myBadMeshDisplayer )
1117 myBadMeshDisplayer->SetVisibility( false );
1119 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1121 list< int >::iterator row;
1122 int nbSelected = getSelectedRows( table(), rows );
1123 for ( row = rows.begin(); row != rows.end(); ++row )
1125 bool hasData = ( !table()->text(*row, COL_SHAPE).isEmpty() );
1126 bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
1127 if ( hasData && !isPublished )
1128 publishEnable = true;
1130 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1131 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1133 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1140 if ( !table()->text(*row, COL_BAD_MESH).isEmpty() )
1143 myDlg->myPublishBtn->setEnabled( publishEnable );
1144 myDlg->myShowBtn ->setEnabled( showEnable );
1145 myDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1148 //================================================================================
1150 * \brief update preview
1152 //================================================================================
1154 void SMESHGUI_ComputeOp::onPreviewShape()
1156 if ( myTShapeDisplayer )
1158 SUIT_OverrideCursor aWaitCursor;
1160 list< int >::iterator row;
1161 getSelectedRows( table(), rows );
1163 bool showOnly = true;
1164 for ( row = rows.begin(); row != rows.end(); ++row )
1166 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1168 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1172 currentCellChanged(); // to update buttons
1176 //================================================================================
1180 //================================================================================
1182 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1184 delete myTShapeDisplayer;
1185 if ( myBadMeshDisplayer )
1186 delete myBadMeshDisplayer;
1189 //================================================================================
1191 * \brief Gets dialog of this operation
1192 * \retval LightApp_Dialog* - pointer to dialog of this operation
1194 //================================================================================
1196 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1201 //================================================================================
1203 * \brief perform it's intention action: compute mesh
1205 //================================================================================
1207 bool SMESHGUI_ComputeOp::onApply()
1212 //================================================================================
1214 * \brief Return a table
1216 //================================================================================
1218 QTable* SMESHGUI_ComputeOp::table()
1220 return myDlg->myTable;