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 "SVTK_ViewModel.h"
48 #include "SalomeApp_Tools.h"
49 #include "SalomeApp_Application.h"
50 #include "SUIT_ResourceMgr.h"
51 #include "SUIT_OverrideCursor.h"
52 #include "SUIT_MessageBox.h"
53 #include "SUIT_Desktop.h"
54 #include "SUIT_Study.h"
55 #include "OB_Browser.h"
58 #include <BRep_Tool.hxx>
60 #include <TopExp_Explorer.hxx>
61 #include <TopTools_IndexedMapOfShape.hxx>
64 #include <TopLoc_Location.hxx>
65 #include <Poly_Triangulation.hxx>
66 #include <Bnd_Box.hxx>
67 #include <BRepBndLib.hxx>
68 #include <BRepMesh_IncrementalMesh.hxx>
73 #include <qpushbutton.h>
75 #include <qbuttongroup.h>
76 #include <qradiobutton.h>
79 #include <vtkProperty.h>
82 #include <SALOMEconfig.h>
83 #include CORBA_SERVER_HEADER(SMESH_Gen)
84 #include CORBA_SERVER_HEADER(SMESH_Mesh)
93 enum TCol { COL_ALGO = 0, COL_SHAPE, COL_ERROR, COL_SHAPEID, COL_PUBLISHED, NB_COLUMNS };
95 using namespace SMESH;
99 // =========================================================================================
101 * \brief Class showing shapes without publishing
103 // =========================================================================================
105 class TShapeDisplayer
108 // -----------------------------------------------------------------------
109 TShapeDisplayer(): myViewWindow(0)
111 myProperty = vtkProperty::New();
112 myProperty->SetRepresentationToWireframe();
113 myProperty->SetColor( 250, 0, 250 );
114 myProperty->SetAmbientColor( 250, 0, 250 );
115 myProperty->SetDiffuseColor( 250, 0, 250 );
116 //myProperty->SetSpecularColor( 250, 0, 250 );
117 myProperty->SetLineWidth( 5 );
119 // -----------------------------------------------------------------------
123 myProperty->Delete();
125 // -----------------------------------------------------------------------
128 if ( hasViewWindow() ) {
129 TActorIterator actorIt = actorIterator();
130 while ( actorIt.more() )
131 if (VTKViewer_Actor* anActor = actorIt.next()) {
132 myViewWindow->RemoveActor( anActor );
136 myIndexToShape.Clear();
138 myShownActors.clear();
141 // -----------------------------------------------------------------------
142 void SetVisibility (bool theVisibility)
144 TActorIterator actorIt = shownIterator();
145 while ( actorIt.more() )
146 if (VTKViewer_Actor* anActor = actorIt.next())
147 anActor->SetVisibility(theVisibility);
148 SMESH::RepaintCurrentView();
150 // -----------------------------------------------------------------------
151 bool HasReadyActorsFor (int subShapeID, GEOM::GEOM_Object_var aMainShape )
154 if ( !aMainShape->_is_nil() )
155 mainEntry = aMainShape->GetStudyEntry();
156 return ( myMainEntry == mainEntry &&
157 myBuiltSubs.find( subShapeID ) != myBuiltSubs.end() );
159 // -----------------------------------------------------------------------
160 void Show( int subShapeID, GEOM::GEOM_Object_var aMainShape, bool only = false)
162 SVTK_ViewWindow* aViewWindow = SMESH::GetViewWindow( SMESHGUI::GetSMESHGUI() );
164 if ( !aMainShape->_is_nil() )
165 mainEntry = aMainShape->GetStudyEntry();
166 if ( myMainEntry != mainEntry || aViewWindow != myViewWindow ) { // remove actors
169 if ( !aMainShape->_is_nil() && GEOMBase::GetShape(aMainShape, aShape)) {
170 checkTriangulation( aShape );
171 TopExp::MapShapes(aShape, myIndexToShape);
172 myActors.resize( myIndexToShape.Extent(), 0 );
173 myShownActors.reserve( myIndexToShape.Extent() );
175 myMainEntry = mainEntry;
176 myViewWindow = aViewWindow;
178 if ( only ) { // hide shown actors
179 TActorIterator actorIt = shownIterator();
180 while ( actorIt.more() )
181 if (VTKViewer_Actor* anActor = actorIt.next())
182 anActor->SetVisibility(false);
183 myShownActors.clear();
185 // find actors to show
186 TopoDS_Shape aShape = myIndexToShape( subShapeID );
187 if ( !aShape.IsNull() ) {
188 TopAbs_ShapeEnum type( aShape.ShapeType() >= TopAbs_WIRE ? TopAbs_EDGE : TopAbs_FACE );
189 for ( TopExp_Explorer exp( aShape, type ); exp.More(); exp.Next() ) {
190 //checkTriangulation( exp.Current() );
191 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
192 myShownActors.push_back( anActor );
194 if ( type == TopAbs_FACE ) {
195 for ( TopExp_Explorer exp( aShape, TopAbs_EDGE ); exp.More(); exp.Next() ) {
196 const TopoDS_Edge & edge = TopoDS::Edge( exp.Current() );
197 if ( !BRep_Tool::Degenerated( edge ))
198 if ( GEOM_Actor* anActor = getActor( exp.Current() ))
199 myShownActors.push_back( anActor );
203 myBuiltSubs.insert( subShapeID );
206 // -----------------------------------------------------------------------
210 typedef std::vector<GEOM_Actor*> TActorVec;
212 TActorVec myShownActors;
213 TopTools_IndexedMapOfShape myIndexToShape;
215 SVTK_ViewWindow* myViewWindow;
216 vtkProperty* myProperty;
217 std::set<int> myBuiltSubs;
219 // -----------------------------------------------------------------------
220 typedef SMDS_SetIterator< GEOM_Actor*, TActorVec::const_iterator> TActorIterator;
221 TActorIterator actorIterator() {
222 return TActorIterator( myActors.begin(), myActors.end() );
224 TActorIterator shownIterator() {
225 return TActorIterator( myShownActors.begin(), myShownActors.end() );
227 // -----------------------------------------------------------------------
228 GEOM_Actor* getActor(const TopoDS_Shape& shape)
230 int index = myIndexToShape.FindIndex( shape ) - 1;
231 if ( index < 0 || index >= myActors.size() )
233 GEOM_Actor* & actor = myActors[ index ];
235 actor = GEOM_Actor::New();
237 actor->setInputShape(shape,0,0);
238 //actor->SetProperty(myProperty);
239 actor->SetShadingProperty(myProperty);
240 actor->SetWireframeProperty(myProperty);
241 actor->SetPreviewProperty(myProperty);
242 actor->PickableOff();
243 // if ( shape.ShapeType() == TopAbs_EDGE )
244 // actor->SubShapeOn();
245 myViewWindow->AddActor( actor );
250 // -----------------------------------------------------------------------
251 void checkTriangulation(const TopoDS_Shape& shape)
253 TopLoc_Location aLoc;
254 Standard_Boolean alreadymesh = Standard_True;
255 TopExp_Explorer ex(shape, TopAbs_FACE);
257 for (; ex.More(); ex.Next()) {
258 const TopoDS_Face& aFace = TopoDS::Face(ex.Current());
259 Handle(Poly_Triangulation) aPoly = BRep_Tool::Triangulation(aFace,aLoc);
260 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
263 for (ex.Init(shape, TopAbs_EDGE); ex.More(); ex.Next()) {
264 const TopoDS_Edge& edge = TopoDS::Edge(ex.Current());
265 Handle(Poly_Polygon3D) aPoly = BRep_Tool::Polygon3D(edge, aLoc);
266 if(aPoly.IsNull()) { alreadymesh = Standard_False; break; }
268 if (alreadymesh) return;
269 // Compute default deflection
271 BRepBndLib::Add(shape, B);
272 Standard_Real aXmin, aYmin, aZmin, aXmax, aYmax, aZmax;
273 B.Get(aXmin, aYmin, aZmin, aXmax, aYmax, aZmax);
274 double deflection = Max( aXmax-aXmin , Max ( aYmax-aYmin , aZmax-aZmin)) * 0.01 *4;
275 BRepMesh_IncrementalMesh MESH(shape,deflection);
277 // -----------------------------------------------------------------------
278 bool hasViewWindow() const
280 if ( !myViewWindow ) return false;
282 if ( SalomeApp_Application* anApp = SMESHGUI::GetSMESHGUI()->getApp() )
283 return FindVtkViewWindow( anApp->getViewManager(SVTK_Viewer::Type(), false ),
289 // =========================================================================================
291 * \brief Return text describing an error
293 #define CASE2TEXT(enum) case SMESH::enum: text = QObject::tr( #enum ); break;
294 QString errorText(int errCode, const char* comment)
298 CASE2TEXT( COMPERR_OK );
299 CASE2TEXT( COMPERR_BAD_INPUT_MESH);
300 CASE2TEXT( COMPERR_STD_EXCEPTION );
301 CASE2TEXT( COMPERR_OCC_EXCEPTION );
302 CASE2TEXT( COMPERR_SLM_EXCEPTION );
303 CASE2TEXT( COMPERR_EXCEPTION );
304 CASE2TEXT( COMPERR_MEMORY_PB );
305 CASE2TEXT( COMPERR_BAD_SHAPE );
306 case SMESH::COMPERR_ALGO_FAILED:
307 if ( strlen(comment) == 0 )
308 text = QObject::tr("COMPERR_ALGO_FAILED");
311 text = QString("#%1").arg( -errCode );
313 if ( text.length() > 0 ) text += ". ";
314 return text + comment;
316 // -----------------------------------------------------------------------
318 * \brief Return SO of a subshape
320 _PTR(SObject) getSubShapeSO( int subShapeID, GEOM::GEOM_Object_var aMainShape)
322 _PTR(SObject) so = SMESH::FindSObject(aMainShape);
323 if ( subShapeID == 1 || !so )
325 _PTR(ChildIterator) it;
326 if (_PTR(Study) study = SMESH::GetActiveStudyDocument())
327 it = study->NewChildIterator(so);
330 for ( it->InitEx(true); !subSO && it->More(); it->Next() ) {
331 GEOM::GEOM_Object_var geom = SMESH::SObjectToInterface<GEOM::GEOM_Object>( it->Value() );
332 if ( !geom->_is_nil() ) {
333 GEOM::ListOfLong_var list = geom->GetSubShapeIndices();
334 if ( list->length() == 1 && list[0] == subShapeID )
341 // -----------------------------------------------------------------------
343 * \brief Return subshape by ID
345 GEOM::GEOM_Object_ptr getSubShape( int subShapeID, GEOM::GEOM_Object_var aMainShape)
347 GEOM::GEOM_Object_var aSubShape;
348 if ( subShapeID == 1 )
349 aSubShape = aMainShape;
350 else if ( _PTR(SObject) so = getSubShapeSO( subShapeID, aMainShape ))
351 aSubShape = SMESH::SObjectToInterface<GEOM::GEOM_Object>( so );
353 aSubShape = SMESH::GetSubShape( aMainShape, subShapeID );
354 return aSubShape._retn();
356 // -----------------------------------------------------------------------
358 * \brief Return shape type name
360 #define CASE2NAME(enum) case GEOM::enum: name = QObject::tr( "GEOM_" #enum ); break;
361 QString shapeTypeName(GEOM::GEOM_Object_var aShape, const char* dflt = "" )
364 if ( !aShape->_is_nil() ) {
365 switch ( aShape->GetShapeType() ) {
372 CASE2NAME( COMPSOLID );
373 CASE2NAME( COMPOUND );
379 // -----------------------------------------------------------------------
381 * \brief Return text describing a subshape
383 QString shapeText(int subShapeID, GEOM::GEOM_Object_var aMainShape )
386 if ( _PTR(SObject) aSO = getSubShapeSO( subShapeID, aMainShape ))
387 text = aSO->GetName();
389 text = QString("#%1").arg( subShapeID );
390 QString typeName = shapeTypeName( getSubShape( subShapeID, aMainShape ));
391 if ( typeName.length() )
392 text += QString(" (%1)").arg(typeName);
399 // =========================================================================================
401 * \brief Dialog to compute a mesh and show computation errors
403 //=======================================================================
405 SMESHGUI_ComputeDlg::SMESHGUI_ComputeDlg(): SMESHGUI_Dialog( 0, false, true, OK | Help )
407 QVBoxLayout* aDlgLay = new QVBoxLayout (mainFrame(), 0, SPACING);
409 QFrame* aMainFrame = createMainFrame (mainFrame());
411 aDlgLay->addWidget(aMainFrame);
413 aDlgLay->setStretchFactor(aMainFrame, 1);
416 //=======================================================================
417 // function : createMainFrame()
418 // purpose : Create frame containing dialog's fields
419 //=======================================================================
421 #define CASE2HEADER(enum) case enum: header = QObject::tr( #enum "_HEADER" ); break;
423 QFrame* SMESHGUI_ComputeDlg::createMainFrame (QWidget* theParent)
425 QFrame* aFrame = new QFrame(theParent);
427 SUIT_ResourceMgr* rm = resourceMgr();
428 QPixmap iconCompute (rm->loadPixmap("SMESH", tr("ICON_COMPUTE")));
432 QButtonGroup* aPixGrp = new QButtonGroup(1, Qt::Vertical, tr("CONSTRUCTOR"), aFrame);
433 aPixGrp->setExclusive(TRUE);
434 QRadioButton* aRBut = new QRadioButton(aPixGrp);
435 aRBut->setPixmap(iconCompute);
436 aRBut->setChecked(TRUE);
440 QGroupBox* infoGrp = new QGroupBox( 2, Qt::Horizontal,
441 tr("SMESH_MESHINFO_TITLE"), aFrame, "infoGrp" );
442 QLabel* nodeLabel = new QLabel(tr("SMESH_MESHINFO_NODES"), infoGrp );
443 myNbNodesLabel = new QLabel("0", infoGrp );
444 QLabel* edgeLabel = new QLabel(tr("SMESH_MESHINFO_EDGES"), infoGrp );
445 myNbEdgesLabel = new QLabel("0", infoGrp );
446 QLabel* faceLabel = new QLabel(tr("SMESH_MESHINFO_FACES"), infoGrp);
447 myNbFacesLabel = new QLabel("0", infoGrp );
448 QLabel* volumeLbl = new QLabel(tr("SMESH_MESHINFO_VOLUMES"), infoGrp);
449 myNbVolumLabel = new QLabel("0", infoGrp );
453 QGroupBox* errorGrp = new QGroupBox(tr("ERRORS"), aFrame, "errorGrBox");
454 myTable = new QTable( 1, NB_COLUMNS, errorGrp, "myTable");
455 myShowBtn = new QPushButton(tr("SHOW_SHAPE"), errorGrp, "myShowBtn");
456 myPublishBtn = new QPushButton(tr("PUBLISH_SHAPE"), errorGrp, "myPublishBtn");
458 myTable->setReadOnly( TRUE );
459 myTable->hideColumn( COL_PUBLISHED );
460 myTable->hideColumn( COL_SHAPEID );
461 myTable->setColumnStretchable( COL_ERROR, 1 );
462 for ( int col = 0; col < NB_COLUMNS; ++col ) {
465 CASE2HEADER( COL_ALGO );
466 CASE2HEADER( COL_SHAPE );
467 CASE2HEADER( COL_ERROR );
468 CASE2HEADER( COL_SHAPEID );
469 CASE2HEADER( COL_PUBLISHED);
471 myTable->horizontalHeader()->setLabel( col, header );
474 errorGrp->setColumnLayout(0, Qt::Vertical);
475 errorGrp->layout()->setSpacing(0);
476 errorGrp->layout()->setMargin(0);
477 QGridLayout* grpLayout = new QGridLayout(errorGrp->layout());
478 grpLayout->setAlignment(Qt::AlignTop);
479 grpLayout->setSpacing(SPACING);
480 grpLayout->setMargin(MARGIN);
481 grpLayout->addMultiCellWidget( myTable, 0, 2, 0, 0 );
482 grpLayout->addWidget ( myShowBtn, 0, 1 );
483 grpLayout->addWidget ( myPublishBtn, 1, 1 );
484 grpLayout->setRowStretch( 2, 1 );
486 QVBoxLayout* aLay = new QVBoxLayout(aFrame);
487 aLay->addWidget( aPixGrp );
488 aLay->addWidget( infoGrp );
489 aLay->addWidget( errorGrp );
490 aLay->setStretchFactor( errorGrp, 1 );
494 //================================================================================
496 * \brief Show mesh info
498 //================================================================================
500 void SMESHGUI_ComputeDlg::SetMeshInfo(int nbNodes, int nbEdges, int nbFaces, int nbVolums)
502 myNbNodesLabel->setText(QString("%1").arg(nbNodes));
503 myNbEdgesLabel->setText(QString("%1").arg(nbEdges));
504 myNbFacesLabel->setText(QString("%1").arg(nbFaces));
505 myNbVolumLabel->setText(QString("%1").arg(nbVolums));
508 //================================================================================
512 //================================================================================
514 SMESHGUI_ComputeOp::SMESHGUI_ComputeOp()
516 myDlg = new SMESHGUI_ComputeDlg;
517 myTShapeDisplayer = new TShapeDisplayer();
519 // connect signals and slots
520 connect(myDlg->myShowBtn, SIGNAL (clicked()), SLOT(onPreviewShape()));
521 connect(myDlg->myPublishBtn, SIGNAL (clicked()), SLOT(onPublishShape()));
522 connect(table(),SIGNAL(selectionChanged()), SLOT(currentCellChanged()));
525 //=======================================================================
526 // function : startOperation()
527 // purpose : Init dialog fields, connect signals and slots, show dialog
528 //=======================================================================
530 void SMESHGUI_ComputeOp::startOperation()
532 SMESHGUI_Operation::startOperation();
534 SMESH::SMESH_Mesh_var aMesh;
535 SMESH::compute_error_array_var anErrors;
537 myMainShape = GEOM::GEOM_Object::_nil();
541 bool computeFailed = true;
542 int nbNodes = 0, nbEdges = 0, nbFaces = 0, nbVolums = 0;
544 LightApp_SelectionMgr *Sel = selectionMgr();
545 SALOME_ListIO selected; Sel->selectedObjects( selected );
547 int nbSel = selected.Extent();
549 SUIT_MessageBox::warn1(desktop(),
550 tr("SMESH_WRN_WARNING"),
551 tr("SMESH_WRN_NO_AVAILABLE_DATA"),
557 Handle(SALOME_InteractiveObject) IObject = selected.First();
558 aMesh = SMESH::GetMeshByIO(IObject);
559 if (!aMesh->_is_nil()) {
560 myMainShape = aMesh->GetShapeToMesh();
561 if ( !myMainShape->_is_nil() ) {
562 SMESH::SMESH_Gen_var gen = getSMESHGUI()->GetSMESHGen();
563 SMESH::algo_error_array_var errors = gen->GetAlgoState(aMesh,myMainShape);
564 if ( errors->length() > 0 ) {
565 SUIT_MessageBox::warn1(desktop(), tr("SMESH_WRN_WARNING"),
566 SMESH::GetMessageOnAlgoStateErrors( errors.in() ),
572 if (gen->Compute(aMesh, myMainShape)) {
573 computeFailed = false;
576 anErrors = gen->GetComputeErrors( aMesh, myMainShape );
577 // if ( anErrors->length() == 0 ) {
578 // SUIT_MessageBox::warn1(desktop(),
579 // tr("SMESH_WRN_WARNING"),
580 // tr("SMESH_WRN_COMPUTE_FAILED"),
581 // tr("SMESH_BUT_OK"));
586 nbNodes = aMesh->NbNodes();
587 nbEdges = aMesh->NbEdges();
588 nbFaces = aMesh->NbFaces();
589 nbVolums = aMesh->NbVolumes();
590 _PTR(SObject) aMeshSObj = SMESH::FindSObject(aMesh);
591 SMESH::ModifiedMesh(aMeshSObj, !computeFailed, nbNodes == 0);
593 catch(const SALOME::SALOME_Exception & S_ex){
594 SalomeApp_Tools::QtCatchCorbaException(S_ex);
596 update( UF_ObjBrowser | UF_Model );
598 if ( getSMESHGUI()->automaticUpdate() ) {
599 SVTK_ViewWindow* aVTKView = SMESH::GetViewWindow(getSMESHGUI(), true);
601 int anId = study()->id();
602 TVisualObjPtr aVisualObj = SMESH::GetVisualObj(anId, IObject->getEntry());
604 aVisualObj->Update();
605 SMESH_Actor* anActor = SMESH::FindActorByEntry(IObject->getEntry());
607 anActor = SMESH::CreateActor(studyDS(), IObject->getEntry());
609 SMESH::DisplayActor(aVTKView, anActor); //apo
613 SMESH::RepaintCurrentView();
614 Sel->setSelectedObjects( selected );
623 myDlg->SetMeshInfo( nbNodes, nbEdges, nbFaces, nbVolums);
624 myDlg->setCaption(tr( computeFailed ? "SMESH_WRN_COMPUTE_FAILED" : "SMESH_COMPUTE_SUCCEED"));
628 bool noError = ( !anErrors.operator->() || anErrors->length() == 0 );
630 QTable* tbl = myDlg->myTable;
638 // fill table of errors
639 tbl->setNumRows( anErrors->length() );
640 bool hasShape = aMesh->HasShapeToMesh();
641 if ( !hasShape ) tbl->hideColumn( COL_SHAPE );
642 else tbl->showColumn( COL_SHAPE );
643 tbl->setColumnWidth( COL_ERROR, 200 );
645 for ( int row = 0; row < anErrors->length(); ++row )
647 SMESH::ComputeError & err = anErrors[ row ];
648 tbl->setText( row, COL_ALGO, err.algoName.in() );
649 tbl->setText( row, COL_ERROR, errorText( err.code, err.comment.in() ));
650 tbl->setText( row, COL_SHAPEID, QString("%1").arg( err.subShapeID ));
652 QString text = hasShape ? shapeText( err.subShapeID, myMainShape ) : QString("");
653 tbl->setText( row, COL_SHAPE, text );
655 text = ( !hasShape || getSubShapeSO( err.subShapeID, myMainShape )) ? "PUBLISHED" : "";
656 tbl->setText( row, COL_PUBLISHED, text ); // if text=="", "PUBLISH" button enabled
658 tbl->item( row, COL_ERROR )->setWordWrap( TRUE );
659 tbl->adjustRow( row );
661 tbl->adjustColumn( COL_ALGO );
662 tbl->adjustColumn( COL_SHAPE );
664 tbl->setCurrentCell(0,0);
665 currentCellChanged(); // to update buttons
671 //================================================================================
673 * \brief Stops operation
675 //================================================================================
677 void SMESHGUI_ComputeOp::stopOperation()
679 SMESHGUI_Operation::stopOperation();
680 myTShapeDisplayer->SetVisibility( false );
683 //================================================================================
685 * \brief publish selected subshape
687 //================================================================================
689 void SMESHGUI_ComputeOp::onPublishShape()
691 GEOM::GEOM_Gen_var geomGen = SMESH::GetGEOMGen();
692 SALOMEDS::Study_var study = SMESHGUI::GetSMESHGen()->GetCurrentStudy();
694 int nbSel = table()->numSelections();
695 for ( int i = 0; i < nbSel; ++i ) {
696 QTableSelection selected = table()->selection(i);
697 if ( !selected.isActive() ) continue;
698 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
700 bool isPublished = ( !table()->text(row, COL_PUBLISHED).isEmpty() );
701 if ( !isPublished ) {
702 int curSub = table()->text(row, COL_SHAPEID).toInt();
703 GEOM::GEOM_Object_var shape = getSubShape( curSub, myMainShape );
704 if ( !shape->_is_nil() && ! getSubShapeSO( curSub, myMainShape ))
706 QString name = GEOMBase::GetDefaultName( shapeTypeName( shape, "ERROR_SHAPE" ));
707 SALOMEDS::SObject_var so = geomGen->AddInStudy( study, shape, name, myMainShape);
708 if ( !so->_is_nil() ) {
709 table()->setText( row, COL_SHAPE, so->GetName() );
710 table()->setText( row, COL_PUBLISHED, so->GetID() );
716 getSMESHGUI()->getApp()->updateObjectBrowser();
717 currentCellChanged(); // to update buttons
720 //================================================================================
722 * \brief SLOT called when a selected cell in table() changed
724 //================================================================================
726 void SMESHGUI_ComputeOp::currentCellChanged()
728 myTShapeDisplayer->SetVisibility( false );
730 bool publishEnable = 0, showEnable = 0, showOnly = 1;
731 int nbSel = table()->numSelections();
732 for ( int i = 0; i < nbSel; ++i )
734 QTableSelection selected = table()->selection(i);
735 if ( !selected.isActive() ) continue;
736 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
738 bool hasData = ( !table()->text(row, COL_SHAPE).isEmpty() );
739 bool isPublished = ( !table()->text(row, COL_PUBLISHED).isEmpty() );
740 if ( hasData && !isPublished )
741 publishEnable = true;
743 int curSub = table()->text(row, COL_SHAPEID).toInt();
744 bool prsReady = myTShapeDisplayer->HasReadyActorsFor( curSub, myMainShape );
746 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
754 myDlg->myPublishBtn->setEnabled( publishEnable );
755 myDlg->myShowBtn->setEnabled( showEnable );
758 //================================================================================
760 * \brief update preview
762 //================================================================================
764 void SMESHGUI_ComputeOp::onPreviewShape()
766 if ( myTShapeDisplayer )
768 SUIT_OverrideCursor aWaitCursor;
769 bool showOnly = true;
770 int nbSel = table()->numSelections();
771 for ( int i = 0; i < nbSel; ++i )
773 QTableSelection selected = table()->selection(i);
774 if ( !selected.isActive() ) continue;
775 for ( int row = selected.topRow(); row <= selected.bottomRow(); ++row )
777 int curSub = table()->text(row, COL_SHAPEID).toInt();
779 myTShapeDisplayer->Show( curSub, myMainShape, showOnly );
784 currentCellChanged(); // to update buttons
788 //================================================================================
792 //================================================================================
794 SMESHGUI_ComputeOp::~SMESHGUI_ComputeOp()
796 if ( myTShapeDisplayer ) delete myTShapeDisplayer;
799 //================================================================================
801 * \brief Gets dialog of this operation
802 * \retval LightApp_Dialog* - pointer to dialog of this operation
804 //================================================================================
806 LightApp_Dialog* SMESHGUI_ComputeOp::dlg() const
811 //================================================================================
813 * \brief perform it's intention action: compute mesh
815 //================================================================================
817 bool SMESHGUI_ComputeOp::onApply()
822 //================================================================================
824 * \brief Return a table
826 //================================================================================
828 QTable* SMESHGUI_ComputeOp::table()
830 return myDlg->myTable;