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>
82 #include <vtkProperty.h>
85 #include <SALOMEconfig.h>
86 #include CORBA_SERVER_HEADER(SMESH_Gen)
95 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
97 static void addSeparator( QWidget* parent )
99 QGridLayout* l = qobject_cast<QGridLayout*>( parent->layout() );
100 int row = l->rowCount();
101 int cols = l->columnCount();
102 for ( int i = 0; i < cols; i++ ) {
103 QFrame* hline = new QFrame( parent );
104 hline->setFrameStyle( QFrame::HLine | QFrame::Sunken );
105 l->addWidget( hline, row, i );
109 enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, NB_COLUMNS };
111 //using namespace SMESH;
115 //=============================================================================
117 * \brief Allocate some memory at construction and release it at destruction.
118 * Is used to be able to continue working after mesh generation or visualization
119 * break due to lack of memory
121 //=============================================================================
126 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
127 ~MemoryReserve() { delete [] myBuf; }
130 // =========================================================================================
132 * \brief Class showing shapes without publishing
134 // =========================================================================================
136 class TShapeDisplayer
139 // -----------------------------------------------------------------------
140 TShapeDisplayer(): myViewWindow(0)
142 myProperty = vtkProperty::New();
143 myProperty->SetRepresentationToWireframe();
144 myProperty->SetColor( 250, 0, 250 );
145 myProperty->SetAmbientColor( 250, 0, 250 );
146 myProperty->SetDiffuseColor( 250, 0, 250 );
147 //myProperty->SetSpecularColor( 250, 0, 250 );
148 myProperty->SetLineWidth( 5 );
150 // -----------------------------------------------------------------------
154 myProperty->Delete();
156 // -----------------------------------------------------------------------
159 if ( hasViewWindow() ) {
160 TActorIterator actorIt = actorIterator();
161 while ( actorIt.more() )
162 if (VTKViewer_Actor* anActor = actorIt.next()) {
163 myViewWindow->RemoveActor( anActor );
167 myIndexToShape.Clear();
169 myShownActors.clear();
172 // -----------------------------------------------------------------------
173 void SetVisibility (bool theVisibility)
175 TActorIterator actorIt = shownIterator();
176 while ( actorIt.more() )
177 if (VTKViewer_Actor* anActor = actorIt.next())
178 anActor->SetVisibility(theVisibility);
179 SMESH::RepaintCurrentView();
181 // -----------------------------------------------------------------------
182 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
185 if ( !aMainShape->_is_nil() )
186 mainEntry = aMainShape->GetStudyEntry();
187 return ( myMainEntry == mainEntry &&
188 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
190 // -----------------------------------------------------------------------
191 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
193 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
195 if ( !aMainShape->_is_nil() )
196 mainEntry = aMainShape->GetStudyEntry();
197 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
200 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
201 checkTriangulation( aShape );
202 TopExp::MapShapes(aShape, myIndexToShape);
203 myActors.resize( myIndexToShape.Extent(), 0 );
204 myShownActors.reserve( myIndexToShape.Extent() );
206 myMainEntry = mainEntry;
207 myViewWindow = aViewWindow;
209 if ( only ) { // hide shown actors
210 TActorIterator actorIt = shownIterator();
211 while ( actorIt.more() )
212 if (VTKViewer_Actor* anActor = actorIt.next())
213 anActor->SetVisibility(false);
214 myShownActors.clear();
216 // find actors to show
217 TopoDS_Shape aShape = myIndexToShape( subShapeID );
218 if ( !aShape.IsNull() ) {
219 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
220 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
221 //checkTriangulation( exp.Current() );
222 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
223 myShownActors.push_back( anActor );
225 if ( type == TopAbs_FACE ) {
226 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
227 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
228 if ( !BRep_Tool::Degenerated( edge ))
229 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
230 myShownActors.push_back( anActor );
234 myBuiltSubs.insert( subShapeID );
237 // -----------------------------------------------------------------------
241 typedef std::vector<GEOM_Actor*> TActorVec;
243 TActorVec myShownActors;
244 TopTools_IndexedMapOfShape myIndexToShape;
246 SVTK_ViewWindow* myViewWindow;
247 vtkProperty* myProperty;
248 std::set<int> myBuiltSubs;
250 // -----------------------------------------------------------------------
251 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
252 TActorIterator actorIterator() {
253 return TActorIterator( myActors.begin(), myActors.end() );
255 TActorIterator shownIterator() {
256 return TActorIterator( myShownActors.begin(), myShownActors.end() );
258 // -----------------------------------------------------------------------
259 GEOM_Actor* getActor(const TopoDS_Shape& shape)
261 int index = myIndexToShape.FindIndex( shape ) - 1;
262 if ( index < 0 || index >= myActors.size() )
264 GEOM_Actor* & actor = myActors[ index ];
266 actor = GEOM_Actor::New();
268 actor->setInputShape(shape,0,0);
269 //actor->SetProperty(myProperty);
270 actor->SetShadingProperty(myProperty);
271 actor->SetWireframeProperty(myProperty);
272 actor->SetPreviewProperty(myProperty);
273 actor->PickableOff();
274 // if ( shape.ShapeType() == TopAbs_EDGE )
275 // actor->SubShapeOn();
276 myViewWindow->AddActor( actor );
281 // -----------------------------------------------------------------------
282 void checkTriangulation(const TopoDS_Shape& shape)
284 TopLoc_Location aLoc;
285 Standard_Boolean alreadymesh = Standard_True;
286 TopExp_Explorer ex(shape, TopAbs_FACE);
288 for ( ; ex.More(); ex.Next()) {
289 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
290 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
291 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
294 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
295 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
296 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
297 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
299 if (alreadymesh) return;
300 // Compute default deflection
302 BRepBndLib::Add(shape, B);
303 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
304 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
305 double deflection = Max( aXmax-aXmin, Max ( aYmax-aYmin, aZmax-aZmin)) * 0.01 *4;
306 BRepMesh_IncrementalMesh MESH(shape,deflection);
308 // -----------------------------------------------------------------------
309 bool hasViewWindow() const
311 if ( !myViewWindow ) return false;
313 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
314 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
320 // =========================================================================================
322 * \brief Return text describing an error
324 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
325 QString errorText(int errCode, const char* comment)
329 CASE2TEXT( COMPERR_OK );
330 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
331 CASE2TEXT( COMPERR_STD_EXCEPTION );
332 CASE2TEXT( COMPERR_OCC_EXCEPTION );
333 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
334 CASE2TEXT( COMPERR_EXCEPTION );
335 CASE2TEXT( COMPERR_MEMORY_PB );
336 CASE2TEXT( COMPERR_BAD_SHAPE );
337 case SMESH::COMPERR_ALGO_FAILED:
338 if ( strlen(comment) == 0 )
339 text = QObject::tr("COMPERR_ALGO_FAILED");
342 text = QString("#%1").arg( -errCode );
344 if ( text.length() > 0 ) text += ". ";
345 return text + comment;
347 // -----------------------------------------------------------------------
349 * \brief Return SO of a subshape
351 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
353 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
354 if ( subShapeID == 1 || !so )
356 _PTR(ChildIterator) it;
357 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
358 it = study->NewChildIterator(so);
361 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
362 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
363 if ( !geom->_is_nil() ) {
364 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
365 if ( list->length() == 1 && list[0] == subShapeID )
372 // -----------------------------------------------------------------------
374 * \brief Return subshape by ID
376 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
378 GEOM::GEOM_Object_var aSubShape;
379 if ( subShapeID == 1 )
380 aSubShape = aMainShape;
381 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
382 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
384 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
385 return aSubShape._retn();
387 // -----------------------------------------------------------------------
389 * \brief Return shape type name
391 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
392 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
395 if ( !aShape->_is_nil() ) {
396 switch ( aShape->GetShapeType() ) {
403 CASE2NAME( COMPSOLID );
404 CASE2NAME( COMPOUND );
410 // -----------------------------------------------------------------------
412 * \brief Return text describing a subshape
414 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
417 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
418 text = aSO->GetName().c_str();
420 text = QString("#%1").arg( subShapeID );
421 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
422 if ( typeName.length() )
423 text += QString(" (%1)").arg(typeName);
427 // -----------------------------------------------------------------------
429 * \brief Return a list of selected rows
431 bool getSelectedRows(QTableWidget* table, QList<int>& rows)
434 QList<QTableWidgetSelectionRange> selRanges = table->selectedRanges();
435 QTableWidgetSelectionRange range;
436 foreach( range, selRanges )
438 for ( int row = range.topRow(); row <= range.bottomRow(); ++row )
441 if ( rows.isEmpty() && table->currentRow() > -1 )
442 rows.append( table->currentRow() );
444 return !rows.isEmpty();
450 // =========================================================================================
452 * \brief Box showing mesh info
454 // =========================================================================================
456 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
457 : QGroupBox( tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
459 QGridLayout* l = new QGridLayout(this);
460 l->setMargin( MARGIN );
461 l->setSpacing( SPACING );
463 QFont italic = font(); italic.setItalic(true);
464 QFont bold = font(); bold.setBold(true);
470 lab = new QLabel( this );
471 lab->setMinimumWidth(100); lab->setFont( italic );
472 l->addWidget( lab, row, 0 );
474 lab = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
475 lab->setMinimumWidth(100); lab->setFont( italic );
476 l->addWidget( lab, row, 1 );
478 lab = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
479 lab->setMinimumWidth(100); lab->setFont( italic );
480 l->addWidget( lab, row, 2 );
482 lab = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
483 lab->setMinimumWidth(100); lab->setFont( italic );
484 l->addWidget( lab, row, 3 );
489 row = l->rowCount(); // retrieve current row count
491 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
492 lab->setFont( bold );
493 l->addWidget( lab, row, 0 );
495 myNbNode = new QLabel( this );
496 l->addWidget( myNbNode, row, 1 );
498 addSeparator(this); // add separator
501 row = l->rowCount(); // retrieve current row count
503 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
504 lab->setFont( bold );
505 l->addWidget( lab, row, 0 );
507 myNbEdge = new QLabel( this );
508 l->addWidget( myNbEdge, row, 1 );
510 myNbLinEdge = new QLabel( this );
511 l->addWidget( myNbLinEdge, row, 2 );
513 myNbQuadEdge = new QLabel( this );
514 l->addWidget( myNbQuadEdge, row, 3 );
516 addSeparator(this); // add separator
519 row = l->rowCount(); // retrieve current row count
521 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
522 lab->setFont( bold );
523 l->addWidget( lab, row, 0 );
525 myNbFace = new QLabel( this );
526 l->addWidget( myNbFace, row, 1 );
528 myNbLinFace = new QLabel( this );
529 l->addWidget( myNbLinFace, row, 2 );
531 myNbQuadFace = new QLabel( this );
532 l->addWidget( myNbQuadFace, row, 3 );
534 row++; // increment row count
536 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
537 l->addWidget( lab, row, 0 );
539 myNbTrai = new QLabel( this );
540 l->addWidget( myNbTrai, row, 1 );
542 myNbLinTrai = new QLabel( this );
543 l->addWidget( myNbLinTrai, row, 2 );
545 myNbQuadTrai = new QLabel( this );
546 l->addWidget( myNbQuadTrai, row, 3 );
548 row++; // increment row count
550 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
551 l->addWidget( lab, row, 0 );
553 myNbQuad = new QLabel( this );
554 l->addWidget( myNbQuad, row, 1 );
556 myNbLinQuad = new QLabel( this );
557 l->addWidget( myNbLinQuad, row, 2 );
559 myNbQuadQuad = new QLabel( this );
560 l->addWidget( myNbQuadQuad, row, 3 );
562 row++; // increment row count
564 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
565 l->addWidget( lab, row, 0 );
566 myNbPolyg = new QLabel( this );
567 l->addWidget( myNbPolyg, row, 1 );
569 addSeparator(this); // add separator
572 row = l->rowCount(); // retrieve current row count
574 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
575 lab->setFont( bold );
576 l->addWidget( lab, row, 0 );
578 myNbVolum = new QLabel( this );
579 l->addWidget( myNbVolum, row, 1 );
581 myNbLinVolum = new QLabel( this );
582 l->addWidget( myNbLinVolum, row, 2 );
584 myNbQuadVolum = new QLabel( this );
585 l->addWidget( myNbQuadVolum, row, 3 );
587 row++; // increment row count
589 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
590 l->addWidget( lab, row, 0 );
592 myNbTetra = new QLabel( this );
593 l->addWidget( myNbTetra, row, 1 );
595 myNbLinTetra = new QLabel( this );
596 l->addWidget( myNbLinTetra, row, 2 );
598 myNbQuadTetra = new QLabel( this );
599 l->addWidget( myNbQuadTetra, row, 3 );
601 row++; // increment row count
603 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
604 l->addWidget( lab, row, 0 );
606 myNbHexa = new QLabel( this );
607 l->addWidget( myNbHexa, row, 1 );
609 myNbLinHexa = new QLabel( this );
610 l->addWidget( myNbLinHexa, row, 2 );
612 myNbQuadHexa = new QLabel( this );
613 l->addWidget( myNbQuadHexa, row, 3 );
615 row++; // increment row count
617 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
618 l->addWidget( lab, row, 0 );
620 myNbPyra = new QLabel( this );
621 l->addWidget( myNbPyra, row, 1 );
623 myNbLinPyra = new QLabel( this );
624 l->addWidget( myNbLinPyra, row, 2 );
626 myNbQuadPyra = new QLabel( this );
627 l->addWidget( myNbQuadPyra, row, 3 );
629 row++; // increment row count
631 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
632 l->addWidget( lab, row, 0 );
634 myNbPrism = new QLabel( this );
635 l->addWidget( myNbPrism, row, 1 );
637 myNbLinPrism = new QLabel( this );
638 l->addWidget( myNbLinPrism, row, 2 );
640 myNbQuadPrism = new QLabel( this );
641 l->addWidget( myNbQuadPrism, row, 3 );
643 row++; // increment row count
645 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
646 l->addWidget( lab, row, 0 );
648 myNbPolyh = new QLabel( this );
649 l->addWidget( myNbPolyh, row, 1 );
654 row = l->rowCount(); // retrieve current row count
656 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
657 l->addWidget( lab, row, 0 );
659 myNbNode = new QLabel( this );
660 l->addWidget( myNbNode, row, 1 );
663 row = l->rowCount(); // retrieve current row count
665 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
666 l->addWidget( lab, row, 0 );
668 myNbEdge = new QLabel( this );
669 l->addWidget( myNbEdge, row, 1 );
671 myNbLinEdge = new QLabel( this );
672 l->addWidget( myNbLinEdge, row, 2 );
674 myNbQuadEdge = new QLabel( this );
675 l->addWidget( myNbQuadEdge, row, 3 );
678 row = l->rowCount(); // retrieve current row count
680 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
681 l->addWidget( lab, row, 0 );
683 myNbFace = new QLabel( this );
684 l->addWidget( myNbFace, row, 1 );
686 myNbLinFace = new QLabel( this );
687 l->addWidget( myNbLinFace, row, 2 );
689 myNbQuadFace = new QLabel( this );
690 l->addWidget( myNbQuadFace, row, 3 );
693 row = l->rowCount(); // retrieve current row count
695 lab = new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
696 l->addWidget( lab, row, 0 );
698 myNbVolum = new QLabel( this );
699 l->addWidget( myNbVolum, row, 1 );
701 myNbLinVolum = new QLabel( this );
702 l->addWidget( myNbLinVolum, row, 2 );
704 myNbQuadVolum = new QLabel( this );
705 l->addWidget( myNbQuadVolum, row, 3 );
709 // =========================================================================================
711 * \brief Set mesh info
713 // =========================================================================================
715 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
717 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
721 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
724 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
725 myNbEdge ->setText( QString("%1").arg( nbTot ));
726 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
727 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
730 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
731 myNbFace ->setText( QString("%1").arg( nbTot ));
732 myNbLinFace ->setText( QString("%1").arg( nbLin ));
733 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
736 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
737 myNbVolum ->setText( QString("%1").arg( nbTot ));
738 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
739 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
744 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
745 myNbTrai ->setText( QString("%1").arg( nbTot ));
746 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
747 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
749 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
750 myNbQuad ->setText( QString("%1").arg( nbTot ));
751 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
752 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
754 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
757 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
758 myNbTetra ->setText( QString("%1").arg( nbTot ));
759 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
760 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
762 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
763 myNbHexa ->setText( QString("%1").arg( nbTot ));
764 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
765 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
767 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
768 myNbPyra ->setText( QString("%1").arg( nbTot ));
769 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
770 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
772 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
773 myNbPrism ->setText( QString("%1").arg( nbTot ));
774 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
775 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
777 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
781 // =========================================================================================
783 * \brief Dialog to compute a mesh and show computation errors
785 //=======================================================================
787 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, OK/* | Help*/ )
789 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame());
790 aDlgLay->setMargin( 0 );
791 aDlgLay->setSpacing( SPACING );
793 QFrame* aMainFrame = createMainFrame (mainFrame());
795 aDlgLay->addWidget(aMainFrame);
797 aDlgLay->setStretchFactor(aMainFrame, 1);
800 //=======================================================================
801 // function : createMainFrame()
802 // purpose : Create frame containing dialog's fields
803 //=======================================================================
805 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
807 QFrame* aFrame = new QFrame(theParent);
809 SUIT_ResourceMgr* rm = resourceMgr();
810 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
814 QGroupBox* aPixGrp = new QGroupBox(tr("CONSTRUCTOR"), aFrame);
815 QHBoxLayout* aPixGrpLayout = new QHBoxLayout(aPixGrp);
816 aPixGrpLayout->setMargin(MARGIN); aPixGrpLayout->setSpacing(SPACING);
818 QRadioButton* aRBut = new QRadioButton(aPixGrp);
819 aRBut->setIcon(iconCompute);
820 aRBut->setChecked(true);
821 aPixGrpLayout->addWidget(aRBut);
825 QGroupBox* nameBox = new QGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
826 QHBoxLayout* nameBoxLayout = new QHBoxLayout(nameBox);
827 nameBoxLayout->setMargin(MARGIN); nameBoxLayout->setSpacing(SPACING);
828 myMeshName = new QLabel(nameBox);
829 nameBoxLayout->addWidget(myMeshName);
833 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
834 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
836 // Computation errors
838 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame);
839 myTable = new QTableWidget( 1, NB_COLUMNS, myCompErrorGroup);
840 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup);
841 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup);
843 //myTable->setReadOnly( true ); // VSR: check
844 myTable->setEditTriggers( QAbstractItemView::NoEditTriggers );
845 myTable->hideColumn( COL_PUBLISHED );
846 myTable->hideColumn( COL_SHAPEID );
847 myTable->horizontalHeader()->setResizeMode( COL_ERROR, QHeaderView::Interactive );
850 headers << tr( "COL_ALGO_HEADER" );
851 headers << tr( "COL_SHAPE_HEADER" );
852 headers << tr( "COL_ERROR_HEADER" );
853 headers << tr( "COL_SHAPEID_HEADER" );
854 headers << tr( "COL_PUBLISHED_HEADER" );
856 myTable->setHorizontalHeaderLabels( headers );
859 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup);
860 grpLayout->setSpacing(SPACING);
861 grpLayout->setMargin(MARGIN);
862 grpLayout->addWidget( myTable, 0, 0, 3, 1 );
863 grpLayout->addWidget( myShowBtn, 0, 1 );
864 grpLayout->addWidget( myPublishBtn, 1, 1 );
865 grpLayout->setRowStretch( 2, 1 );
867 // Hypothesis definition errors
869 myHypErrorGroup = new QGroupBox(tr("SMESH_WRN_MISSING_PARAMETERS"), aFrame);
870 QHBoxLayout* myHypErrorGroupLayout = new QHBoxLayout(myHypErrorGroup);
871 myHypErrorGroupLayout->setMargin(MARGIN);
872 myHypErrorGroupLayout->setSpacing(SPACING);
873 myHypErrorLabel = new QLabel(myHypErrorGroup);
874 myHypErrorGroupLayout->addWidget(myHypErrorLabel);
878 myMemoryLackGroup = new QGroupBox(tr("ERRORS"), aFrame);
879 QVBoxLayout* myMemoryLackGroupLayout = new QVBoxLayout(myMemoryLackGroup);
880 myMemoryLackGroupLayout->setMargin(MARGIN);
881 myMemoryLackGroupLayout->setSpacing(SPACING);
882 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
883 QFont bold = memLackLabel->font(); bold.setBold(true);
884 memLackLabel->setFont( bold );
885 memLackLabel->setMinimumWidth(300);
886 myMemoryLackGroupLayout->addWidget(memLackLabel);
888 // add all widgets to aFrame
889 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
890 aLay->setMargin( 0 );
891 aLay->setSpacing( 0 );
892 aLay->addWidget( aPixGrp );
893 aLay->addWidget( nameBox );
894 aLay->addWidget( myBriefInfo );
895 aLay->addWidget( myFullInfo );
896 aLay->addWidget( myHypErrorGroup );
897 aLay->addWidget( myCompErrorGroup );
898 aLay->addWidget( myMemoryLackGroup );
899 aLay->setStretchFactor( myCompErrorGroup, 1 );
901 ((QPushButton*) button( OK ))->setDefault( true );
906 //================================================================================
910 //================================================================================
912 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
914 myDlg = new SMESHGUI_ComputeDlg;
915 myTShapeDisplayer = new SMESH::TShapeDisplayer();
916 //myHelpFileName = "/files/about_meshes.htm"; // V3
917 myHelpFileName = "about_meshes_page.html"; // V4
919 // connect signals and slots
920 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
921 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
922 connect(table(), SIGNAL(itemSelectionChanged()), SLOT(currentCellChanged()));
923 connect(table(), SIGNAL(currentCellChanged(int,int,int,int)), SLOT(currentCellChanged()));
926 //=======================================================================
927 // function : startOperation()
928 // purpose : Init dialog fields, connect signals and slots, show dialog
929 //=======================================================================
931 void SMESHGUI_ComputeOp::startOperation()
933 SMESHGUI_Operation::startOperation();
937 SMESH::SMESH_Mesh_var aMesh;
938 myMainShape = GEOM::GEOM_Object::_nil();
940 LightApp_SelectionMgr *Sel = selectionMgr();
941 SALOME_ListIO selected; Sel->selectedObjects( selected );
943 int nbSel = selected.Extent();
945 SUIT_MessageBox::warning(desktop(),
946 tr("SMESH_WRN_WARNING"),
947 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
952 Handle(SALOME_InteractiveObject) IObject = selected.First();
953 aMesh = SMESH::GetMeshByIO(IObject);
954 if (aMesh->_is_nil()) {
955 SUIT_MessageBox::warning(desktop(),
956 tr("SMESH_WRN_WARNING"),
957 tr("SMESH_WRN_NO_AVAILABLE_DATA"));
964 SMESH::MemoryReserve aMemoryReserve;
966 SMESH::compute_error_array_var aCompErrors;
969 bool computeFailed = true, memoryLack = false;
971 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
972 myMainShape = aMesh->GetShapeToMesh();
973 bool hasShape = aMesh->HasShapeToMesh();
974 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
975 if ( shapeOK && aMeshSObj )
977 myDlg->myMeshName->setText( aMeshSObj->GetName().c_str() );
978 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
979 SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
980 if ( errors->length() > 0 ) {
981 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
983 SUIT_OverrideCursor aWaitCursor;
985 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
988 if (gen->Compute(aMesh, myMainShape))
989 computeFailed = false;
991 catch(const SALOME::SALOME_Exception & S_ex){
995 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
998 aCompErrors = gen->GetComputeErrors( aMesh, myMainShape );
999 // check if there are memory problems
1000 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
1001 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
1003 catch(const SALOME::SALOME_Exception & S_ex){
1007 // NPAL16631: if ( !memoryLack )
1009 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, aMesh->NbNodes() == 0);
1010 update( UF_ObjBrowser | UF_Model );
1013 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
1014 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
1017 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
1020 SMESH::Update(IObject, true);
1024 cout << "Exception thrown during mesh visualization" << endl;
1026 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
1027 SMESH::OnVisuException();
1034 Sel->setSelectedObjects( selected );
1037 myDlg->setWindowTitle(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
1038 myDlg->myMemoryLackGroup->hide();
1042 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
1043 bool noHypoError = ( aHypErrors.isEmpty() );
1047 myDlg->myMemoryLackGroup->show();
1048 myDlg->myFullInfo->hide();
1049 myDlg->myBriefInfo->hide();
1050 myDlg->myHypErrorGroup->hide();
1051 myDlg->myCompErrorGroup->hide();
1053 else if ( noCompError && noHypoError )
1055 myDlg->myFullInfo->SetInfoByMesh( aMesh );
1056 myDlg->myFullInfo->show();
1057 myDlg->myBriefInfo->hide();
1058 myDlg->myHypErrorGroup->hide();
1059 myDlg->myCompErrorGroup->hide();
1063 QTableWidget* tbl = myDlg->myTable;
1064 myDlg->myBriefInfo->SetInfoByMesh( aMesh );
1065 myDlg->myBriefInfo->show();
1066 myDlg->myFullInfo->hide();
1068 if ( noHypoError ) {
1069 myDlg->myHypErrorGroup->hide();
1072 myDlg->myHypErrorGroup->show();
1073 myDlg->myHypErrorLabel->setText( aHypErrors );
1076 if ( noCompError ) {
1077 myDlg->myCompErrorGroup->hide();
1080 myDlg->myCompErrorGroup->show();
1083 myDlg->myPublishBtn->hide();
1084 myDlg->myShowBtn->hide();
1087 myDlg->myPublishBtn->show();
1088 myDlg->myShowBtn->show();
1091 // fill table of errors
1092 tbl->setRowCount( aCompErrors->length() );
1093 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
1094 else tbl->showColumn( COL_SHAPE );
1095 tbl->setColumnWidth( COL_ERROR, 200 );
1097 for ( int row = 0; row < aCompErrors->length(); ++row )
1099 SMESH::ComputeError & err = aCompErrors[ row ];
1100 tbl->item( row, COL_ALGO )->setText( err.algoName.in() );
1101 tbl->item( row, COL_ERROR )->setText( SMESH::errorText( err.code, err.comment.in() ));
1102 tbl->item( row, COL_SHAPEID )->setText( QString("%1").arg( err.subShapeID ));
1104 QString text = hasShape ? SMESH::shapeText( err.subShapeID, myMainShape ) : QString("");
1105 tbl->item( row, COL_SHAPE )->setText( text );
1107 text = ( !hasShape || SMESH::getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
1108 tbl->item( row, COL_PUBLISHED )->setText( text ); // if text=="", "PUBLISH" button enabled
1110 //tbl->item( row, COL_ERROR )->setWordWrap( true ); // VSR: TODO ???
1111 tbl->resizeRowToContents( row );
1113 tbl->resizeColumnToContents( COL_ALGO );
1114 tbl->resizeColumnToContents( COL_SHAPE );
1116 tbl->setCurrentCell(0,0);
1117 currentCellChanged(); // to update buttons
1123 //================================================================================
1125 * \brief Stops operation
1127 //================================================================================
1129 void SMESHGUI_ComputeOp::stopOperation()
1131 SMESHGUI_Operation::stopOperation();
1132 myTShapeDisplayer->SetVisibility( false );
1135 //================================================================================
1137 * \brief publish selected subshape
1139 //================================================================================
1141 void SMESHGUI_ComputeOp::onPublishShape()
1143 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1144 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1147 SMESH::getSelectedRows( table(), rows );
1149 foreach ( row, rows )
1151 int curSub = table()->item(row, COL_SHAPEID)->text().toInt();
1152 GEOM::GEOM_Object_var shape = SMESH::getSubShape( curSub, myMainShape );
1153 if ( !shape->_is_nil() && ! SMESH::getSubShapeSO( curSub, myMainShape ))
1155 if ( !SMESH::getSubShapeSO( 1, myMainShape )) // the main shape not published
1157 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1158 SALOMEDS::SObject_var so =
1159 geomGen->AddInStudy( study, myMainShape, name.toLatin1().data(), GEOM::GEOM_Object::_nil());
1160 // look for myMainShape in the table
1161 for ( int r = 0, nr = table()->rowCount(); r < nr; ++r ) {
1162 if ( table()->item( r, COL_SHAPEID )->text() == "1" ) {
1163 if ( so->_is_nil() ) {
1164 table()->item( r, COL_SHAPE )->setText( so->GetName() );
1165 table()->item( r, COL_PUBLISHED )->setText( so->GetID() );
1170 if ( curSub == 1 ) continue;
1172 QString name = GEOMBase::GetDefaultName( SMESH::shapeTypeName( shape, "ERROR_SHAPE" ));
1173 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name.toLatin1().data(), myMainShape);
1174 if ( !so->_is_nil() ) {
1175 table()->item( row, COL_SHAPE )->setText( so->GetName() );
1176 table()->item( row, COL_PUBLISHED )->setText( so->GetID() );
1180 getSMESHGUI()->getApp()->updateObjectBrowser();
1181 currentCellChanged(); // to update buttons
1184 //================================================================================
1186 * \brief SLOT called when a selected cell in table() changed
1188 //================================================================================
1190 void SMESHGUI_ComputeOp::currentCellChanged()
1192 myTShapeDisplayer->SetVisibility( false );
1194 bool publishEnable = 0, showEnable = 0, showOnly = 1;
1196 SMESH::getSelectedRows( table(), rows );
1198 foreach ( row, rows )
1200 bool hasData = ( !table()->item( row, COL_SHAPE )->text().isEmpty() );
1201 bool isPublished = ( !table()->item( row, COL_PUBLISHED )->text().isEmpty() );
1202 if ( hasData && !isPublished )
1203 publishEnable = true;
1205 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1206 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1208 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1215 myDlg->myPublishBtn->setEnabled( publishEnable );
1216 myDlg->myShowBtn->setEnabled( showEnable );
1219 //================================================================================
1221 * \brief update preview
1223 //================================================================================
1225 void SMESHGUI_ComputeOp::onPreviewShape()
1227 if ( myTShapeDisplayer )
1229 SUIT_OverrideCursor aWaitCursor;
1231 SMESH::getSelectedRows( table(), rows );
1233 bool showOnly = true;
1235 foreach ( row, rows )
1237 int curSub = table()->item( row, COL_SHAPEID )->text().toInt();
1239 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1243 currentCellChanged(); // to update buttons
1247 //================================================================================
1251 //================================================================================
1253 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1255 if ( myTShapeDisplayer ) delete myTShapeDisplayer;
1258 //================================================================================
1260 * \brief Gets dialog of this operation
1261 * \retval LightApp_Dialog* - pointer to dialog of this operation
1263 //================================================================================
1265 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1270 //================================================================================
1272 * \brief perform it's intention action: compute mesh
1274 //================================================================================
1276 bool SMESHGUI_ComputeOp::onApply()
1281 //================================================================================
1283 * \brief Return a table
1285 //================================================================================
1287 QTableWidget* SMESHGUI_ComputeOp::table()
1289 return myDlg->myTable;