1 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
2 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License.
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
20 // File : SMESHGUI_ComputeDlg.cxx
21 // Author : Edward AGAPOV, Open CASCADE S.A.S.
25 #include "SMESHGUI_ComputeDlg.h"
28 #include "SMESHGUI_GEOMGenUtils.h"
29 #include "SMESHGUI_MeshUtils.h"
30 #include "SMESHGUI_VTKUtils.h"
31 #include "SMESHGUI_HypothesesUtils.h"
33 #include <SMDS_SetIterator.hxx>
34 #include <SMDS_Mesh.hxx>
36 // SALOME GEOM includes
38 #include <GEOM_Actor.h>
40 // SALOME GUI includes
41 #include <LightApp_SelectionMgr.h>
42 #include <LightApp_UpdateFlags.h>
43 #include <SALOME_ListIO.hxx>
44 #include <SVTK_ViewWindow.h>
45 #include <SVTK_ViewModel.h>
46 #include <SalomeApp_Application.h>
47 #include <SUIT_ResourceMgr.h>
48 #include <SUIT_OverrideCursor.h>
49 #include <SUIT_MessageBox.h>
50 #include <SUIT_Desktop.h>
52 // SALOME KERNEL includes
53 #include <SALOMEDSClient_SObject.hxx>
56 #include <BRep_Tool.hxx>
58 #include <TopExp_Explorer.hxx>
59 #include <TopTools_IndexedMapOfShape.hxx>
62 #include <TopLoc_Location.hxx>
63 #include <Poly_Triangulation.hxx>
64 #include <Bnd_Box.hxx>
65 #include <BRepBndLib.hxx>
66 #include <BRepMesh_IncrementalMesh.hxx>
68 #include <Standard_ErrorHandler.hxx>
72 #include <QPushButton>
74 #include <QRadioButton>
75 #include <QTableWidget>
76 #include <QHeaderView>
77 #include <QGridLayout>
78 #include <QHBoxLayout>
79 #include <QVBoxLayout>
80 #include <QButtonGroup>
83 #include <vtkProperty.h>
86 #include <SALOMEconfig.h>
87 #include CORBA_SERVER_HEADER(SMESH_Gen)
96 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
98 static void addSeparator( QWidget* parent )
100 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
101 int row = l->rowCount();
102 int cols = l->columnCount();
103 for ( int i = 0; i < cols; i++ ) {
104 QFrame* hline = new QFrame( parent );
105 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
106 l->addWidget( hline, row, i );
110 enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, NB_COLUMNS };
112 //using namespace SMESH;
116 //=============================================================================
118 * \brief Allocate some memory at construction and release it at destruction.
119 * Is used to be able to continue working after mesh generation or visualization
120 * break due to lack of memory
122 //=============================================================================
127 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
128 ~MemoryReserve() { delete [] myBuf; }
131 // =========================================================================================
133 * \brief Class showing shapes without publishing
135 // =========================================================================================
137 class TShapeDisplayer
140 // -----------------------------------------------------------------------
141 TShapeDisplayer(): myViewWindow(0)
143 myProperty = vtkProperty::New();
144 myProperty->SetRepresentationToWireframe();
145 myProperty->SetColor( 250, 0, 250 );
146 myProperty->SetAmbientColor( 250, 0, 250 );
147 myProperty->SetDiffuseColor( 250, 0, 250 );
148 //myProperty->SetSpecularColor( 250, 0, 250 );
149 myProperty->SetLineWidth( 5 );
151 // -----------------------------------------------------------------------
155 myProperty->Delete();
157 // -----------------------------------------------------------------------
160 if ( hasViewWindow() ) {
161 TActorIterator actorIt = actorIterator();
162 while ( actorIt.more() )
163 if (VTKViewer_Actor* anActor = actorIt.next()) {
164 myViewWindow->RemoveActor( anActor );
168 myIndexToShape.Clear();
170 myShownActors.clear();
173 // -----------------------------------------------------------------------
174 void SetVisibility (bool theVisibility)
176 TActorIterator actorIt = shownIterator();
177 while ( actorIt.more() )
178 if (VTKViewer_Actor* anActor = actorIt.next())
179 anActor->SetVisibility(theVisibility);
180 SMESH::RepaintCurrentView();
182 // -----------------------------------------------------------------------
183 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
185 std::string mainEntry;
186 if ( !aMainShape->_is_nil() )
187 mainEntry = aMainShape->GetStudyEntry();
188 return ( myMainEntry == mainEntry &&
189 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
191 // -----------------------------------------------------------------------
192 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
194 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
195 std::string mainEntry;
196 if ( !aMainShape->_is_nil() )
197 mainEntry = aMainShape->GetStudyEntry();
198 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
201 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
202 checkTriangulation( aShape );
203 TopExp::MapShapes(aShape, myIndexToShape);
204 myActors.resize( myIndexToShape.Extent(), 0 );
205 myShownActors.reserve( myIndexToShape.Extent() );
207 myMainEntry = mainEntry;
208 myViewWindow = aViewWindow;
210 if ( only ) { // hide shown actors
211 TActorIterator actorIt = shownIterator();
212 while ( actorIt.more() )
213 if (VTKViewer_Actor* anActor = actorIt.next())
214 anActor->SetVisibility(false);
215 myShownActors.clear();
217 // find actors to show
218 TopoDS_Shape aShape = myIndexToShape( subShapeID );
219 if ( !aShape.IsNull() ) {
220 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
221 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
222 //checkTriangulation( exp.Current() );
223 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
224 myShownActors.push_back( anActor );
226 if ( type == TopAbs_FACE ) {
227 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
228 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
229 if ( !BRep_Tool::Degenerated( edge ))
230 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
231 myShownActors.push_back( anActor );
235 myBuiltSubs.insert( subShapeID );
238 // -----------------------------------------------------------------------
242 typedef std::vector<GEOM_Actor*> TActorVec;
244 TActorVec myShownActors;
245 TopTools_IndexedMapOfShape myIndexToShape;
246 std::string myMainEntry;
247 SVTK_ViewWindow* myViewWindow;
248 vtkProperty* myProperty;
249 std::set<int> myBuiltSubs;
251 // -----------------------------------------------------------------------
252 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
253 TActorIterator actorIterator() {
254 return TActorIterator( myActors.begin(), myActors.end() );
256 TActorIterator shownIterator() {
257 return TActorIterator( myShownActors.begin(), myShownActors.end() );
259 // -----------------------------------------------------------------------
260 GEOM_Actor* getActor(const TopoDS_Shape& shape)
262 int index = myIndexToShape.FindIndex( shape ) - 1;
263 if ( index < 0 || index >= myActors.size() )
265 GEOM_Actor* & actor = myActors[ index ];
267 actor = GEOM_Actor::New();
269 actor->setInputShape(shape,0,0);
270 //actor->SetProperty(myProperty);
271 actor->SetShadingProperty(myProperty);
272 actor->SetWireframeProperty(myProperty);
273 actor->SetPreviewProperty(myProperty);
274 actor->PickableOff();
275 // if ( shape.ShapeType() == TopAbs_EDGE )
276 // actor->SubShapeOn();
277 myViewWindow->AddActor( actor );
282 // -----------------------------------------------------------------------
283 void checkTriangulation(const TopoDS_Shape& shape)
285 TopLoc_Location aLoc;
286 Standard_Boolean alreadymesh = Standard_True;
287 TopExp_Explorer ex(shape, TopAbs_FACE);
289 for ( ; ex.More(); ex.Next()) {
290 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
291 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
292 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
295 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
296 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
297 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
298 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
300 if (alreadymesh) return;
301 // Compute default deflection
303 BRepBndLib::Add(shape, B);
304 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
305 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
306 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
307 BRepMesh_IncrementalMesh MESH(shape,deflection);
309 // -----------------------------------------------------------------------
310 bool hasViewWindow() const
312 if ( !myViewWindow ) return false;
314 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
315 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
321 // =========================================================================================
323 * \brief Return text describing an error
325 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
326 QString errorText(int errCode, const char* comment)
330 CASE2TEXT( COMPERR_OK );
331 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
332 CASE2TEXT( COMPERR_STD_EXCEPTION );
333 CASE2TEXT( COMPERR_OCC_EXCEPTION );
334 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
335 CASE2TEXT( COMPERR_EXCEPTION );
336 CASE2TEXT( COMPERR_MEMORY_PB );
337 CASE2TEXT( COMPERR_BAD_SHAPE );
338 case SMESH::COMPERR_ALGO_FAILED:
339 if ( strlen(comment) == 0 )
340 text = QObject::tr("COMPERR_ALGO_FAILED");
343 text = QString("#%1").arg( -errCode );
345 if ( text.length() > 0 ) text += ". ";
346 return text + comment;
348 // -----------------------------------------------------------------------
350 * \brief Return SO of a subshape
352 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
354 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
355 if ( subShapeID == 1 || !so )
357 _PTR(ChildIterator) it;
358 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
359 it = study->NewChildIterator(so);
362 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
363 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
364 if ( !geom->_is_nil() ) {
365 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
366 if ( list->length() == 1 && list[0] == subShapeID )
373 // -----------------------------------------------------------------------
375 * \brief Return subshape by ID
377 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
379 GEOM::GEOM_Object_var aSubShape;
380 if ( subShapeID == 1 )
381 aSubShape = aMainShape;
382 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
383 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
385 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
386 return aSubShape._retn();
388 // -----------------------------------------------------------------------
390 * \brief Return shape type name
392 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
393 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
396 if ( !aShape->_is_nil() ) {
397 switch ( aShape->GetShapeType() ) {
404 CASE2NAME( COMPSOLID );
405 CASE2NAME( COMPOUND );
411 // -----------------------------------------------------------------------
413 * \brief Return text describing a subshape
415 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
418 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
419 text = aSO->GetName().c_str();
421 text = QString("#%1").arg( subShapeID );
422 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
423 if ( typeName.length() )
424 text += QString(" (%1)").arg(typeName);
428 // -----------------------------------------------------------------------
430 * \brief Return a list of selected rows
432 bool getSelectedRows(QTableWidget* table, QList<int>& rows)
435 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
436 QTableWidgetSelectionRange range;
437 foreach( range, selRanges )
439 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
442 if ( rows.isEmpty() && table->currentRow() > -1 )
443 rows.append( table->currentRow() );
445 return !rows.isEmpty();
451 // =========================================================================================
453 * \brief Box showing mesh info
455 // =========================================================================================
457 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
458 : QGroupBox( tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
460 QGridLayout* l = new QGridLayout(this);
461 l->setMargin( MARGIN );
462 l->setSpacing( SPACING );
464 QFont italic = font(); italic.setItalic(true);
465 QFont bold = font(); bold.setBold(true);
471 lab = new QLabel( this );
472 lab->setMinimumWidth(100); lab->setFont( italic );
473 l->addWidget( lab, row, 0 );
475 lab = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
476 lab->setMinimumWidth(100); lab->setFont( italic );
477 l->addWidget( lab, row, 1 );
479 lab = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
480 lab->setMinimumWidth(100); lab->setFont( italic );
481 l->addWidget( lab, row, 2 );
483 lab = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
484 lab->setMinimumWidth(100); lab->setFont( italic );
485 l->addWidget( lab, row, 3 );
490 row = l->rowCount(); // retrieve current row count
492 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
493 lab->setFont( bold );
494 l->addWidget( lab, row, 0 );
496 myNbNode = new QLabel( this );
497 l->addWidget( myNbNode, row, 1 );
499 addSeparator(this); // add separator
502 row = l->rowCount(); // retrieve current row count
504 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
505 lab->setFont( bold );
506 l->addWidget( lab, row, 0 );
508 myNbEdge = new QLabel( this );
509 l->addWidget( myNbEdge, row, 1 );
511 myNbLinEdge = new QLabel( this );
512 l->addWidget( myNbLinEdge, row, 2 );
514 myNbQuadEdge = new QLabel( this );
515 l->addWidget( myNbQuadEdge, row, 3 );
517 addSeparator(this); // add separator
520 row = l->rowCount(); // retrieve current row count
522 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
523 lab->setFont( bold );
524 l->addWidget( lab, row, 0 );
526 myNbFace = new QLabel( this );
527 l->addWidget( myNbFace, row, 1 );
529 myNbLinFace = new QLabel( this );
530 l->addWidget( myNbLinFace, row, 2 );
532 myNbQuadFace = new QLabel( this );
533 l->addWidget( myNbQuadFace, row, 3 );
535 row++; // increment row count
537 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
538 l->addWidget( lab, row, 0 );
540 myNbTrai = new QLabel( this );
541 l->addWidget( myNbTrai, row, 1 );
543 myNbLinTrai = new QLabel( this );
544 l->addWidget( myNbLinTrai, row, 2 );
546 myNbQuadTrai = new QLabel( this );
547 l->addWidget( myNbQuadTrai, row, 3 );
549 row++; // increment row count
551 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
552 l->addWidget( lab, row, 0 );
554 myNbQuad = new QLabel( this );
555 l->addWidget( myNbQuad, row, 1 );
557 myNbLinQuad = new QLabel( this );
558 l->addWidget( myNbLinQuad, row, 2 );
560 myNbQuadQuad = new QLabel( this );
561 l->addWidget( myNbQuadQuad, row, 3 );
563 row++; // increment row count
565 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
566 l->addWidget( lab, row, 0 );
567 myNbPolyg = new QLabel( this );
568 l->addWidget( myNbPolyg, row, 1 );
570 addSeparator(this); // add separator
573 row = l->rowCount(); // retrieve current row count
575 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
576 lab->setFont( bold );
577 l->addWidget( lab, row, 0 );
579 myNbVolum = new QLabel( this );
580 l->addWidget( myNbVolum, row, 1 );
582 myNbLinVolum = new QLabel( this );
583 l->addWidget( myNbLinVolum, row, 2 );
585 myNbQuadVolum = new QLabel( this );
586 l->addWidget( myNbQuadVolum, row, 3 );
588 row++; // increment row count
590 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
591 l->addWidget( lab, row, 0 );
593 myNbTetra = new QLabel( this );
594 l->addWidget( myNbTetra, row, 1 );
596 myNbLinTetra = new QLabel( this );
597 l->addWidget( myNbLinTetra, row, 2 );
599 myNbQuadTetra = new QLabel( this );
600 l->addWidget( myNbQuadTetra, row, 3 );
602 row++; // increment row count
604 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
605 l->addWidget( lab, row, 0 );
607 myNbHexa = new QLabel( this );
608 l->addWidget( myNbHexa, row, 1 );
610 myNbLinHexa = new QLabel( this );
611 l->addWidget( myNbLinHexa, row, 2 );
613 myNbQuadHexa = new QLabel( this );
614 l->addWidget( myNbQuadHexa, row, 3 );
616 row++; // increment row count
618 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
619 l->addWidget( lab, row, 0 );
621 myNbPyra = new QLabel( this );
622 l->addWidget( myNbPyra, row, 1 );
624 myNbLinPyra = new QLabel( this );
625 l->addWidget( myNbLinPyra, row, 2 );
627 myNbQuadPyra = new QLabel( this );
628 l->addWidget( myNbQuadPyra, row, 3 );
630 row++; // increment row count
632 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
633 l->addWidget( lab, row, 0 );
635 myNbPrism = new QLabel( this );
636 l->addWidget( myNbPrism, row, 1 );
638 myNbLinPrism = new QLabel( this );
639 l->addWidget( myNbLinPrism, row, 2 );
641 myNbQuadPrism = new QLabel( this );
642 l->addWidget( myNbQuadPrism, row, 3 );
644 row++; // increment row count
646 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
647 l->addWidget( lab, row, 0 );
649 myNbPolyh = new QLabel( this );
650 l->addWidget( myNbPolyh, row, 1 );
655 row = l->rowCount(); // retrieve current row count
657 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
658 l->addWidget( lab, row, 0 );
660 myNbNode = new QLabel( this );
661 l->addWidget( myNbNode, row, 1 );
664 row = l->rowCount(); // retrieve current row count
666 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
667 l->addWidget( lab, row, 0 );
669 myNbEdge = new QLabel( this );
670 l->addWidget( myNbEdge, row, 1 );
672 myNbLinEdge = new QLabel( this );
673 l->addWidget( myNbLinEdge, row, 2 );
675 myNbQuadEdge = new QLabel( this );
676 l->addWidget( myNbQuadEdge, row, 3 );
679 row = l->rowCount(); // retrieve current row count
681 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
682 l->addWidget( lab, row, 0 );
684 myNbFace = new QLabel( this );
685 l->addWidget( myNbFace, row, 1 );
687 myNbLinFace = new QLabel( this );
688 l->addWidget( myNbLinFace, row, 2 );
690 myNbQuadFace = new QLabel( this );
691 l->addWidget( myNbQuadFace, row, 3 );
694 row = l->rowCount(); // retrieve current row count
696 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
697 l->addWidget( lab, row, 0 );
699 myNbVolum = new QLabel( this );
700 l->addWidget( myNbVolum, row, 1 );
702 myNbLinVolum = new QLabel( this );
703 l->addWidget( myNbLinVolum, row, 2 );
705 myNbQuadVolum = new QLabel( this );
706 l->addWidget( myNbQuadVolum, row, 3 );
710 // =========================================================================================
712 * \brief Set mesh info
714 // =========================================================================================
716 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
718 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
722 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
725 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
726 myNbEdge ->setText( QString("%1").arg( nbTot ));
727 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
728 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
731 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
732 myNbFace ->setText( QString("%1").arg( nbTot ));
733 myNbLinFace ->setText( QString("%1").arg( nbLin ));
734 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
737 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
738 myNbVolum ->setText( QString("%1").arg( nbTot ));
739 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
740 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
745 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
746 myNbTrai ->setText( QString("%1").arg( nbTot ));
747 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
748 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
750 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
751 myNbQuad ->setText( QString("%1").arg( nbTot ));
752 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
753 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
755 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
758 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
759 myNbTetra ->setText( QString("%1").arg( nbTot ));
760 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
761 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
763 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
764 myNbHexa ->setText( QString("%1").arg( nbTot ));
765 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
766 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
768 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
769 myNbPyra ->setText( QString("%1").arg( nbTot ));
770 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
771 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
773 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
774 myNbPrism ->setText( QString("%1").arg( nbTot ));
775 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
776 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
778 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
782 // =========================================================================================
784 * \brief Dialog to compute a mesh and show computation errors
786 //=======================================================================
788 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, OK/* | Help*/ )
790 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
791 aDlgLay->setMargin( 0 );
792 aDlgLay->setSpacing( SPACING );
794 QFrame* aMainFrame = createMainFrame (mainFrame());
796 aDlgLay->addWidget(aMainFrame);
798 aDlgLay->setStretchFactor(aMainFrame, 1);
801 //=======================================================================
802 // function : createMainFrame()
803 // purpose : Create frame containing dialog's fields
804 //=======================================================================
806 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
808 QFrame* aFrame = new QFrame(theParent);
810 SUIT_ResourceMgr* rm = resourceMgr();
811 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
815 QGroupBox* aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
816 QButtonGroup* aBtnGrp = new QButtonGroup(this);
817 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
818 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
820 QRadioButton* aRBut = new QRadioButton(aPixGrp);
821 aRBut->setIcon(iconCompute);
822 aRBut->setChecked(true);
823 aPixGrpLayout->addWidget(aRBut);
824 aBtnGrp->addButton(aRBut, 0);
828 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
829 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
830 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
831 myMeshName = new QLabel(nameBox);
832 nameBoxLayout->addWidget(myMeshName);
836 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
837 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
839 // Computation errors
841 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
842 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
843 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
844 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
846 //myTable->setReadOnly( true ); // VSR: check
847 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
848 myTable->hideColumn( COL_PUBLISHED );
849 myTable->hideColumn( COL_SHAPEID );
850 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
853 headers << tr( "COL_ALGO_HEADER" );
854 headers << tr( "COL_SHAPE_HEADER" );
855 headers << tr( "COL_ERROR_HEADER" );
856 headers << tr( "COL_SHAPEID_HEADER" );
857 headers << tr( "COL_PUBLISHED_HEADER" );
859 myTable->setHorizontalHeaderLabels( headers );
862 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
863 grpLayout->setSpacing(SPACING);
864 grpLayout->setMargin(MARGIN);
865 grpLayout->addWidget( myTable, 0, 0, 3, 1 );
866 grpLayout->addWidget( myShowBtn, 0, 1 );
867 grpLayout->addWidget( myPublishBtn, 1, 1 );
868 grpLayout->setRowStretch( 2, 1 );
870 // Hypothesis definition errors
872 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
873 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
874 myHypErrorGroupLayout->setMargin(MARGIN);
875 myHypErrorGroupLayout->setSpacing(SPACING);
876 myHypErrorLabel = new QLabel(myHypErrorGroup);
877 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
881 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
882 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
883 myMemoryLackGroupLayout->setMargin(MARGIN);
884 myMemoryLackGroupLayout->setSpacing(SPACING);
885 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
886 QFont bold = memLackLabel->font(); bold.setBold(true);
887 memLackLabel->setFont( bold );
888 memLackLabel->setMinimumWidth(300);
889 myMemoryLackGroupLayout->addWidget(memLackLabel);
891 // add all widgets to aFrame
892 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
893 aLay->setMargin( 0 );
894 aLay->setSpacing( 0 );
895 aLay->addWidget( aPixGrp );
896 aLay->addWidget( nameBox );
897 aLay->addWidget( myBriefInfo );
898 aLay->addWidget( myFullInfo );
899 aLay->addWidget( myHypErrorGroup );
900 aLay->addWidget( myCompErrorGroup );
901 aLay->addWidget( myMemoryLackGroup );
902 aLay->setStretchFactor( myCompErrorGroup, 1 );
904 ((QPushButton*) button( OK ))->setDefault( true );
909 //================================================================================
913 //================================================================================
915 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
917 myDlg = new SMESHGUI_ComputeDlg;
918 myTShapeDisplayer = new SMESH::TShapeDisplayer();
919 //myHelpFileName = "/files/about_meshes.htm"; // V3
920 myHelpFileName = "about_meshes_page.html"; // V4
922 // connect signals and slots
923 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
924 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
925 connect(table(), SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
926 connect(table(), SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
929 //=======================================================================
930 // function : startOperation()
931 // purpose : Init dialog fields, connect signals and slots, show dialog
932 //=======================================================================
934 void SMESHGUI_ComputeOp::startOperation()
936 SMESHGUI_Operation::startOperation();
940 SMESH::SMESH_Mesh_var aMesh;
941 myMainShape = GEOM::GEOM_Object::_nil();
943 LightApp_SelectionMgr *Sel = selectionMgr();
944 SALOME_ListIO selected; Sel->selectedObjects( selected );
946 int nbSel = selected.Extent();
948 SUIT_MessageBox::warning(desktop(),
949 tr("SMESH_WRN_WARNING"),
950 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
955 Handle(SALOME_InteractiveObject) IObject = selected.First();
956 aMesh = SMESH::GetMeshByIO(IObject);
957 if (aMesh->_is_nil()) {
958 SUIT_MessageBox::warning(desktop(),
959 tr("SMESH_WRN_WARNING"),
960 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
967 SMESH::MemoryReserve aMemoryReserve;
969 SMESH::compute_error_array_var aCompErrors;
972 bool computeFailed = true, memoryLack = false;
974 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
975 myMainShape = aMesh->GetShapeToMesh();
976 bool hasShape = aMesh->HasShapeToMesh();
977 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
978 if ( shapeOK && aMeshSObj )
980 myDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
981 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
982 SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
983 if ( errors->length() > 0 ) {
984 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
986 SUIT_OverrideCursor aWaitCursor;
988 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
991 if (gen->Compute(aMesh, myMainShape))
992 computeFailed = false;
994 catch(const SALOME::SALOME_Exception & S_ex){
998 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1001 aCompErrors = gen->GetComputeErrors( aMesh, myMainShape );
1002 // check if there are memory problems
1003 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1004 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1006 catch(const SALOME::SALOME_Exception & S_ex){
1010 // NPAL16631: if ( !memoryLack )
1012 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
1013 update( UF_ObjBrowser | UF_Model );
1016 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
1017 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
1020 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1023 SMESH::Update(IObject, true);
1027 cout << "Exception thrown during mesh visualization" << endl;
1029 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1030 SMESH::OnVisuException();
1037 Sel->setSelectedObjects( selected );
1040 myDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1041 myDlg->myMemoryLackGroup->hide();
1045 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1046 bool noHypoError = ( aHypErrors.isEmpty() );
1050 myDlg->myMemoryLackGroup->show();
1051 myDlg->myFullInfo->hide();
1052 myDlg->myBriefInfo->hide();
1053 myDlg->myHypErrorGroup->hide();
1054 myDlg->myCompErrorGroup->hide();
1056 else if ( noCompError && noHypoError )
1058 myDlg->myFullInfo->SetInfoByMesh( aMesh );
1059 myDlg->myFullInfo->show();
1060 myDlg->myBriefInfo->hide();
1061 myDlg->myHypErrorGroup->hide();
1062 myDlg->myCompErrorGroup->hide();
1066 QTableWidget* tbl = myDlg->myTable;
1067 myDlg->myBriefInfo->SetInfoByMesh( aMesh );
1068 myDlg->myBriefInfo->show();
1069 myDlg->myFullInfo->hide();
1071 if ( noHypoError ) {
1072 myDlg->myHypErrorGroup->hide();
1075 myDlg->myHypErrorGroup->show();
1076 myDlg->myHypErrorLabel->setText( aHypErrors );
1079 if ( noCompError ) {
1080 myDlg->myCompErrorGroup->hide();
1083 myDlg->myCompErrorGroup->show();
1086 myDlg->myPublishBtn->hide();
1087 myDlg->myShowBtn->hide();
1090 myDlg->myPublishBtn->show();
1091 myDlg->myShowBtn->show();
1094 // fill table of errors
1095 tbl->setRowCount( aCompErrors->length() );
1096 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1097 else tbl->showColumn( COL_SHAPE );
1098 tbl->setColumnWidth( COL_ERROR, 200 );
1100 for ( int row = 0; row < aCompErrors->length(); ++row )
1102 SMESH::ComputeError & err = aCompErrors[ row ];
1104 QString text = err.algoName.in();
1105 if ( !tbl->item( row, COL_ALGO ) ) tbl->setItem( row, COL_ALGO, new QTableWidgetItem( text ) );
1106 else tbl->item( row, COL_ALGO )->setText( text );
1108 text = SMESH::errorText( err.code, err.comment.in() );
1109 if ( !tbl->item( row, COL_ERROR ) ) tbl->setItem( row, COL_ERROR, new QTableWidgetItem( text ) );
1110 else tbl->item( row, COL_ERROR )->setText( text );
1112 text = QString("%1").arg( err.subShapeID );
1113 if ( !tbl->item( row, COL_SHAPEID ) ) tbl->setItem( row, COL_SHAPEID, new QTableWidgetItem( text ) );
1114 else tbl->item( row, COL_SHAPEID )->setText( text );
1116 text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1117 if ( !tbl->item( row, COL_SHAPE ) ) tbl->setItem( row, COL_SHAPE, new QTableWidgetItem( text ) );
1118 else tbl->item( row, COL_SHAPE )->setText( text );
1120 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1121 if ( !tbl->item( row, COL_PUBLISHED ) ) tbl->setItem( row, COL_PUBLISHED, new QTableWidgetItem( text ) );
1122 else tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1124 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1125 tbl->resizeRowToContents( row );
1127 tbl->resizeColumnToContents( COL_ALGO );
1128 tbl->resizeColumnToContents( COL_SHAPE );
1130 tbl->setCurrentCell(0,0);
1131 currentCellChanged(); // to update buttons
1137 //================================================================================
1139 * \brief Stops operation
1141 //================================================================================
1143 void SMESHGUI_ComputeOp::stopOperation()
1145 SMESHGUI_Operation::stopOperation();
1146 myTShapeDisplayer->SetVisibility( false );
1149 //================================================================================
1151 * \brief publish selected subshape
1153 //================================================================================
1155 void SMESHGUI_ComputeOp::onPublishShape()
1157 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1158 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1161 SMESH::getSelectedRows( table(), rows );
1163 foreach ( row, rows )
1165 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1166 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1167 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1169 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1171 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1172 SALOMEDS::SObject_var so =
1173 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1174 // look for myMainShape in the table
1175 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1176 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1177 if ( so->_is_nil() ) {
1178 table()->item( r, COL_SHAPE )->setText( so->GetName() );
1179 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1184 if ( curSub == 1 ) continue;
1186 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1187 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1188 if ( !so->_is_nil() ) {
1189 table()->item( row, COL_SHAPE )->setText( so->GetName() );
1190 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1194 getSMESHGUI()->getApp()->updateObjectBrowser();
1195 currentCellChanged(); // to update buttons
1198 //================================================================================
1200 * \brief SLOT called when a selected cell in table() changed
1202 //================================================================================
1204 void SMESHGUI_ComputeOp::currentCellChanged()
1206 myTShapeDisplayer->SetVisibility( false );
1208 bool publishEnable = 0, showEnable = 0, showOnly = 1;
1210 SMESH::getSelectedRows( table(), rows );
1212 foreach ( row, rows )
1214 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1215 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1216 if ( hasData && !isPublished )
1217 publishEnable = true;
1219 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1220 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1222 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1229 myDlg->myPublishBtn->setEnabled( publishEnable );
1230 myDlg->myShowBtn->setEnabled( showEnable );
1233 //================================================================================
1235 * \brief update preview
1237 //================================================================================
1239 void SMESHGUI_ComputeOp::onPreviewShape()
1241 if ( myTShapeDisplayer )
1243 SUIT_OverrideCursor aWaitCursor;
1245 SMESH::getSelectedRows( table(), rows );
1247 bool showOnly = true;
1249 foreach ( row, rows )
1251 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1253 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1257 currentCellChanged(); // to update buttons
1261 //================================================================================
1265 //================================================================================
1267 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1269 if ( myTShapeDisplayer ) delete myTShapeDisplayer;
1272 //================================================================================
1274 * \brief Gets dialog of this operation
1275 * \retval LightApp_Dialog* - pointer to dialog of this operation
1277 //================================================================================
1279 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1284 //================================================================================
1286 * \brief perform it's intention action: compute mesh
1288 //================================================================================
1290 bool SMESHGUI_ComputeOp::onApply()
1295 //================================================================================
1297 * \brief Return a table
1299 //================================================================================
1301 QTableWidget* SMESHGUI_ComputeOp::table()
1303 return myDlg->myTable;