1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : SMESHGUI_ComputeDlg.cxx
25 // Author : Edward AGAPOV
28 #include "SMESHGUI_ComputeDlg.h"
31 #include "SMESHGUI_GEOMGenUtils.h"
32 #include "SMESHGUI_MeshUtils.h"
33 #include "SMESHGUI_Utils.h"
34 #include "SMESHGUI_VTKUtils.h"
35 #include "SMESHGUI_HypothesesUtils.h"
37 #include "SMDS_SetIterator.hxx"
40 #include "GEOM_Actor.h"
42 #include "LightApp_SelectionMgr.h"
43 #include "LightApp_UpdateFlags.h"
44 #include "SALOMEDSClient_SObject.hxx"
45 #include "SALOME_ListIO.hxx"
46 #include "SVTK_ViewWindow.h"
47 #include "SalomeApp_Tools.h"
48 #include "SalomeApp_Application.h"
49 #include "SUIT_ResourceMgr.h"
50 #include "SUIT_OverrideCursor.h"
51 #include "SUIT_MessageBox.h"
52 #include "SUIT_Desktop.h"
53 #include "SUIT_Study.h"
54 #include "OB_Browser.h"
57 #include <BRep_Tool.hxx>
59 #include <TopExp_Explorer.hxx>
60 #include <TopTools_IndexedMapOfShape.hxx>
63 #include <TopLoc_Location.hxx>
64 #include <Poly_Triangulation.hxx>
65 #include <Bnd_Box.hxx>
66 #include <BRepBndLib.hxx>
67 #include <BRepMesh_IncrementalMesh.hxx>
72 #include <qpushbutton.h>
74 #include <qbuttongroup.h>
75 #include <qradiobutton.h>
78 #include <vtkProperty.h>
81 #include <SALOMEconfig.h>
82 #include CORBA_SERVER_HEADER(SMESH_Gen)
83 #include CORBA_SERVER_HEADER(SMESH_Mesh)
92 enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, NB_COLUMNS };
94 using namespace SMESH;
98 // =========================================================================================
100 * \brief Class showing shapes without publishing
102 // =========================================================================================
104 class TShapeDisplayer
107 // -----------------------------------------------------------------------
108 TShapeDisplayer(): myViewWindow(0)
110 myProperty = vtkProperty::New();
111 myProperty->SetRepresentationToWireframe();
112 myProperty->SetColor( 250, 0, 250 );
113 myProperty->SetAmbientColor( 250, 0, 250 );
114 myProperty->SetDiffuseColor( 250, 0, 250 );
115 //myProperty->SetSpecularColor( 250, 0, 250 );
116 myProperty->SetLineWidth( 5 );
118 // -----------------------------------------------------------------------
122 myProperty->Delete();
124 // -----------------------------------------------------------------------
127 TActorIterator actorIt = actorIterator();
128 while ( actorIt.more() )
129 if (VTKViewer_Actor* anActor = actorIt.next()) {
130 myViewWindow->RemoveActor( anActor );
133 myIndexToShape.Clear();
135 myShownActors.clear();
138 // -----------------------------------------------------------------------
139 void SetVisibility (bool theVisibility)
141 TActorIterator actorIt = shownIterator();
142 while ( actorIt.more() )
143 if (VTKViewer_Actor* anActor = actorIt.next())
144 anActor->SetVisibility(theVisibility);
145 SMESH::RepaintCurrentView();
147 // -----------------------------------------------------------------------
148 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
151 if ( !aMainShape->_is_nil() )
152 mainEntry = aMainShape->GetStudyEntry();
153 return ( myMainEntry == mainEntry &&
154 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
156 // -----------------------------------------------------------------------
157 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
159 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
161 if ( !aMainShape->_is_nil() )
162 mainEntry = aMainShape->GetStudyEntry();
163 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
166 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
167 checkTriangulation( aShape );
168 TopExp::MapShapes(aShape, myIndexToShape);
169 myActors.resize( myIndexToShape.Extent(), 0 );
170 myShownActors.reserve( myIndexToShape.Extent() );
172 myMainEntry = mainEntry;
173 myViewWindow = aViewWindow;
175 if ( only ) { // hide shown actors
176 TActorIterator actorIt = shownIterator();
177 while ( actorIt.more() )
178 if (VTKViewer_Actor* anActor = actorIt.next())
179 anActor->SetVisibility(false);
180 myShownActors.clear();
182 // find actors to show
183 TopoDS_Shape aShape = myIndexToShape( subShapeID );
184 if ( !aShape.IsNull() ) {
185 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
186 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
187 //checkTriangulation( exp.Current() );
188 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
189 myShownActors.push_back( anActor );
191 if ( type == TopAbs_FACE ) {
192 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
193 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
194 if ( !BRep_Tool::Degenerated( edge ))
195 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
196 myShownActors.push_back( anActor );
200 myBuiltSubs.insert( subShapeID );
203 // -----------------------------------------------------------------------
207 typedef std::vector<GEOM_Actor*> TActorVec;
209 TActorVec myShownActors;
210 TopTools_IndexedMapOfShape myIndexToShape;
212 SVTK_ViewWindow* myViewWindow;
213 vtkProperty* myProperty;
214 std::set<int> myBuiltSubs;
216 // -----------------------------------------------------------------------
217 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
218 TActorIterator actorIterator() {
219 return TActorIterator( myActors.begin(), myActors.end() );
221 TActorIterator shownIterator() {
222 return TActorIterator( myShownActors.begin(), myShownActors.end() );
224 // -----------------------------------------------------------------------
225 GEOM_Actor* getActor(const TopoDS_Shape& shape)
227 int index = myIndexToShape.FindIndex( shape ) - 1;
228 if ( index < 0 || index >= myActors.size() )
230 GEOM_Actor* & actor = myActors[ index ];
232 actor = GEOM_Actor::New();
234 actor->setInputShape(shape,0,0);
235 //actor->SetProperty(myProperty);
236 actor->SetShadingProperty(myProperty);
237 actor->SetWireframeProperty(myProperty);
238 actor->SetPreviewProperty(myProperty);
239 actor->PickableOff();
240 // if ( shape.ShapeType() == TopAbs_EDGE )
241 // actor->SubShapeOn();
242 myViewWindow->AddActor( actor );
247 // -----------------------------------------------------------------------
248 void checkTriangulation(const TopoDS_Shape& shape)
250 TopLoc_Location aLoc;
251 Standard_Boolean alreadymesh = Standard_True;
252 TopExp_Explorer ex(shape, TopAbs_FACE);
254 for (; ex.More(); ex.Next()) {
255 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
256 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
257 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
260 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
261 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
262 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
263 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
265 if (alreadymesh) return;
266 // Compute default deflection
268 BRepBndLib::Add(shape, B);
269 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
270 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
271 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
272 BRepMesh_IncrementalMesh MESH(shape,deflection);
276 // =========================================================================================
278 * \brief Return text describing an error
280 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
281 QString errorText(int errCode, const char* comment)
285 CASE2TEXT( COMPERR_OK );
286 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
287 CASE2TEXT( COMPERR_STD_EXCEPTION );
288 CASE2TEXT( COMPERR_OCC_EXCEPTION );
289 CASE2TEXT( COMPERR_SLM_EXCEPTION );
290 CASE2TEXT( COMPERR_EXCEPTION );
291 CASE2TEXT( COMPERR_MEMORY_PB );
292 CASE2TEXT( COMPERR_BAD_SHAPE );
293 case SMESH::COMPERR_ALGO_FAILED:
294 if ( strlen(comment) == 0 )
295 text = QObject::tr("COMPERR_ALGO_FAILED");
298 text = QString("#%1").arg( -errCode );
300 if ( text.length() > 0 ) text += ". ";
301 return text + comment;
303 // -----------------------------------------------------------------------
305 * \brief Return SO of a subshape
307 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
309 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
310 if ( subShapeID == 1 || !so )
312 _PTR(ChildIterator) it;
313 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
314 it = study->NewChildIterator(so);
317 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
318 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
319 if ( !geom->_is_nil() ) {
320 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
321 if ( list->length() == 1 && list[0] == subShapeID )
328 // -----------------------------------------------------------------------
330 * \brief Return subshape by ID
332 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
334 GEOM::GEOM_Object_var aSubShape;
335 if ( subShapeID == 1 )
336 aSubShape = aMainShape;
337 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
338 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
340 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
341 return aSubShape._retn();
343 // -----------------------------------------------------------------------
345 * \brief Return shape type name
347 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
348 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
351 if ( !aShape->_is_nil() ) {
352 switch ( aShape->GetShapeType() ) {
359 CASE2NAME( COMPSOLID );
360 CASE2NAME( COMPOUND );
366 // -----------------------------------------------------------------------
368 * \brief Return text describing a subshape
370 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
373 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
374 text = aSO->GetName();
376 text = QString("#%1").arg( subShapeID );
377 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
378 if ( typeName.length() )
379 text += QString(" (%1)").arg(typeName);
386 // =========================================================================================
388 * \brief Dialog to compute a mesh and show computation errors
390 //=======================================================================
392 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, OK | Help )
394 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
396 QFrame* aMainFrame = createMainFrame (mainFrame());
398 aDlgLay->addWidget(aMainFrame);
400 aDlgLay->setStretchFactor(aMainFrame, 1);
403 //=======================================================================
404 // function : createMainFrame()
405 // purpose : Create frame containing dialog's fields
406 //=======================================================================
408 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
410 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
412 QFrame* aFrame = new QFrame(theParent);
414 SUIT_ResourceMgr* rm = resourceMgr();
415 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
419 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
420 aPixGrp->setExclusive(TRUE);
421 QRadioButton* aRBut = new QRadioButton(aPixGrp);
422 aRBut->setPixmap(iconCompute);
423 aRBut->setChecked(TRUE);
427 QGroupBox* infoGrp = new QGroupBox( 2, Qt::Horizontal,
428 tr("SMESH_MESHINFO_TITLE"), aFrame, "infoGrp" );
429 QLabel* nodeLabel = new QLabel(tr("SMESH_MESHINFO_NODES"), infoGrp );
430 myNbNodesLabel = new QLabel("0", infoGrp );
431 QLabel* edgeLabel = new QLabel(tr("SMESH_MESHINFO_EDGES"), infoGrp );
432 myNbEdgesLabel = new QLabel("0", infoGrp );
433 QLabel* faceLabel = new QLabel(tr("SMESH_MESHINFO_FACES"), infoGrp);
434 myNbFacesLabel = new QLabel("0", infoGrp );
435 QLabel* volumeLbl = new QLabel(tr("SMESH_MESHINFO_VOLUMES"), infoGrp);
436 myNbVolumLabel = new QLabel("0", infoGrp );
440 QGroupBox* errorGrp = new QGroupBox(tr("ERRORS"), aFrame, "errorGrBox");
441 myTable = new QTable( 1, NB_COLUMNS, errorGrp, "myTable");
442 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), errorGrp, "myShowBtn");
443 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), errorGrp, "myPublishBtn");
445 myTable->setReadOnly( TRUE );
446 myTable->hideColumn( COL_PUBLISHED );
447 myTable->hideColumn( COL_SHAPEID );
448 myTable->setColumnStretchable( COL_ERROR, 1 );
449 for ( int col = 0; col < NB_COLUMNS; ++col ) {
452 CASE2HEADER( COL_ALGO );
453 CASE2HEADER( COL_SHAPE );
454 CASE2HEADER( COL_ERROR );
455 CASE2HEADER( COL_SHAPEID );
456 CASE2HEADER( COL_PUBLISHED);
458 myTable->horizontalHeader()->setLabel( col, header );
461 errorGrp->setColumnLayout(0, Qt::Vertical);
462 errorGrp->layout()->setSpacing(0);
463 errorGrp->layout()->setMargin(0);
464 QGridLayout* grpLayout = new QGridLayout(errorGrp->layout());
465 grpLayout->setAlignment(Qt::AlignTop);
466 grpLayout->setSpacing(SPACING);
467 grpLayout->setMargin(MARGIN);
468 grpLayout->addMultiCellWidget( myTable, 0, 2, 0, 0 );
469 grpLayout->addWidget ( myShowBtn, 0, 1 );
470 grpLayout->addWidget ( myPublishBtn, 1, 1 );
471 grpLayout->setRowStretch( 2, 1 );
473 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
474 aLay->addWidget( aPixGrp );
475 aLay->addWidget( infoGrp );
476 aLay->addWidget( errorGrp );
477 aLay->setStretchFactor( errorGrp, 1 );
481 //================================================================================
483 * \brief Show mesh info
485 //================================================================================
487 void SMESHGUI_ComputeDlg::SetMeshInfo(int nbNodes, int nbEdges, int nbFaces, int nbVolums)
489 myNbNodesLabel->setText(QString("%1").arg(nbNodes));
490 myNbEdgesLabel->setText(QString("%1").arg(nbEdges));
491 myNbFacesLabel->setText(QString("%1").arg(nbFaces));
492 myNbVolumLabel->setText(QString("%1").arg(nbVolums));
495 //================================================================================
499 //================================================================================
501 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
503 myDlg = new SMESHGUI_ComputeDlg;
504 myTShapeDisplayer = new TShapeDisplayer();
506 // connect signals and slots
507 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
508 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
509 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
512 //=======================================================================
513 // function : startOperation()
514 // purpose : Init dialog fields, connect signals and slots, show dialog
515 //=======================================================================
517 void SMESHGUI_ComputeOp::startOperation()
519 SMESHGUI_Operation::startOperation();
521 SMESH::SMESH_Mesh_var aMesh;
522 SMESH::compute_error_array_var anErrors;
524 myMainShape = GEOM::GEOM_Object::_nil();
528 bool computeFailed = true;
529 int nbNodes = 0, nbEdges = 0, nbFaces = 0, nbVolums = 0;
531 LightApp_SelectionMgr *Sel = selectionMgr();
532 SALOME_ListIO selected; Sel->selectedObjects( selected );
534 int nbSel = selected.Extent();
536 SUIT_MessageBox::warn1(desktop(),
537 tr("SMESH_WRN_WARNING"),
538 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
544 Handle(SALOME_InteractiveObject) IObject = selected.First();
545 aMesh = SMESH::GetMeshByIO(IObject);
546 if (!aMesh->_is_nil()) {
547 myMainShape = aMesh->GetShapeToMesh();
548 if ( !myMainShape->_is_nil() ) {
549 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
550 SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
551 if ( errors->length() > 0 ) {
552 SUIT_MessageBox::warn1(desktop(), tr("SMESH_WRN_WARNING"),
553 SMESH::GetMessageOnAlgoStateErrors( errors.in() ),
559 if (gen->Compute(aMesh, myMainShape)) {
560 computeFailed = false;
563 anErrors = gen->GetComputeErrors( aMesh, myMainShape );
564 // if ( anErrors->length() == 0 ) {
565 // SUIT_MessageBox::warn1(desktop(),
566 // tr("SMESH_WRN_WARNING"),
567 // tr("SMESH_WRN_COMPUTE_FAILED"),
568 // tr("SMESH_BUT_OK"));
573 nbNodes = aMesh->NbNodes();
574 nbEdges = aMesh->NbEdges();
575 nbFaces = aMesh->NbFaces();
576 nbVolums = aMesh->NbVolumes();
577 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
578 SMESH::ModifiedMesh(aMeshSObj, true, nbNodes == 0);
580 catch(const SALOME::SALOME_Exception & S_ex){
581 SalomeApp_Tools::QtCatchCorbaException(S_ex);
583 update( UF_ObjBrowser | UF_Model );
585 if ( getSMESHGUI()->automaticUpdate() ) {
586 SVTK_ViewWindow* aVTKView = SMESH::GetViewWindow(getSMESHGUI(), true);
588 int anId = study()->id();
589 TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, IObject->getEntry());
591 aVisualObj->Update();
592 SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
594 anActor = SMESH::CreateActor(studyDS(), IObject->getEntry());
596 SMESH::DisplayActor(aVTKView, anActor); //apo
600 SMESH::RepaintCurrentView();
601 Sel->setSelectedObjects( selected );
610 myDlg->SetMeshInfo( nbNodes, nbEdges, nbFaces, nbVolums);
611 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
615 bool noError = ( !anErrors.operator->() || anErrors->length() == 0 );
617 QTable* tbl = myDlg->myTable;
625 // fill table of errors
626 tbl->setNumRows( anErrors->length() );
627 bool hasShape = aMesh->HasShapeToMesh();
628 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
629 else tbl->showColumn( COL_SHAPE );
630 tbl->setColumnWidth( COL_ERROR, 200 );
632 for ( int row = 0; row < anErrors->length(); ++row )
634 SMESH::ComputeError & err = anErrors[ row ];
635 tbl->setText( row, COL_ALGO, err.algoName.in() );
636 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
637 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
639 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
640 tbl->setText( row, COL_SHAPE, text );
642 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
643 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
645 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
646 tbl->adjustRow( row );
648 tbl->adjustColumn( COL_ALGO );
649 tbl->adjustColumn( COL_SHAPE );
651 tbl->setCurrentCell(0,0);
652 currentCellChanged(); // to update buttons
658 //================================================================================
660 * \brief Stops operation
662 //================================================================================
664 void SMESHGUI_ComputeOp::stopOperation()
666 SMESHGUI_Operation::stopOperation();
667 myTShapeDisplayer->SetVisibility( false );
670 //================================================================================
672 * \brief publish selected subshape
674 //================================================================================
676 void SMESHGUI_ComputeOp::onPublishShape()
678 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
679 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
681 int nbSel = table()->numSelections();
682 for ( int i = 0; i < nbSel; ++i ) {
683 QTableSelection selected = table()->selection(i);
684 if ( !selected.isActive() ) continue;
685 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
687 bool isPublished = ( !table()->text(row, COL_PUBLISHED).isEmpty() );
688 if ( !isPublished ) {
689 int curSub = table()->text(row, COL_SHAPEID).toInt();
690 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
691 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
693 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
694 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
695 if ( !so->_is_nil() ) {
696 table()->setText( row, COL_SHAPE, so->GetName() );
697 table()->setText( row, COL_PUBLISHED, so->GetID() );
703 getSMESHGUI()->getApp()->updateObjectBrowser();
704 currentCellChanged(); // to update buttons
707 //================================================================================
709 * \brief SLOT called when a selected cell in table() changed
711 //================================================================================
713 void SMESHGUI_ComputeOp::currentCellChanged()
715 myTShapeDisplayer->SetVisibility( false );
717 bool publishEnable = 0, showEnable = 0, showOnly = 1;
718 int nbSel = table()->numSelections();
719 for ( int i = 0; i < nbSel; ++i )
721 QTableSelection selected = table()->selection(i);
722 if ( !selected.isActive() ) continue;
723 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
725 bool hasData = ( !table()->text(row, COL_SHAPE).isEmpty() );
726 bool isPublished = ( !table()->text(row, COL_PUBLISHED).isEmpty() );
727 if ( hasData && !isPublished )
728 publishEnable = true;
730 int curSub = table()->text(row, COL_SHAPEID).toInt();
731 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
733 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
741 myDlg->myPublishBtn->setEnabled( publishEnable );
742 myDlg->myShowBtn->setEnabled( showEnable );
745 //================================================================================
747 * \brief update preview
749 //================================================================================
751 void SMESHGUI_ComputeOp::onPreviewShape()
753 if ( myTShapeDisplayer )
755 SUIT_OverrideCursor aWaitCursor;
756 bool showOnly = true;
757 int nbSel = table()->numSelections();
758 for ( int i = 0; i < nbSel; ++i )
760 QTableSelection selected = table()->selection(i);
761 if ( !selected.isActive() ) continue;
762 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
764 int curSub = table()->text(row, COL_SHAPEID).toInt();
766 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
771 currentCellChanged(); // to update buttons
775 //================================================================================
779 //================================================================================
781 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
783 if ( myTShapeDisplayer ) delete myTShapeDisplayer;
786 //================================================================================
788 * \brief Gets dialog of this operation
789 * \retval LightApp_Dialog* - pointer to dialog of this operation
791 //================================================================================
793 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
798 //================================================================================
800 * \brief perform it's intention action: compute mesh
802 //================================================================================
804 bool SMESHGUI_ComputeOp::onApply()
809 //================================================================================
811 * \brief Return a table
813 //================================================================================
815 QTable* SMESHGUI_ComputeOp::table()
817 return myDlg->myTable;