1 // Copyright (C) 2007-2008 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
22 // SMESH SMESHGUI : GUI for SMESH component
23 // File : SMESHGUI_ComputeDlg.cxx
24 // Author : Edward AGAPOV
27 #include "SMESHGUI_ComputeDlg.h"
30 #include "SMESHGUI_GEOMGenUtils.h"
31 #include "SMESHGUI_MeshUtils.h"
32 #include "SMESHGUI_Utils.h"
33 #include "SMESHGUI_VTKUtils.h"
34 #include "SMESHGUI_HypothesesUtils.h"
35 #include "SMESHGUI_MeshEditPreview.h"
36 #include "SMESH_ActorUtils.h"
38 #include "SMDS_SetIterator.hxx"
39 #include "SMDS_Mesh.hxx"
42 #include "GEOM_Actor.h"
44 #include "LightApp_SelectionMgr.h"
45 #include "LightApp_UpdateFlags.h"
46 #include "SALOMEDSClient_SObject.hxx"
47 #include "SALOME_ListIO.hxx"
48 #include "SVTK_ViewWindow.h"
49 #include "SVTK_ViewModel.h"
50 #include "SalomeApp_Tools.h"
51 #include "SalomeApp_Application.h"
52 #include "SUIT_ResourceMgr.h"
53 #include "SUIT_OverrideCursor.h"
54 #include "SUIT_MessageBox.h"
55 #include "SUIT_Desktop.h"
56 #include "SUIT_Study.h"
57 #include "OB_Browser.h"
60 #include <BRep_Tool.hxx>
62 #include <TopExp_Explorer.hxx>
63 #include <TopTools_IndexedMapOfShape.hxx>
66 #include <TopLoc_Location.hxx>
67 #include <Poly_Triangulation.hxx>
68 #include <Bnd_Box.hxx>
69 #include <BRepBndLib.hxx>
70 #include <BRepMesh_IncrementalMesh.hxx>
72 #include <Standard_ErrorHandler.hxx>
77 #include <qpushbutton.h>
79 #include <qbuttongroup.h>
80 #include <qradiobutton.h>
83 #include <qhgroupbox.h>
84 #include <qvgroupbox.h>
86 #include <vtkProperty.h>
89 #include <SALOMEconfig.h>
90 #include CORBA_SERVER_HEADER(SMESH_Gen)
91 #include CORBA_SERVER_HEADER(SMESH_Mesh)
102 #define COLONIZE(str) (QString(str).contains(":") > 0 ? QString(str) : QString(str) + " :" )
104 #define _SEPARATOR(father) \
106 /*new QLabel(father); new QLabel(father); new QLabel(father)*/;\
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);\
110 (new QFrame(father))->setFrameStyle(QFrame::HLine | QFrame::Sunken);\
114 COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, COL_BAD_MESH, NB_COLUMNS
117 using namespace SMESH;
121 //=============================================================================
123 * \brief Allocate some memory at construction and release it at destruction.
124 * Is used to be able to continue working after mesh generation or visualization
125 * break due to lack of memory
127 //=============================================================================
132 MemoryReserve(): myBuf( new char[1024*1024*1] ){} // 1M
133 void release() { delete [] myBuf; myBuf = 0; }
134 ~MemoryReserve() { release(); }
137 // =========================================================================================
139 * \brief Class showing shapes without publishing
141 // =========================================================================================
143 class TShapeDisplayer
146 // -----------------------------------------------------------------------
147 TShapeDisplayer(): myViewWindow(0)
149 myProperty = vtkProperty::New();
150 myProperty->SetRepresentationToWireframe();
151 myProperty->SetColor( 250, 0, 250 );
152 myProperty->SetAmbientColor( 250, 0, 250 );
153 myProperty->SetDiffuseColor( 250, 0, 250 );
154 //myProperty->SetSpecularColor( 250, 0, 250 );
155 myProperty->SetLineWidth( 5 );
157 // -----------------------------------------------------------------------
161 myProperty->Delete();
163 // -----------------------------------------------------------------------
166 if ( hasViewWindow() ) {
167 TActorIterator actorIt = actorIterator();
168 while ( actorIt.more() )
169 if (VTKViewer_Actor* anActor = actorIt.next()) {
170 myViewWindow->RemoveActor( anActor );
174 myIndexToShape.Clear();
176 myShownActors.clear();
179 // -----------------------------------------------------------------------
180 void SetVisibility (bool theVisibility)
182 TActorIterator actorIt = shownIterator();
183 while ( actorIt.more() )
184 if (VTKViewer_Actor* anActor = actorIt.next())
185 anActor->SetVisibility(theVisibility);
186 SMESH::RepaintCurrentView();
188 // -----------------------------------------------------------------------
189 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
192 if ( !aMainShape->_is_nil() )
193 mainEntry = aMainShape->GetStudyEntry();
194 return ( myMainEntry == mainEntry &&
195 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
197 // -----------------------------------------------------------------------
198 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
200 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
202 if ( !aMainShape->_is_nil() )
203 mainEntry = aMainShape->GetStudyEntry();
204 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
207 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
208 checkTriangulation( aShape );
209 TopExp::MapShapes(aShape, myIndexToShape);
210 myActors.resize( myIndexToShape.Extent(), 0 );
211 myShownActors.reserve( myIndexToShape.Extent() );
213 myMainEntry = mainEntry;
214 myViewWindow = aViewWindow;
216 if ( only ) { // hide shown actors
217 TActorIterator actorIt = shownIterator();
218 while ( actorIt.more() )
219 if (VTKViewer_Actor* anActor = actorIt.next())
220 anActor->SetVisibility(false);
221 myShownActors.clear();
223 // find actors to show
224 TopoDS_Shape aShape = myIndexToShape( subShapeID );
225 if ( !aShape.IsNull() ) {
226 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
227 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
228 //checkTriangulation( exp.Current() );
229 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
230 myShownActors.push_back( anActor );
232 if ( type == TopAbs_FACE ) {
233 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
234 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
235 if ( !BRep_Tool::Degenerated( edge ))
236 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
237 myShownActors.push_back( anActor );
241 myBuiltSubs.insert( subShapeID );
244 // -----------------------------------------------------------------------
248 typedef std::vector<GEOM_Actor*> TActorVec;
250 TActorVec myShownActors;
251 TopTools_IndexedMapOfShape myIndexToShape;
253 SVTK_ViewWindow* myViewWindow;
254 vtkProperty* myProperty;
255 std::set<int> myBuiltSubs;
257 // -----------------------------------------------------------------------
258 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
259 TActorIterator actorIterator() {
260 return TActorIterator( myActors.begin(), myActors.end() );
262 TActorIterator shownIterator() {
263 return TActorIterator( myShownActors.begin(), myShownActors.end() );
265 // -----------------------------------------------------------------------
266 GEOM_Actor* getActor(const TopoDS_Shape& shape)
268 int index = myIndexToShape.FindIndex( shape ) - 1;
269 if ( index < 0 || index >= myActors.size() )
271 GEOM_Actor* & actor = myActors[ index ];
273 actor = GEOM_Actor::New();
275 actor->SetShape(shape,0,0);
276 actor->SetProperty(myProperty);
277 actor->SetShadingProperty(myProperty);
278 actor->SetWireframeProperty(myProperty);
279 actor->SetPreviewProperty(myProperty);
280 actor->PickableOff();
281 // if ( shape.ShapeType() == TopAbs_EDGE )
282 // actor->SubShapeOn();
283 myViewWindow->AddActor( actor );
288 // -----------------------------------------------------------------------
289 void checkTriangulation(const TopoDS_Shape& shape)
291 TopLoc_Location aLoc;
292 Standard_Boolean alreadymesh = Standard_True;
293 TopExp_Explorer ex(shape, TopAbs_FACE);
295 for (; ex.More(); ex.Next()) {
296 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
297 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
298 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
301 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
302 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
303 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
304 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
306 if (alreadymesh) return;
307 // Compute default deflection
309 BRepBndLib::Add(shape, B);
310 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
311 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
312 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
313 BRepMesh_IncrementalMesh MESH(shape,deflection);
315 // -----------------------------------------------------------------------
316 bool hasViewWindow() const
318 if ( !myViewWindow ) return false;
320 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
321 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
327 // =========================================================================================
329 * \brief Return text describing an error
331 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
332 QString errorText(int errCode, const char* comment)
336 CASE2TEXT( COMPERR_OK );
337 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
338 CASE2TEXT( COMPERR_STD_EXCEPTION );
339 CASE2TEXT( COMPERR_OCC_EXCEPTION );
340 case SMESH::COMPERR_SLM_EXCEPTION: break; // avoid double "Salome exception"
341 CASE2TEXT( COMPERR_EXCEPTION );
342 CASE2TEXT( COMPERR_MEMORY_PB );
343 CASE2TEXT( COMPERR_BAD_SHAPE );
344 case SMESH::COMPERR_ALGO_FAILED:
345 if ( strlen(comment) == 0 )
346 text = QObject::tr("COMPERR_ALGO_FAILED");
349 text = QString("#%1").arg( -errCode );
351 if ( text.length() > 0 ) text += ". ";
352 return text + comment;
354 // -----------------------------------------------------------------------
356 * \brief Return SO of a subshape
358 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
360 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
361 if ( subShapeID == 1 || !so )
363 _PTR(ChildIterator) it;
364 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
365 it = study->NewChildIterator(so);
368 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
369 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
370 if ( !geom->_is_nil() ) {
371 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
372 if ( list->length() == 1 && list[0] == subShapeID )
379 // -----------------------------------------------------------------------
381 * \brief Return subshape by ID
383 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
385 GEOM::GEOM_Object_var aSubShape;
386 if ( subShapeID == 1 )
387 aSubShape = aMainShape;
388 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
389 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
391 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
392 return aSubShape._retn();
394 // -----------------------------------------------------------------------
396 * \brief Return shape type name
398 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
399 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
402 if ( !aShape->_is_nil() ) {
403 switch ( aShape->GetShapeType() ) {
410 CASE2NAME( COMPSOLID );
411 CASE2NAME( COMPOUND );
417 // -----------------------------------------------------------------------
419 * \brief Return text describing a subshape
421 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
424 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
425 text = aSO->GetName();
427 text = QString("#%1").arg( subShapeID );
428 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
429 if ( typeName.length() )
430 text += QString(" (%1)").arg(typeName);
434 // -----------------------------------------------------------------------
436 * \brief Return a list of selected rows
438 int getSelectedRows(QTable* table, list< int > & rows)
441 int nbSel = table->numSelections();
442 for ( int i = 0; i < nbSel; ++i )
444 QTableSelection selected = table->selection(i);
445 if ( !selected.isActive() ) continue;
446 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
447 rows.push_back( row );
449 if (rows.empty() && table->currentRow() > -1 )
450 rows.push_back( table->currentRow() );
458 // =========================================================================================
460 * \brief Box showing mesh info
462 // =========================================================================================
464 SMESHGUI_MeshInfosBox::SMESHGUI_MeshInfosBox(const bool full, QWidget* theParent)
465 :QGroupBox( 4, Qt::Horizontal, tr("SMESH_MESHINFO_TITLE"), theParent ), myFull( full )
468 QLabel* lab1 = new QLabel(this);
469 QLabel* lab2 = new QLabel(tr("SMESH_MESHINFO_ORDER0"), this );
470 QLabel* lab3 = new QLabel(tr("SMESH_MESHINFO_ORDER1"), this );
471 QLabel* lab4 = new QLabel(tr("SMESH_MESHINFO_ORDER2"), this );
473 QFont italic = lab1->font(); italic.setItalic(true);
474 QFont bold = lab1->font(); bold.setBold(true);
476 lab1->setMinimumWidth(100); lab1->setFont( italic );
477 lab2->setMinimumWidth(100); lab2->setFont( italic );
478 lab3->setMinimumWidth(100); lab3->setFont( italic );
479 lab4->setMinimumWidth(100); lab4->setFont( italic );
484 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this ))->setFont( bold );
485 myNbNode = new QLabel( this );
492 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this ))->setFont( bold );
493 myNbEdge = new QLabel( this );
494 myNbLinEdge = new QLabel( this );
495 myNbQuadEdge = new QLabel( this );
500 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this))->setFont( bold );
501 myNbFace = new QLabel( this );
502 myNbLinFace = new QLabel( this );
503 myNbQuadFace = new QLabel( this );
505 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TRIANGLES")), this );
506 myNbTrai = new QLabel( this );
507 myNbLinTrai = new QLabel( this );
508 myNbQuadTrai = new QLabel( this );
510 new QLabel(COLONIZE(tr("SMESH_MESHINFO_QUADRANGLES")), this );
511 myNbQuad = new QLabel( this );
512 myNbLinQuad = new QLabel( this );
513 myNbQuadQuad = new QLabel( this );
515 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYGONES")), this );
516 myNbPolyg = new QLabel( this );
517 new QLabel("",this );
518 new QLabel("", this );
523 (new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this))->setFont( bold );
524 myNbVolum = new QLabel( this );
525 myNbLinVolum = new QLabel( this );
526 myNbQuadVolum = new QLabel( this );
528 new QLabel(COLONIZE(tr("SMESH_MESHINFO_TETRAS")), this );
529 myNbTetra = new QLabel( this );
530 myNbLinTetra = new QLabel( this );
531 myNbQuadTetra = new QLabel( this );
533 new QLabel(COLONIZE(tr("SMESH_MESHINFO_HEXAS")), this );
534 myNbHexa = new QLabel( this );
535 myNbLinHexa = new QLabel( this );
536 myNbQuadHexa = new QLabel( this );
538 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PYRAS")), this );
539 myNbPyra = new QLabel( this );
540 myNbLinPyra = new QLabel( this );
541 myNbQuadPyra = new QLabel( this );
543 new QLabel(COLONIZE(tr("SMESH_MESHINFO_PRISMS")), this );
544 myNbPrism = new QLabel( this );
545 myNbLinPrism = new QLabel( this );
546 myNbQuadPrism = new QLabel( this );
548 new QLabel(COLONIZE(tr("SMESH_MESHINFO_POLYEDRES")), this );
549 myNbPolyh = new QLabel( this );
550 new QLabel("", this );
551 new QLabel("", this );
556 new QLabel(COLONIZE(tr("SMESH_MESHINFO_NODES")), this );
557 myNbNode = new QLabel( this );
562 new QLabel(COLONIZE(tr("SMESH_MESHINFO_EDGES")), this );
563 myNbEdge = new QLabel( this );
564 myNbLinEdge = new QLabel( this );
565 myNbQuadEdge = new QLabel( this );
568 new QLabel(COLONIZE(tr("SMESH_MESHINFO_FACES")), this);
569 myNbFace = new QLabel( this );
570 myNbLinFace = new QLabel( this );
571 myNbQuadFace = new QLabel( this );
574 new QLabel(COLONIZE(tr("SMESH_MESHINFO_VOLUMES")), this);
575 myNbVolum = new QLabel( this );
576 myNbLinVolum = new QLabel( this );
577 myNbQuadVolum = new QLabel( this );
581 // =========================================================================================
583 * \brief Set mesh info
585 // =========================================================================================
587 void SMESHGUI_MeshInfosBox::SetInfoByMesh(SMESH::SMESH_Mesh_var mesh)
589 const SMESH::ElementOrder lin = SMESH::ORDER_LINEAR;
593 myNbNode ->setText( QString("%1").arg( mesh->NbNodes() ));
596 nbTot = mesh->NbEdges(), nbLin = mesh->NbEdgesOfOrder(lin);
597 myNbEdge ->setText( QString("%1").arg( nbTot ));
598 myNbLinEdge ->setText( QString("%1").arg( nbLin ));
599 myNbQuadEdge ->setText( QString("%1").arg( nbTot - nbLin ));
602 nbTot = mesh->NbFaces(), nbLin = mesh->NbFacesOfOrder(lin);
603 myNbFace ->setText( QString("%1").arg( nbTot ));
604 myNbLinFace ->setText( QString("%1").arg( nbLin ));
605 myNbQuadFace ->setText( QString("%1").arg( nbTot - nbLin ));
608 nbTot = mesh->NbVolumes(), nbLin = mesh->NbVolumesOfOrder(lin);
609 myNbVolum ->setText( QString("%1").arg( nbTot ));
610 myNbLinVolum ->setText( QString("%1").arg( nbLin ));
611 myNbQuadVolum->setText( QString("%1").arg( nbTot - nbLin ));
616 nbTot = mesh->NbTriangles(), nbLin = mesh->NbTrianglesOfOrder(lin);
617 myNbTrai ->setText( QString("%1").arg( nbTot ));
618 myNbLinTrai ->setText( QString("%1").arg( nbLin ));
619 myNbQuadTrai ->setText( QString("%1").arg( nbTot - nbLin ));
621 nbTot = mesh->NbQuadrangles(), nbLin = mesh->NbQuadranglesOfOrder(lin);
622 myNbQuad ->setText( QString("%1").arg( nbTot ));
623 myNbLinQuad ->setText( QString("%1").arg( nbLin ));
624 myNbQuadQuad ->setText( QString("%1").arg( nbTot - nbLin ));
626 myNbPolyg ->setText( QString("%1").arg( mesh->NbPolygons() ));
629 nbTot = mesh->NbTetras(), nbLin = mesh->NbTetrasOfOrder(lin);
630 myNbTetra ->setText( QString("%1").arg( nbTot ));
631 myNbLinTetra ->setText( QString("%1").arg( nbLin ));
632 myNbQuadTetra->setText( QString("%1").arg( nbTot - nbLin ));
634 nbTot = mesh->NbHexas(), nbLin = mesh->NbHexasOfOrder(lin);
635 myNbHexa ->setText( QString("%1").arg( nbTot ));
636 myNbLinHexa ->setText( QString("%1").arg( nbLin ));
637 myNbQuadHexa ->setText( QString("%1").arg( nbTot - nbLin ));
639 nbTot = mesh->NbPyramids(), nbLin = mesh->NbPyramidsOfOrder(lin);
640 myNbPyra ->setText( QString("%1").arg( nbTot ));
641 myNbLinPyra ->setText( QString("%1").arg( nbLin ));
642 myNbQuadPyra ->setText( QString("%1").arg( nbTot - nbLin ));
644 nbTot = mesh->NbPrisms(), nbLin = mesh->NbPrismsOfOrder(lin);
645 myNbPrism ->setText( QString("%1").arg( nbTot ));
646 myNbLinPrism ->setText( QString("%1").arg( nbLin ));
647 myNbQuadPrism->setText( QString("%1").arg( nbTot - nbLin ));
649 myNbPolyh ->setText( QString("%1").arg( mesh->NbPolyhedrons() ));
653 // =========================================================================================
655 * \brief Dialog to compute a mesh and show computation errors
657 //=======================================================================
659 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, Close/* | Help*/ )
661 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
663 QFrame* aMainFrame = createMainFrame (mainFrame());
665 aDlgLay->addWidget(aMainFrame);
667 aDlgLay->setStretchFactor(aMainFrame, 1);
670 //=======================================================================
671 // function : createMainFrame()
672 // purpose : Create frame containing dialog's fields
673 //=======================================================================
675 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
677 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
679 QFrame* aFrame = new QFrame(theParent);
681 SUIT_ResourceMgr* rm = resourceMgr();
682 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
686 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
687 aPixGrp->setExclusive(TRUE);
688 QRadioButton* aRBut = new QRadioButton(aPixGrp);
689 aRBut->setPixmap(iconCompute);
690 aRBut->setChecked(TRUE);
694 QHGroupBox* nameBox = new QHGroupBox(tr("SMESH_MESHINFO_NAME"), aFrame );
695 myMeshName = new QLabel(nameBox);
699 myBriefInfo = new SMESHGUI_MeshInfosBox(false, aFrame);
700 myFullInfo = new SMESHGUI_MeshInfosBox(true, aFrame);
702 // Computation errors
704 myCompErrorGroup = new QGroupBox(tr("ERRORS"), aFrame, "myCompErrorGroup");
705 myTable = new QTable( 1, NB_COLUMNS, myCompErrorGroup, "myTable");
706 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), myCompErrorGroup, "myShowBtn");
707 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), myCompErrorGroup, "myPublishBtn");
708 myBadMeshBtn = new QPushButton(tr("SHOW_BAD_MESH"), myCompErrorGroup, "myBadMeshBtn");
710 myTable->setReadOnly( TRUE );
711 myTable->hideColumn( COL_PUBLISHED );
712 myTable->hideColumn( COL_SHAPEID );
713 myTable->hideColumn( COL_BAD_MESH );
714 myTable->setColumnStretchable( COL_ERROR, 1 );
715 for ( int col = 0; col < NB_COLUMNS; ++col ) {
718 CASE2HEADER( COL_ALGO );
719 CASE2HEADER( COL_SHAPE );
720 CASE2HEADER( COL_ERROR );
721 CASE2HEADER( COL_SHAPEID );
722 CASE2HEADER( COL_PUBLISHED);
724 myTable->horizontalHeader()->setLabel( col, header );
727 myCompErrorGroup->setColumnLayout(0, Qt::Vertical);
728 myCompErrorGroup->layout()->setSpacing(0);
729 myCompErrorGroup->layout()->setMargin(0);
730 QGridLayout* grpLayout = new QGridLayout(myCompErrorGroup->layout());
731 grpLayout->setAlignment(Qt::AlignTop);
732 grpLayout->setSpacing(SPACING);
733 grpLayout->setMargin(MARGIN);
734 grpLayout->addMultiCellWidget( myTable, 0, 3, 0, 0 );
735 grpLayout->addWidget ( myShowBtn, 0, 1 );
736 grpLayout->addWidget ( myPublishBtn, 1, 1 );
737 grpLayout->addWidget ( myBadMeshBtn, 2, 1 );
738 grpLayout->setRowStretch( 3, 1 );
740 // Hypothesis definition errors
742 myHypErrorGroup = new QGroupBox(1,Qt::Vertical, tr("SMESH_WRN_MISSING_PARAMETERS"),aFrame);
743 myHypErrorLabel = new QLabel(myHypErrorGroup);
747 myMemoryLackGroup = new QVGroupBox(tr("ERRORS"), aFrame, "memlackGrBox");
748 QLabel* memLackLabel = new QLabel(tr("MEMORY_LACK"), myMemoryLackGroup);
749 QFont bold = memLackLabel->font(); bold.setBold(true);
750 memLackLabel->setFont( bold );
751 memLackLabel->setMinimumWidth(300);
753 // add all widgets to aFrame
754 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
755 aLay->addWidget( aPixGrp );
756 aLay->addWidget( nameBox );
757 aLay->addWidget( myBriefInfo );
758 aLay->addWidget( myFullInfo );
759 aLay->addWidget( myHypErrorGroup );
760 aLay->addWidget( myCompErrorGroup );
761 aLay->addWidget( myMemoryLackGroup );
762 aLay->setStretchFactor( myCompErrorGroup, 1 );
764 ((QPushButton*) button( OK ))->setDefault( true );
769 //================================================================================
773 //================================================================================
775 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
777 myDlg = new SMESHGUI_ComputeDlg;
778 myTShapeDisplayer = new TShapeDisplayer();
779 myBadMeshDisplayer = 0;
781 //myHelpFileName = "/files/about_meshes.htm"; // V3
782 myHelpFileName = "about_meshes_page.html"; // V4
784 // connect signals and slots
785 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
786 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
787 connect(myDlg->myBadMeshBtn, SIGNAL (clicked()), SLOT(onShowBadMesh()));
788 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
789 connect(table(),SIGNAL(currentChanged(int,int)), SLOT(currentCellChanged()));
792 //=======================================================================
793 // function : startOperation()
794 // purpose : Init dialog fields, connect signals and slots, show dialog
795 //=======================================================================
797 void SMESHGUI_ComputeOp::startOperation()
799 SMESHGUI_Operation::startOperation();
803 myMesh = SMESH::SMESH_Mesh::_nil();
804 myMainShape = GEOM::GEOM_Object::_nil();
806 LightApp_SelectionMgr *Sel = selectionMgr();
807 SALOME_ListIO selected; Sel->selectedObjects( selected );
809 int nbSel = selected.Extent();
811 SUIT_MessageBox::warn1(desktop(),
812 tr("SMESH_WRN_WARNING"),
813 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
819 Handle(SALOME_InteractiveObject) IObject = selected.First();
820 myMesh = SMESH::GetMeshByIO(IObject);
821 if (myMesh->_is_nil()) {
822 SUIT_MessageBox::warn1(desktop(),
823 tr("SMESH_WRN_WARNING"),
824 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
832 MemoryReserve aMemoryReserve;
834 SMESH::compute_error_array_var aCompErrors;
837 bool computeFailed = true, memoryLack = false;
839 _PTR(SObject) aMeshSObj = SMESH::FindSObject(myMesh);
840 myMainShape = myMesh->GetShapeToMesh();
841 bool hasShape = myMesh->HasShapeToMesh();
842 bool shapeOK = myMainShape->_is_nil() ? !hasShape : hasShape;
843 if ( shapeOK && aMeshSObj )
845 myDlg->myMeshName->setText( aMeshSObj->GetName() );
846 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
847 SMESH::algo_error_array_var errors = gen->GetAlgoState(myMesh,myMainShape);
848 if ( errors->length() > 0 ) {
849 aHypErrors = SMESH::GetMessageOnAlgoStateErrors( errors.in() );
851 SUIT_OverrideCursor aWaitCursor;
853 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
856 if (gen->Compute(myMesh, myMainShape))
857 computeFailed = false;
859 catch(const SALOME::SALOME_Exception & S_ex){
863 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
866 aCompErrors = gen->GetComputeErrors( myMesh, myMainShape );
867 // check if there are memory problems
868 for ( int i = 0; (i < aCompErrors->length()) && !memoryLack; ++i )
869 memoryLack = ( aCompErrors[ i ].code == SMESH::COMPERR_MEMORY_PB );
871 catch(const SALOME::SALOME_Exception & S_ex){
875 // NPAL16631: if ( !memoryLack )
877 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, myMesh->NbNodes() == 0);
878 update( UF_ObjBrowser | UF_Model );
881 // NPAL16631: if ( getSMESHGUI()->automaticUpdate() )
882 if ( !memoryLack && getSMESHGUI()->automaticUpdate() )
885 #if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100
888 SMESH::Update(IObject, true);
892 MESSAGE ( "Exception thrown during mesh visualization" );
894 if ( SMDS_Mesh::CheckMemory(true) ) { // has memory to show warning?
895 SMESH::OnVisuException();
902 Sel->setSelectedObjects( selected );
907 aMemoryReserve.release();
909 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
910 myDlg->myMemoryLackGroup->hide();
914 bool noCompError = ( !aCompErrors.operator->() || aCompErrors->length() == 0 );
915 bool noHypoError = ( aHypErrors.isEmpty() );
919 myDlg->myMemoryLackGroup->show();
920 myDlg->myFullInfo->hide();
921 myDlg->myBriefInfo->hide();
922 myDlg->myHypErrorGroup->hide();
923 myDlg->myCompErrorGroup->hide();
925 else if ( noCompError && noHypoError )
927 myDlg->myFullInfo->SetInfoByMesh( myMesh );
928 myDlg->myFullInfo->show();
929 myDlg->myBriefInfo->hide();
930 myDlg->myHypErrorGroup->hide();
931 myDlg->myCompErrorGroup->hide();
935 QTable* tbl = myDlg->myTable;
936 myDlg->myBriefInfo->SetInfoByMesh( myMesh );
937 myDlg->myBriefInfo->show();
938 myDlg->myFullInfo->hide();
941 myDlg->myHypErrorGroup->hide();
944 myDlg->myHypErrorGroup->show();
945 myDlg->myHypErrorLabel->setText( aHypErrors );
949 myDlg->myCompErrorGroup->hide();
952 myDlg->myCompErrorGroup->show();
955 myDlg->myPublishBtn->hide();
956 myDlg->myShowBtn->hide();
959 myDlg->myPublishBtn->show();
960 myDlg->myShowBtn->show();
963 // fill table of errors
964 tbl->setNumRows( aCompErrors->length() );
965 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
966 else tbl->showColumn( COL_SHAPE );
967 tbl->setColumnWidth( COL_ERROR, 200 );
969 bool hasBadMesh = false;
970 for ( int row = 0; row < aCompErrors->length(); ++row )
972 SMESH::ComputeError & err = aCompErrors[ row ];
973 tbl->setText( row, COL_ALGO, err.algoName.in() );
974 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
975 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
977 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
978 tbl->setText( row, COL_SHAPE, text );
980 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
981 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
983 text = err.hasBadMesh ? "hasBadMesh" : "";
984 tbl->setText( row, COL_BAD_MESH, text );
985 if ( err.hasBadMesh ) hasBadMesh = true;
987 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
988 tbl->adjustRow( row );
990 tbl->adjustColumn( COL_ALGO );
991 tbl->adjustColumn( COL_SHAPE );
994 myDlg->myBadMeshBtn->show();
996 myDlg->myBadMeshBtn->hide();
998 tbl->setCurrentCell(0,0);
999 currentCellChanged(); // to update buttons
1005 //================================================================================
1007 * \brief Stops operation
1009 //================================================================================
1011 void SMESHGUI_ComputeOp::stopOperation()
1013 SMESHGUI_Operation::stopOperation();
1014 myTShapeDisplayer->SetVisibility( false );
1015 if ( myBadMeshDisplayer ) {
1016 myBadMeshDisplayer->SetVisibility( false );
1017 // delete it in order not to have problems at its destruction when the viewer
1018 // where it worked is dead due to e.g. study closing
1019 delete myBadMeshDisplayer;
1020 myBadMeshDisplayer = 0;
1024 //================================================================================
1026 * \brief publish selected subshape
1028 //================================================================================
1030 void SMESHGUI_ComputeOp::onPublishShape()
1032 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
1033 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
1036 list< int >::iterator row;
1037 getSelectedRows( table(), rows );
1038 for ( row = rows.begin(); row != rows.end(); ++row )
1040 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1041 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
1042 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
1044 if ( !getSubShapeSO( 1, myMainShape )) // the main shape not published
1046 QString name = GEOMBase::GetDefaultName( shapeTypeName( myMainShape, "MAIN_SHAPE" ));
1047 SALOMEDS::SObject_var so =
1048 geomGen->AddInStudy( study, myMainShape, name, GEOM::GEOM_Object::_nil());
1049 // look for myMainShape in the table
1050 for ( int r = 0, nr = table()->numRows(); r < nr; ++r ) {
1051 if ( table()->text(r, COL_SHAPEID) == "1" ) {
1052 if ( so->_is_nil() ) {
1053 table()->setText( r, COL_SHAPE, so->GetName() );
1054 table()->setText( r, COL_PUBLISHED, so->GetID() );
1059 if ( curSub == 1 ) continue;
1061 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
1062 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
1063 if ( !so->_is_nil() ) {
1064 table()->setText( *row, COL_SHAPE, so->GetName() );
1065 table()->setText( *row, COL_PUBLISHED, so->GetID() );
1069 getSMESHGUI()->getApp()->updateObjectBrowser();
1070 currentCellChanged(); // to update buttons
1073 //================================================================================
1075 * \brief show mesh elements preventing computation of a submesh of current row
1077 //================================================================================
1079 void SMESHGUI_ComputeOp::onShowBadMesh()
1081 myTShapeDisplayer->SetVisibility( false );
1083 if ( getSelectedRows( table(), rows ) == 1 ) {
1084 bool hasBadMesh = ( !table()->text(rows.front(), COL_BAD_MESH).isEmpty() );
1086 int curSub = table()->text(rows.front(), COL_SHAPEID).toInt();
1087 SMESHGUI* gui = getSMESHGUI();
1088 SMESH::SMESH_Gen_var gen = gui->GetSMESHGen();
1089 SVTK_ViewWindow* view = GetViewWindow( gui );
1090 if ( myBadMeshDisplayer ) delete myBadMeshDisplayer;
1091 myBadMeshDisplayer = new SMESHGUI_MeshEditPreview( view );
1092 SMESH::MeshPreviewStruct_var aMeshData = gen->GetBadInputElements(myMesh,curSub);
1093 vtkFloatingPointType aPointSize = SMESH::GetFloat("SMESH:node_size",3);
1094 vtkFloatingPointType aLineWidth = SMESH::GetFloat("SMESH:element_width",1);
1095 // delete property !!!!!!!!!!
1096 vtkProperty* prop = vtkProperty::New();
1097 prop->SetLineWidth( aLineWidth * 3 );
1098 prop->SetPointSize( aPointSize * 3 );
1099 prop->SetColor( 250, 0, 250 );
1100 myBadMeshDisplayer->GetActor()->SetProperty( prop );
1101 myBadMeshDisplayer->SetData( aMeshData._retn() );
1106 //================================================================================
1108 * \brief SLOT called when a selected cell in table() changed
1110 //================================================================================
1112 void SMESHGUI_ComputeOp::currentCellChanged()
1114 myTShapeDisplayer->SetVisibility( false );
1115 if ( myBadMeshDisplayer )
1116 myBadMeshDisplayer->SetVisibility( false );
1118 bool publishEnable = 0, showEnable = 0, showOnly = 1, hasBadMesh = 0;
1120 list< int >::iterator row;
1121 int nbSelected = getSelectedRows( table(), rows );
1122 for ( row = rows.begin(); row != rows.end(); ++row )
1124 bool hasData = ( !table()->text(*row, COL_SHAPE).isEmpty() );
1125 bool isPublished = ( !table()->text(*row, COL_PUBLISHED).isEmpty() );
1126 if ( hasData && !isPublished )
1127 publishEnable = true;
1129 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1130 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
1132 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1139 if ( !table()->text(*row, COL_BAD_MESH).isEmpty() )
1142 myDlg->myPublishBtn->setEnabled( publishEnable );
1143 myDlg->myShowBtn ->setEnabled( showEnable );
1144 myDlg->myBadMeshBtn->setEnabled( hasBadMesh && ( nbSelected == 1 ));
1147 //================================================================================
1149 * \brief update preview
1151 //================================================================================
1153 void SMESHGUI_ComputeOp::onPreviewShape()
1155 if ( myTShapeDisplayer )
1157 SUIT_OverrideCursor aWaitCursor;
1159 list< int >::iterator row;
1160 getSelectedRows( table(), rows );
1162 bool showOnly = true;
1163 for ( row = rows.begin(); row != rows.end(); ++row )
1165 int curSub = table()->text(*row, COL_SHAPEID).toInt();
1167 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
1171 currentCellChanged(); // to update buttons
1175 //================================================================================
1179 //================================================================================
1181 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
1183 delete myTShapeDisplayer;
1184 if ( myBadMeshDisplayer )
1185 delete myBadMeshDisplayer;
1188 //================================================================================
1190 * \brief Gets dialog of this operation
1191 * \retval LightApp_Dialog* - pointer to dialog of this operation
1193 //================================================================================
1195 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
1200 //================================================================================
1202 * \brief perform it's intention action: compute mesh
1204 //================================================================================
1206 bool SMESHGUI_ComputeOp::onApply()
1211 //================================================================================
1213 * \brief Return a table
1215 //================================================================================
1217 QTable* SMESHGUI_ComputeOp::table()
1219 return myDlg->myTable;