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)
101 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
103 #define _SEPARATOR(father) \
105 /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
106 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
107 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
108 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
109 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
113 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
116 using namespace SMESH;
120 //=============================================================================
122 * \brief Allocate some memory at construction and release it at destruction.
123 * Is used to be able to continue working after mesh generation or visualization
124 * break due to lack of memory
126 //=============================================================================
131 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
132 void release() { delete [] myBuf; myBuf = 0; }
133 ~MemoryReserve() { release(); }
136 // =========================================================================================
138 * \brief Class showing shapes without publishing
140 // =========================================================================================
142 class TShapeDisplayer
145 // -----------------------------------------------------------------------
146 TShapeDisplayer(): myViewWindow(0)
148 myProperty = vtkProperty::New();
149 myProperty->SetRepresentationToWireframe();
150 myProperty->SetColor( 250, 0, 250 );
151 myProperty->SetAmbientColor( 250, 0, 250 );
152 myProperty->SetDiffuseColor( 250, 0, 250 );
153 //myProperty->SetSpecularColor( 250, 0, 250 );
154 myProperty->SetLineWidth( 5 );
156 // -----------------------------------------------------------------------
160 myProperty->Delete();
162 // -----------------------------------------------------------------------
165 if ( hasViewWindow() ) {
166 TActorIterator actorIt = actorIterator();
167 while ( actorIt.more() )
168 if (VTKViewer_Actor* anActor = actorIt.next()) {
169 myViewWindow->RemoveActor( anActor );
173 myIndexToShape.Clear();
175 myShownActors.clear();
178 // -----------------------------------------------------------------------
179 void SetVisibility (bool theVisibility)
181 TActorIterator actorIt = shownIterator();
182 while ( actorIt.more() )
183 if (VTKViewer_Actor* anActor = actorIt.next())
184 anActor->SetVisibility(theVisibility);
185 SMESH::RepaintCurrentView();
187 // -----------------------------------------------------------------------
188 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
191 if ( !aMainShape->_is_nil() )
192 mainEntry = aMainShape->GetStudyEntry();
193 return ( myMainEntry == mainEntry &&
194 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
196 // -----------------------------------------------------------------------
197 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
199 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
201 if ( !aMainShape->_is_nil() )
202 mainEntry = aMainShape->GetStudyEntry();
203 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
206 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
207 checkTriangulation( aShape );
208 TopExp::MapShapes(aShape, myIndexToShape);
209 myActors.resize( myIndexToShape.Extent(), 0 );
210 myShownActors.reserve( myIndexToShape.Extent() );
212 myMainEntry = mainEntry;
213 myViewWindow = aViewWindow;
215 if ( only ) { // hide shown actors
216 TActorIterator actorIt = shownIterator();
217 while ( actorIt.more() )
218 if (VTKViewer_Actor* anActor = actorIt.next())
219 anActor->SetVisibility(false);
220 myShownActors.clear();
222 // find actors to show
223 TopoDS_Shape aShape = myIndexToShape( subShapeID );
224 if ( !aShape.IsNull() ) {
225 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
226 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
227 //checkTriangulation( exp.Current() );
228 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
229 myShownActors.push_back( anActor );
231 if ( type == TopAbs_FACE ) {
232 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
233 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
234 if ( !BRep_Tool::Degenerated( edge ))
235 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
236 myShownActors.push_back( anActor );
240 myBuiltSubs.insert( subShapeID );
243 // -----------------------------------------------------------------------
247 typedef std::vector<GEOM_Actor*> TActorVec;
249 TActorVec myShownActors;
250 TopTools_IndexedMapOfShape myIndexToShape;
252 SVTK_ViewWindow* myViewWindow;
253 vtkProperty* myProperty;
254 std::set<int> myBuiltSubs;
256 // -----------------------------------------------------------------------
257 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
258 TActorIterator actorIterator() {
259 return TActorIterator( myActors.begin(), myActors.end() );
261 TActorIterator shownIterator() {
262 return TActorIterator( myShownActors.begin(), myShownActors.end() );
264 // -----------------------------------------------------------------------
265 GEOM_Actor* getActor(const TopoDS_Shape& shape)
267 int index = myIndexToShape.FindIndex( shape ) - 1;
268 if ( index < 0 || index >= myActors.size() )
270 GEOM_Actor* & actor = myActors[ index ];
272 actor = GEOM_Actor::New();
274 actor->SetShape(shape,0,0);
275 actor->SetProperty(myProperty);
276 actor->SetShadingProperty(myProperty);
277 actor->SetWireframeProperty(myProperty);
278 actor->SetPreviewProperty(myProperty);
279 actor->PickableOff();
280 // if ( shape.ShapeType() == TopAbs_EDGE )
281 // actor->SubShapeOn();
282 myViewWindow->AddActor( actor );
287 // -----------------------------------------------------------------------
288 void checkTriangulation(const TopoDS_Shape& shape)
290 TopLoc_Location aLoc;
291 Standard_Boolean alreadymesh = Standard_True;
292 TopExp_Explorer ex(shape, TopAbs_FACE);
294 for (; ex.More(); ex.Next()) {
295 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
296 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
297 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
300 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
301 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
302 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
303 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
305 if (alreadymesh) return;
306 // Compute default deflection
308 BRepBndLib::Add(shape, B);
309 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
310 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
311 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
312 BRepMesh_IncrementalMesh MESH(shape,deflection);
314 // -----------------------------------------------------------------------
315 bool hasViewWindow() const
317 if ( !myViewWindow ) return false;
319 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
320 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
326 // =========================================================================================
328 * \brief Return text describing an error
330 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
331 QString errorText(int errCode, const char* comment)
335 CASE2TEXT( COMPERR_OK );
336 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
337 CASE2TEXT( COMPERR_STD_EXCEPTION );
338 CASE2TEXT( COMPERR_OCC_EXCEPTION );
339 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
340 CASE2TEXT( COMPERR_EXCEPTION );
341 CASE2TEXT( COMPERR_MEMORY_PB );
342 CASE2TEXT( COMPERR_BAD_SHAPE );
343 case SMESH::COMPERR_ALGO_FAILED:
344 if ( strlen(comment) == 0 )
345 text = QObject::tr("COMPERR_ALGO_FAILED");
348 text = QString("#%1").arg( -errCode );
350 if ( text.length() > 0 ) text += ". ";
351 return text + comment;
353 // -----------------------------------------------------------------------
355 * \brief Return SO of a subshape
357 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
359 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
360 if ( subShapeID == 1 || !so )
362 _PTR(ChildIterator) it;
363 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
364 it = study->NewChildIterator(so);
367 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
368 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
369 if ( !geom->_is_nil() ) {
370 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
371 if ( list->length() == 1 && list[0] == subShapeID )
378 // -----------------------------------------------------------------------
380 * \brief Return subshape by ID
382 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
384 GEOM::GEOM_Object_var aSubShape;
385 if ( subShapeID == 1 )
386 aSubShape = aMainShape;
387 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
388 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
390 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
391 return aSubShape._retn();
393 // -----------------------------------------------------------------------
395 * \brief Return shape type name
397 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
398 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
401 if ( !aShape->_is_nil() ) {
402 switch ( aShape->GetShapeType() ) {
409 CASE2NAME( COMPSOLID );
410 CASE2NAME( COMPOUND );
416 // -----------------------------------------------------------------------
418 * \brief Return text describing a subshape
420 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
423 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
424 text = aSO->GetName();
426 text = QString("#%1").arg( subShapeID );
427 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
428 if ( typeName.length() )
429 text += QString(" (%1)").arg(typeName);
433 // -----------------------------------------------------------------------
435 * \brief Return a list of selected rows
437 int getSelectedRows(QTable* table, list< int > & rows)
440 int nbSel = table->numSelections();
441 for ( int i = 0; i < nbSel; ++i )
443 QTableSelection selected = table->selection(i);
444 if ( !selected.isActive() ) continue;
445 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
446 rows.push_back( row );
448 if (rows.empty() && table->currentRow() > -1 )
449 rows.push_back( table->currentRow() );
457 // =========================================================================================
459 * \brief Box showing mesh info
461 // =========================================================================================
463 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
464 :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
467 QLabel* lab1 = new QLabel(this);
468 QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
469 QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
470 QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
472 QFont italic = lab1->font(); italic.setItalic(true);
473 QFont bold = lab1->font(); bold.setBold(true);
475 lab1->setMinimumWidth(100); lab1->setFont( italic );
476 lab2->setMinimumWidth(100); lab2->setFont( italic );
477 lab3->setMinimumWidth(100); lab3->setFont( italic );
478 lab4->setMinimumWidth(100); lab4->setFont( italic );
483 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
484 myNbNode = new QLabel( this );
491 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
492 myNbEdge = new QLabel( this );
493 myNbLinEdge = new QLabel( this );
494 myNbQuadEdge = new QLabel( this );
499 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
500 myNbFace = new QLabel( this );
501 myNbLinFace = new QLabel( this );
502 myNbQuadFace = new QLabel( this );
504 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
505 myNbTrai = new QLabel( this );
506 myNbLinTrai = new QLabel( this );
507 myNbQuadTrai = new QLabel( this );
509 new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
510 myNbQuad = new QLabel( this );
511 myNbLinQuad = new QLabel( this );
512 myNbQuadQuad = new QLabel( this );
514 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
515 myNbPolyg = new QLabel( this );
516 new QLabel("",this );
517 new QLabel("", this );
522 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
523 myNbVolum = new QLabel( this );
524 myNbLinVolum = new QLabel( this );
525 myNbQuadVolum = new QLabel( this );
527 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
528 myNbTetra = new QLabel( this );
529 myNbLinTetra = new QLabel( this );
530 myNbQuadTetra = new QLabel( this );
532 new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
533 myNbHexa = new QLabel( this );
534 myNbLinHexa = new QLabel( this );
535 myNbQuadHexa = new QLabel( this );
537 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
538 myNbPyra = new QLabel( this );
539 myNbLinPyra = new QLabel( this );
540 myNbQuadPyra = new QLabel( this );
542 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
543 myNbPrism = new QLabel( this );
544 myNbLinPrism = new QLabel( this );
545 myNbQuadPrism = new QLabel( this );
547 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
548 myNbPolyh = new QLabel( this );
549 new QLabel("", this );
550 new QLabel("", this );
555 new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
556 myNbNode = new QLabel( this );
561 new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
562 myNbEdge = new QLabel( this );
563 myNbLinEdge = new QLabel( this );
564 myNbQuadEdge = new QLabel( this );
567 new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
568 myNbFace = new QLabel( this );
569 myNbLinFace = new QLabel( this );
570 myNbQuadFace = new QLabel( this );
573 new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
574 myNbVolum = new QLabel( this );
575 myNbLinVolum = new QLabel( this );
576 myNbQuadVolum = new QLabel( this );
580 // =========================================================================================
582 * \brief Set mesh info
584 // =========================================================================================
586 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
588 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
592 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
595 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
596 myNbEdge ->setText( QString("%1").arg( nbTot ));
597 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
598 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
601 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
602 myNbFace ->setText( QString("%1").arg( nbTot ));
603 myNbLinFace ->setText( QString("%1").arg( nbLin ));
604 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
607 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
608 myNbVolum ->setText( QString("%1").arg( nbTot ));
609 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
610 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
615 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
616 myNbTrai ->setText( QString("%1").arg( nbTot ));
617 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
618 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
620 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
621 myNbQuad ->setText( QString("%1").arg( nbTot ));
622 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
623 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
625 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
628 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
629 myNbTetra ->setText( QString("%1").arg( nbTot ));
630 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
631 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
633 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
634 myNbHexa ->setText( QString("%1").arg( nbTot ));
635 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
636 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
638 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
639 myNbPyra ->setText( QString("%1").arg( nbTot ));
640 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
641 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
643 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
644 myNbPrism ->setText( QString("%1").arg( nbTot ));
645 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
646 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
648 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
652 // =========================================================================================
654 * \brief Dialog to compute a mesh and show computation errors
656 //=======================================================================
658 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, Close/* | Help*/ )
660 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
662 QFrame* aMainFrame = createMainFrame (mainFrame());
664 aDlgLay->addWidget(aMainFrame);
666 aDlgLay->setStretchFactor(aMainFrame, 1);
669 //=======================================================================
670 // function : createMainFrame()
671 // purpose : Create frame containing dialog's fields
672 //=======================================================================
674 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
676 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
678 QFrame* aFrame = new QFrame(theParent);
680 SUIT_ResourceMgr* rm = resourceMgr();
681 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
685 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
686 aPixGrp->setExclusive(TRUE);
687 QRadioButton* aRBut = new QRadioButton(aPixGrp);
688 aRBut->setPixmap(iconCompute);
689 aRBut->setChecked(TRUE);
693 QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
694 myMeshName = new QLabel(nameBox);
698 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
699 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
701 // Computation errors
703 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "myCompErrorGroup");
704 myTable = new QTable( 1, NB_COLUMNS, myCompErrorGroup, "myTable");
705 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup, "myShowBtn");
706 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup, "myPublishBtn");
707 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup, "myBadMeshBtn");
709 myTable->setReadOnly( TRUE );
710 myTable->hideColumn( COL_PUBLISHED );
711 myTable->hideColumn( COL_SHAPEID );
712 myTable->hideColumn( COL_BAD_MESH );
713 myTable->setColumnStretchable( COL_ERROR, 1 );
714 for ( int col = 0; col < NB_COLUMNS; ++col ) {
717 CASE2HEADER( COL_ALGO );
718 CASE2HEADER( COL_SHAPE );
719 CASE2HEADER( COL_ERROR );
720 CASE2HEADER( COL_SHAPEID );
721 CASE2HEADER( COL_PUBLISHED);
723 myTable->horizontalHeader()->setLabel( col, header );
726 myCompErrorGroup->setColumnLayout(0, Qt::Vertical);
727 myCompErrorGroup->layout()->setSpacing(0);
728 myCompErrorGroup->layout()->setMargin(0);
729 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup->layout());
730 grpLayout->setAlignment(Qt::AlignTop);
731 grpLayout->setSpacing(SPACING);
732 grpLayout->setMargin(MARGIN);
733 grpLayout->addMultiCellWidget( myTable, 0, 3, 0, 0 );
734 grpLayout->addWidget ( myShowBtn, 0, 1 );
735 grpLayout->addWidget ( myPublishBtn, 1, 1 );
736 grpLayout->addWidget ( myBadMeshBtn, 2, 1 );
737 grpLayout->setRowStretch( 3, 1 );
739 // Hypothesis definition errors
741 myHypErrorGroup = new QGroupBox(1,Qt::Vertical, tr("SMESH_WRN_MISSING_PARAMETERS"),aFrame);
742 myHypErrorLabel = new QLabel(myHypErrorGroup);
746 myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
747 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
748 QFont bold = memLackLabel->font(); bold.setBold(true);
749 memLackLabel->setFont( bold );
750 memLackLabel->setMinimumWidth(300);
752 // add all widgets to aFrame
753 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
754 aLay->addWidget( aPixGrp );
755 aLay->addWidget( nameBox );
756 aLay->addWidget( myBriefInfo );
757 aLay->addWidget( myFullInfo );
758 aLay->addWidget( myHypErrorGroup );
759 aLay->addWidget( myCompErrorGroup );
760 aLay->addWidget( myMemoryLackGroup );
761 aLay->setStretchFactor( myCompErrorGroup, 1 );
763 ((QPushButton*) button( OK ))->setDefault( true );
768 //================================================================================
772 //================================================================================
774 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
776 myDlg = new SMESHGUI_ComputeDlg;
777 myTShapeDisplayer = new TShapeDisplayer();
778 myBadMeshDisplayer = 0;
780 //myHelpFileName = "/files/about_meshes.htm"; // V3
781 myHelpFileName = "about_meshes_page.html"; // V4
783 // connect signals and slots
784 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
785 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
786 connect(myDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
787 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
788 connect(table(),SIGNAL(currentChanged(int,int)), SLOT(currentCellChanged()));
791 //=======================================================================
792 // function : startOperation()
793 // purpose : Init dialog fields, connect signals and slots, show dialog
794 //=======================================================================
796 void SMESHGUI_ComputeOp::startOperation()
798 SMESHGUI_Operation::startOperation();
802 myMesh = SMESH::SMESH_Mesh::_nil();
803 myMainShape = GEOM::GEOM_Object::_nil();
805 LightApp_SelectionMgr *Sel = selectionMgr();
806 SALOME_ListIO selected; Sel->selectedObjects( selected );
808 int nbSel = selected.Extent();
810 SUIT_MessageBox::warn1(desktop(),
811 tr("SMESH_WRN_WARNING"),
812 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
818 Handle(SALOME_InteractiveObject) IObject = selected.First();
819 myMesh = SMESH::GetMeshByIO(IObject);
820 if (myMesh->_is_nil()) {
821 SUIT_MessageBox::warn1(desktop(),
822 tr("SMESH_WRN_WARNING"),
823 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
831 MemoryReserve aMemoryReserve;
833 SMESH::compute_error_array_var aCompErrors;
836 bool computeFailed = true, memoryLack = false;
838 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
839 myMainShape = myMesh->GetShapeToMesh();
840 bool hasShape = myMesh->HasShapeToMesh();
841 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
842 if ( shapeOK && aMeshSObj )
844 myDlg->myMeshName->setText( aMeshSObj->GetName() );
845 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
846 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
847 if ( errors->length() > 0 ) {
848 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
850 SUIT_OverrideCursor aWaitCursor;
852 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
855 if (gen->Compute(myMesh, myMainShape))
856 computeFailed = false;
858 catch(const SALOME::SALOME_Exception & S_ex){
862 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
865 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
866 // check if there are memory problems
867 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
868 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
870 catch(const SALOME::SALOME_Exception & S_ex){
874 // NPAL16631: if ( !memoryLack )
876 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
877 update( UF_ObjBrowser | UF_Model );
880 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
881 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
884 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
887 SMESH::Update(IObject, true);
891 MESSAGE ( "Exception thrown during mesh visualization" );
893 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
894 SMESH::OnVisuException();
901 Sel->setSelectedObjects( selected );
906 aMemoryReserve.release();
908 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
909 myDlg->myMemoryLackGroup->hide();
913 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
914 bool noHypoError = ( aHypErrors.isEmpty() );
918 myDlg->myMemoryLackGroup->show();
919 myDlg->myFullInfo->hide();
920 myDlg->myBriefInfo->hide();
921 myDlg->myHypErrorGroup->hide();
922 myDlg->myCompErrorGroup->hide();
924 else if ( noCompError && noHypoError )
926 myDlg->myFullInfo->SetInfoByMesh( myMesh );
927 myDlg->myFullInfo->show();
928 myDlg->myBriefInfo->hide();
929 myDlg->myHypErrorGroup->hide();
930 myDlg->myCompErrorGroup->hide();
934 QTable* tbl = myDlg->myTable;
935 myDlg->myBriefInfo->SetInfoByMesh( myMesh );
936 myDlg->myBriefInfo->show();
937 myDlg->myFullInfo->hide();
940 myDlg->myHypErrorGroup->hide();
943 myDlg->myHypErrorGroup->show();
944 myDlg->myHypErrorLabel->setText( aHypErrors );
948 myDlg->myCompErrorGroup->hide();
951 myDlg->myCompErrorGroup->show();
954 myDlg->myPublishBtn->hide();
955 myDlg->myShowBtn->hide();
958 myDlg->myPublishBtn->show();
959 myDlg->myShowBtn->show();
962 // fill table of errors
963 tbl->setNumRows( aCompErrors->length() );
964 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
965 else tbl->showColumn( COL_SHAPE );
966 tbl->setColumnWidth( COL_ERROR, 200 );
968 bool hasBadMesh = false;
969 for ( int row = 0; row < aCompErrors->length(); ++row )
971 SMESH::ComputeError & err = aCompErrors[ row ];
972 tbl->setText( row, COL_ALGO, err.algoName.in() );
973 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
974 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
976 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
977 tbl->setText( row, COL_SHAPE, text );
979 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
980 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
982 text = err.hasBadMesh ? "hasBadMesh" : "";
983 tbl->setText( row, COL_BAD_MESH, text );
984 if ( err.hasBadMesh ) hasBadMesh = true;
986 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
987 tbl->adjustRow( row );
989 tbl->adjustColumn( COL_ALGO );
990 tbl->adjustColumn( COL_SHAPE );
993 myDlg->myBadMeshBtn->show();
995 myDlg->myBadMeshBtn->hide();
997 tbl->setCurrentCell(0,0);
998 currentCellChanged(); // to update buttons
1004 //================================================================================
1006 * \brief Stops operation
1008 //================================================================================
1010 void SMESHGUI_ComputeOp::stopOperation()
1012 SMESHGUI_Operation::stopOperation();
1013 myTShapeDisplayer->SetVisibility( false );
1014 if ( myBadMeshDisplayer ) {
1015 myBadMeshDisplayer->SetVisibility( false );
1016 // delete it in order not to have problems at its destruction when the viewer
1017 // where it worked is dead due to e.g. study closing
1018 delete myBadMeshDisplayer;
1019 myBadMeshDisplayer = 0;
1023 //================================================================================
1025 * \brief publish selected subshape
1027 //================================================================================
1029 void SMESHGUI_ComputeOp::onPublishShape()
1031 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1032 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1035 list< int >::iterator row;
1036 getSelectedRows( table(), rows );
1037 for ( row = rows.begin(); row != rows.end(); ++row )
1039 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1040 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
1041 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
1043 if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
1045 QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1046 SALOMEDS::SObject_var so =
1047 geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
1048 // look for myMainShape in the table
1049 for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
1050 if ( table()->text(r, COL_SHAPEID) == "1" ) {
1051 if ( so->_is_nil() ) {
1052 table()->setText( r, COL_SHAPE, so->GetName() );
1053 table()->setText( r, COL_PUBLISHED, so->GetID() );
1058 if ( curSub == 1 ) continue;
1060 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
1061 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
1062 if ( !so->_is_nil() ) {
1063 table()->setText( *row, COL_SHAPE, so->GetName() );
1064 table()->setText( *row, COL_PUBLISHED, so->GetID() );
1068 getSMESHGUI()->getApp()->updateObjectBrowser();
1069 currentCellChanged(); // to update buttons
1072 //================================================================================
1074 * \brief show mesh elements preventing computation of a submesh of current row
1076 //================================================================================
1078 void SMESHGUI_ComputeOp::onShowBadMesh()
1080 myTShapeDisplayer->SetVisibility( false );
1082 if ( getSelectedRows( table(), rows ) == 1 ) {
1083 bool hasBadMesh = ( !table()->text(rows.front(), COL_BAD_MESH).isEmpty() );
1085 int curSub = table()->text(rows.front(), COL_SHAPEID).toInt();
1086 SMESHGUI* gui = getSMESHGUI();
1087 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1088 SVTK_ViewWindow* view = GetViewWindow( gui );
1089 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1090 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1091 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1092 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1093 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1094 // delete property !!!!!!!!!!
1095 vtkProperty* prop = vtkProperty::New();
1096 prop->SetLineWidth( aLineWidth * 3 );
1097 prop->SetPointSize( aPointSize * 3 );
1098 prop->SetColor( 250, 0, 250 );
1099 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1100 myBadMeshDisplayer->SetData( aMeshData._retn() );
1105 //================================================================================
1107 * \brief SLOT called when a selected cell in table() changed
1109 //================================================================================
1111 void SMESHGUI_ComputeOp::currentCellChanged()
1113 myTShapeDisplayer->SetVisibility( false );
1114 if ( myBadMeshDisplayer )
1115 myBadMeshDisplayer->SetVisibility( false );
1117 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1119 list< int >::iterator row;
1120 int nbSelected = getSelectedRows( table(), rows );
1121 for ( row = rows.begin(); row != rows.end(); ++row )
1123 bool hasData = ( !table()->text(*row, COL_SHAPE).isEmpty() );
1124 bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
1125 if ( hasData && !isPublished )
1126 publishEnable = true;
1128 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1129 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1131 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1138 if ( !table()->text(*row, COL_BAD_MESH).isEmpty() )
1141 myDlg->myPublishBtn->setEnabled( publishEnable );
1142 myDlg->myShowBtn ->setEnabled( showEnable );
1143 myDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1146 //================================================================================
1148 * \brief update preview
1150 //================================================================================
1152 void SMESHGUI_ComputeOp::onPreviewShape()
1154 if ( myTShapeDisplayer )
1156 SUIT_OverrideCursor aWaitCursor;
1158 list< int >::iterator row;
1159 getSelectedRows( table(), rows );
1161 bool showOnly = true;
1162 for ( row = rows.begin(); row != rows.end(); ++row )
1164 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1166 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1170 currentCellChanged(); // to update buttons
1174 //================================================================================
1178 //================================================================================
1180 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1182 delete myTShapeDisplayer;
1183 if ( myBadMeshDisplayer )
1184 delete myBadMeshDisplayer;
1187 //================================================================================
1189 * \brief Gets dialog of this operation
1190 * \retval LightApp_Dialog* - pointer to dialog of this operation
1192 //================================================================================
1194 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1199 //================================================================================
1201 * \brief perform it's intention action: compute mesh
1203 //================================================================================
1205 bool SMESHGUI_ComputeOp::onApply()
1210 //================================================================================
1212 * \brief Return a table
1214 //================================================================================
1216 QTable* SMESHGUI_ComputeOp::table()
1218 return myDlg->myTable;