3 // Created : Sun May 05 11:49:46 2002
4 // Author : Nicolas REJNERI
7 // Copyright : Open CASCADE 2002
11 #include "SMESHGUI_AddHypothesisDlg.h"
12 #include "SMESHGUI_AddAlgorithmDlg.h"
13 #include "SMESHGUI_InitMeshDlg.h"
14 #include "SMESHGUI_LocalLengthDlg.h"
15 #include "SMESHGUI_NbSegmentsDlg.h"
16 #include "SMESHGUI_AddSubMeshDlg.h"
17 #include "SMESHGUI_NodesDlg.h"
18 #include "SMESHGUI_TransparencyDlg.h"
19 #include "SMESHGUI_RemoveNodesDlg.h"
20 #include "SMESHGUI_RemoveElementsDlg.h"
21 #include "SMESHGUI_MeshInfosDlg.h"
22 #include "SMESHGUI_Preferences_ColorDlg.h"
23 #include "SMESHGUI_MaxElementAreaDlg.h"
24 #include "SMESHGUI_MaxElementVolumeDlg.h"
25 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
26 #include "SMESHGUI_EditScalarBarDlg.h"
27 #include "SMESHGUI_aParameterDlg.h"
28 #include "SMESHGUI_ComputeScalarValue.h"
29 #include "SMESHGUI_MoveNodesDlg.h"
30 #include "SMESHGUI_OrientationElementsDlg.h"
31 #include "SMESHGUI_DiagonalInversionDlg.h"
32 #include "SMESHGUI_EdgesConnectivityDlg.h"
33 #include "SMESHGUI_AddFaceDlg.h"
34 #include "SMESHGUI_AddEdgeDlg.h"
35 #include "SMESHGUI_AddVolumeDlg.h"
36 #include "SMESHGUI_EditHypothesesDlg.h"
38 #include "SMESH_Grid.h"
41 #include "Utils_ORB_INIT.hxx"
42 #include "Utils_SINGLETON.hxx"
45 #include "QAD_Tools.h"
46 #include "QAD_Config.h"
47 #include "QAD_Settings.h"
48 #include "QAD_RightFrame.h"
49 #include "QAD_MessageBox.h"
50 #include "QAD_Resource.h"
51 #include "QAD_FileDlg.h"
52 #include "SALOMEGUI_Desktop.h"
53 #include "SALOMEGUI_NameDlg.h"
55 #include "OCCViewer_ViewPort.h"
56 #include "OCCViewer_ViewPort3d.h"
57 #include "OCCViewer_Viewer3d.h"
59 #include "VTKViewer_RenderWindowInteractor.h"
60 #include "VTKViewer_ViewFrame.h"
61 //#include "QAD_ViewPort.h"
62 //#include "QAD_ViewPort3d.h"
64 #include "GEOM_Client.hxx"
65 #include "GEOM_InteractiveObject.hxx"
67 #include "SALOME_NamingService.hxx"
68 #include "SALOME_ListIteratorOfListIO.hxx"
69 #include "SALOME_InteractiveObject.hxx"
71 #include "SALOMEGUI_ImportOperation.h"
72 #include "SALOMEGUI_QtCatchCorbaException.hxx"
73 #include "utilities.h"
75 #include "SMDS_Mesh.hxx"
76 #include "SMESHDS_Document.hxx"
77 #include "Document_Reader.h"
78 #include "Document_Writer.h"
79 #include "Mesh_Reader.h"
80 #include "Mesh_Writer.h"
82 #include "DriverDAT_R_SMESHDS_Document.h"
83 #include "DriverMED_R_SMESHDS_Document.h"
84 #include "DriverUNV_R_SMESHDS_Document.h"
85 #include "DriverDAT_W_SMESHDS_Document.h"
86 #include "DriverMED_W_SMESHDS_Document.h"
87 #include "DriverUNV_W_SMESHDS_Document.h"
88 #include "DriverDAT_R_SMESHDS_Mesh.h"
89 #include "DriverMED_R_SMESHDS_Mesh.h"
90 #include "DriverUNV_R_SMESHDS_Mesh.h"
91 #include "DriverDAT_W_SMESHDS_Mesh.h"
92 #include "DriverMED_W_SMESHDS_Mesh.h"
93 #include "DriverUNV_W_SMESHDS_Mesh.h"
96 #define INCLUDE_MENUITEM_DEF
97 #include <qapplication.h>
98 #include <qlineedit.h>
99 #include <qmenudata.h>
100 #include <qmenubar.h>
101 #include <qpopupmenu.h>
104 #include <qcheckbox.h>
105 #include <qcolordialog.h>
106 #include <qmessagebox.h>
107 #include <qspinbox.h>
111 #include <qradiobutton.h>
114 #include <vtkPoints.h>
115 #include <vtkDataSetMapper.h>
116 #include <vtkPolyVertex.h>
117 #include <vtkVertex.h>
119 #include <vtkTriangle.h>
120 #include <vtkPointSet.h>
121 #include <vtkShrinkFilter.h>
122 #include <vtkMaskPoints.h>
123 #include <vtkExtractEdges.h>
124 #include <vtkFeatureEdges.h>
125 #include <vtkTubeFilter.h>
126 #include <vtkExtractEdges.h>
127 #include <vtkLegendBoxActor.h>
128 #include <vtkGlyphSource2D.h>
129 #include <vtkIdFilter.h>
130 #include <vtkLabeledDataMapper.h>
131 #include <vtkCellCenters.h>
132 #include <vtkSelectVisiblePoints.h>
134 // Open CASCADE Includes
135 #include <gp_Pnt.hxx>
136 #include <gp_Vec.hxx>
138 static GEOM_Client ShapeReader;
139 static SMESHGUI* smeshGUI = 0;
140 static CORBA::ORB_var _orb;
143 //=============================================================================
147 //=============================================================================
148 class CustomItem : public QCustomMenuItem
151 CustomItem( const QString& s, const QFont& f )
152 : string( s ), font( f ){};
155 void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
158 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
163 return QFontMetrics( font ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
170 //=============================================================================
174 //=============================================================================
175 SMESHGUI::SMESHGUI() :
180 //=============================================================================
184 //=============================================================================
185 SMESHGUI::~SMESHGUI()
190 //=============================================================================
194 //=============================================================================
195 SMESHGUI* SMESHGUI::GetSMESHGUI( )
200 //=============================================================================
204 //=============================================================================
205 SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
207 if( smeshGUI == 0 ) {
209 smeshGUI = new SMESHGUI;
210 smeshGUI->myActiveDialogBox = 0 ;
211 smeshGUI->myState = -1 ;
212 smeshGUI->myDesktop = desktop ;
213 smeshGUI->myActiveStudy = desktop->getActiveStudy();
215 Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
216 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
218 Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");
219 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
221 /* GetCurrentStudy */
222 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
224 smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
225 // smeshGUI->myComponentGeom->NbLabels();
227 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
229 smeshGUI->myStudyAPI = SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
231 smeshGUI->myDocument = new SMESHDS_Document(1);//NBU
233 smeshGUI->mySimulationActors = vtkActorCollection::New();
234 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
236 /* study may have changed */
237 smeshGUI->myActiveStudy = desktop->getActiveStudy();
238 smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
241 /* Automatic Update */
242 if ( desktop->menuBar()->isItemChecked(1001) )
243 smeshGUI->myAutomaticUpdate = true;
245 smeshGUI->myAutomaticUpdate = false;
250 //=============================================================================
254 //=============================================================================
255 void SMESHGUI::SetState(int aState )
256 { this->myState = aState ; return ; }
259 //=============================================================================
263 //=============================================================================
264 void SMESHGUI::ResetState()
265 { this->myState = -1 ; return ; }
268 //=============================================================================
272 //=============================================================================
273 void SMESHGUI::EmitSignalDeactivateDialog()
275 emit this->SignalDeactivateActiveDialog() ;
279 //=============================================================================
283 //=============================================================================
284 void SMESHGUI::EmitSignalCloseAllDialogs()
286 emit this->SignalCloseAllDialogs() ;
291 //=============================================================================
295 //=============================================================================
296 QDialog* SMESHGUI::GetActiveDialogBox()
298 return this->myActiveDialogBox ;
301 //=============================================================================
305 //=============================================================================
306 void SMESHGUI::SetActiveDialogBox(QDialog* aDlg)
308 this->myActiveDialogBox = (QDialog*)aDlg ;
313 //=============================================================================
317 //=============================================================================
318 QAD_Study* SMESHGUI::GetActiveStudy()
320 return this->myActiveStudy ;
324 //=============================================================================
328 //=============================================================================
329 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
331 return SALOMEDS::Study::_narrow( myStudy );
334 //=============================================================================
338 //=============================================================================
339 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
344 //=============================================================================
348 //=============================================================================
349 QAD_Desktop* SMESHGUI::GetDesktop()
351 return this->myDesktop ;
354 //=============================================================================
358 //=============================================================================
359 vtkScalarBarActor* SMESHGUI::GetScalarBar()
361 vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
362 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
363 actor2DList->InitTraversal();
364 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
365 while (aActor2d != NULL) {
366 if (aActor2d->IsA("vtkScalarBarActor"))
367 return vtkScalarBarActor::SafeDownCast(aActor2d);
368 actor2DList->GetNextActor2D();
373 //=============================================================================
377 //=============================================================================
378 void SMESHGUI::activeStudyChanged( QAD_Desktop* parent )
380 MESSAGE ("SMESHGUI::activeStudyChanged init.")
381 /* Create or retrieve an object SMESHGUI */
382 SMESHGUI::GetOrCreateSMESHGUI(parent);
384 smeshGUI->EmitSignalCloseAllDialogs() ;
385 MESSAGE( "Active study changed : SMESHGUI nullified" << endl ) ;
389 //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
390 MESSAGE ("SMESHGUI::activeStudyChanged done.")
394 //=============================================================================
398 //=============================================================================
399 bool SMESHGUI::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
401 /* Here the position is on the bottom right corner - 10 */
402 QAD_Desktop* PP = QAD_Application::getDesktop() ;
403 x = abs ( PP->x() + PP->size().width() - aDlg->size().width() - 10 ) ;
404 y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ;
409 //=============================================================================
413 //=============================================================================
414 void SMESHGUI::EraseSimulationActors()
416 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
417 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
418 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
420 if ( mySimulationActors != NULL ) {
422 mySimulationActors->InitTraversal();
423 vtkActor *ac = mySimulationActors->GetNextActor();
425 theRenderer->RemoveActor(ac);
426 ac = mySimulationActors->GetNextActor();
428 mySimulationActors->RemoveAllItems();
430 if ( mySimulationActors2D != NULL ) {
431 mySimulationActors2D->InitTraversal();
432 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
434 theRenderer->RemoveActor2D(ac);
435 ac = mySimulationActors2D->GetNextActor2D();
437 mySimulationActors2D->RemoveAllItems();
443 //=============================================================================
447 //=============================================================================
448 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
451 if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
452 SMESH::SMESH_Mesh_var aMesh = myComponentMesh->Init( myComponentGeom, myStudyId, aShape);
454 if ( !aMesh->_is_nil() ) {
455 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh ( aMesh );
456 myStudyAPI.SetName( SM, NameMesh );
458 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
459 // not after loading from file, so let's use more reliable way to retrieve SObject
460 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
461 SALOMEDS::SObject_var SObject = myStudy->FindObjectIOR(ShapeIOR);
462 if ( !SObject->_is_nil() && !SM->_is_nil() ) {
463 myStudyAPI.SetShape( SM, SObject );
465 return SMESH::SMESH_Mesh::_narrow(aMesh);
469 catch (const SALOME::SALOME_Exception& S_ex) {
470 QtCatchCorbaException(S_ex);
472 myActiveStudy->updateObjBrowser(true);
473 return SMESH::SMESH_Mesh::_nil();
476 //=============================================================================
480 //=============================================================================
481 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh, GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
484 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
485 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
486 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
487 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
489 if ( !SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() && !aSubMesh->_is_nil() && !aMesh->_is_nil() ) {
490 SALOMEDS::SObject_var SO = myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh, aShape->ShapeType() );
491 myStudyAPI.SetName(SO, NameMesh);
493 SMESH_Actor* amesh = SMESH_Actor::New();
494 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(SO->GetID(),
498 amesh->setName( strdup(NameMesh) );
499 DisplayActor(amesh, false);
500 return SMESH::SMESH_subMesh::_narrow( aSubMesh );
503 catch (const SALOME::SALOME_Exception& S_ex) {
504 QtCatchCorbaException(S_ex);
506 myActiveStudy->updateObjBrowser(true);
507 return SMESH::SMESH_subMesh::_nil();
511 //=============================================================================
515 //=============================================================================
516 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis( QString TypeHypothesis,
517 QString NameHypothesis )
519 SMESH::SMESH_Hypothesis_var Hyp;
521 Hyp = myComponentMesh->CreateHypothesis( TypeHypothesis, myStudyId );
522 if ( !Hyp->_is_nil() ) {
523 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis( Hyp );
524 myStudyAPI.SetName( SHyp, NameHypothesis);
527 catch (const SALOME::SALOME_Exception& S_ex) {
528 QtCatchCorbaException(S_ex);
531 return SMESH::SMESH_Hypothesis::_narrow( Hyp );
534 //=============================================================================
538 //=============================================================================
539 void SMESHGUI::AddHypothesisOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
541 if ( !aMesh->_is_nil() ) {
542 QApplication::setOverrideCursor( Qt::waitCursor );
543 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
544 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
546 bool res = aMesh->AddHypothesis( aShape, aHyp );
548 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
549 if ( !SM->_is_nil() && !SH->_is_nil() ) {
550 myStudyAPI.SetHypothesis( SM, SH );
551 myStudyAPI.ModifiedMesh( SM, false );
553 QApplication::restoreOverrideCursor();
555 QApplication::restoreOverrideCursor();
556 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
557 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
560 catch (const SALOME::SALOME_Exception& S_ex) {
561 QtCatchCorbaException(S_ex);
564 myActiveStudy->updateObjBrowser(true);
565 QApplication::restoreOverrideCursor();
568 //=============================================================================
572 //=============================================================================
573 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( const Handle(SALOME_InteractiveObject)& IObject )
575 if ( IObject->hasReference() ) {
576 SMESH::SMESH_Hypothesis_var anHyp;
577 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getEntry() );
578 SALOMEDS::GenericAttribute_var anAttr;
579 SALOMEDS::AttributeIOR_var anIOR;
581 if ( !SO_Hypothesis->_is_nil() ) {
582 QApplication::setOverrideCursor( Qt::waitCursor );
583 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
584 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
585 anHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()) );
588 SALOMEDS::SObject_var SO_Applied_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getReference());
589 if ( !SO_Applied_Hypothesis->_is_nil() ) {
590 SALOMEDS::SObject_var MorSM = smeshGUI->myStudyAPI.GetMeshOrSubmesh( SO_Applied_Hypothesis );
591 if ( !MorSM->_is_nil() ) {
592 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
594 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
595 if ( !aShape->_is_nil() ) {
596 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
597 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
598 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
599 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
600 if ( !aMesh->_is_nil() ) {
601 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
603 QApplication::restoreOverrideCursor();
604 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
605 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
607 } else if ( !aSubMesh->_is_nil() ) {
608 aMesh = aSubMesh->GetFather();
609 if ( !aMesh->_is_nil() ) {
610 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
612 QApplication::restoreOverrideCursor();
613 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
614 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
618 if ( myAutomaticUpdate ) {
619 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
620 if ( Mesh != NULL ) {
624 DisplayActor( Mesh );
625 DisplayEdges( Mesh );
626 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
632 smeshGUI->myStudyAPI.UnSetHypothesis( SO_Applied_Hypothesis );
635 } else if ( IObject->hasEntry() ) {
636 MESSAGE ( "IObject entry " << IObject->getEntry() )
638 QApplication::restoreOverrideCursor();
641 //=============================================================================
645 //=============================================================================
646 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( SALOMEDS::SObject_ptr MorSM, SMESH::SMESH_Hypothesis_ptr anHyp )
648 SALOMEDS::SObject_var AHR, aRef;
649 SALOMEDS::GenericAttribute_var anAttr;
650 SALOMEDS::AttributeIOR_var anIOR;
652 if ( !MorSM->_is_nil() ) {
653 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
654 if ( !aShape->_is_nil() ) {
655 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
656 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
657 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
658 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
659 if ( !aMesh->_is_nil() ) {
660 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
662 QApplication::restoreOverrideCursor();
663 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
664 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
666 } else if ( !aSubMesh->_is_nil() ) {
667 aMesh = aSubMesh->GetFather();
668 if ( !aMesh->_is_nil() ) {
669 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
671 QApplication::restoreOverrideCursor();
672 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
673 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
677 if ( myAutomaticUpdate ) {
678 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
679 if ( Mesh != NULL ) {
683 DisplayActor( Mesh );
684 DisplayEdges( Mesh );
685 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
691 if ( MorSM->FindSubObject (2, AHR)) {
692 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
693 for (; it->More();it->Next()) {
694 SALOMEDS::SObject_var Obj = it->Value();
695 if ( Obj->ReferencedObject(aRef) ) {
696 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
697 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
698 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
699 smeshGUI->myStudyAPI.UnSetHypothesis( Obj );
706 if ( MorSM->FindSubObject (3, AHR)) {
707 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
708 for (; it->More();it->Next()) {
709 SALOMEDS::SObject_var Obj = it->Value();
710 if ( Obj->ReferencedObject(aRef) ) {
711 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
712 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
713 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
714 smeshGUI->myStudyAPI.UnSetAlgorithm( Obj );
721 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
723 QApplication::restoreOverrideCursor();
726 //=============================================================================
730 //=============================================================================
731 void SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
733 if ( !aMesh->_is_nil() ) {
734 QApplication::setOverrideCursor( Qt::waitCursor );
735 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
736 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
738 bool res = aMesh->AddHypothesis( aShape, aHyp );
740 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
741 if ( !SM->_is_nil() && !SH->_is_nil() ) {
742 myStudyAPI.SetAlgorithms( SM, SH );
743 myStudyAPI.ModifiedMesh( SM, false );
746 QApplication::restoreOverrideCursor();
747 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
748 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
751 catch (const SALOME::SALOME_Exception& S_ex) {
752 QtCatchCorbaException(S_ex);
755 myActiveStudy->updateObjBrowser(true);
756 QApplication::restoreOverrideCursor();
759 //=============================================================================
763 //=============================================================================
764 void SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
766 if ( !aSubMesh->_is_nil() ) {
767 QApplication::setOverrideCursor( Qt::waitCursor );
769 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
770 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
771 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
772 if ( !aMesh->_is_nil() ) {
773 bool res = aMesh->AddHypothesis( aShape, aHyp );
775 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
776 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
777 myStudyAPI.SetHypothesis( SsubM, SH );
778 myStudyAPI.ModifiedMesh( SsubM, false );
781 QApplication::restoreOverrideCursor();
782 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
783 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
787 catch (const SALOME::SALOME_Exception& S_ex) {
788 QtCatchCorbaException(S_ex);
791 myActiveStudy->updateObjBrowser(true);
792 QApplication::restoreOverrideCursor();
795 //=============================================================================
799 //=============================================================================
800 void SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
802 if ( !aSubMesh->_is_nil() ) {
803 QApplication::setOverrideCursor( Qt::waitCursor );
805 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
806 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
807 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
808 if ( !aMesh->_is_nil() ) {
809 bool res = aMesh->AddHypothesis( aShape, aHyp );
811 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
812 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
813 myStudyAPI.SetAlgorithms( SsubM, SH );
814 myStudyAPI.ModifiedMesh( SsubM, false );
817 QApplication::restoreOverrideCursor();
818 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
819 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
823 catch (const SALOME::SALOME_Exception& S_ex) {
824 QtCatchCorbaException(S_ex);
827 myActiveStudy->updateObjBrowser(true);
828 QApplication::restoreOverrideCursor();
831 //=============================================================================
835 //=============================================================================
836 void SMESHGUI::CreateAlgorithm( QString TypeAlgo, QString NameAlgo )
838 SMESH::SMESH_Hypothesis_var Hyp;
840 if ( TypeAlgo.compare("Regular_1D") == 0 )
841 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
842 else if ( TypeAlgo.compare("MEFISTO_2D") == 0 )
843 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
844 else if ( TypeAlgo.compare("Quadrangle_2D") == 0 )
845 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
846 else if ( TypeAlgo.compare("Hexa_3D") == 0 )
847 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
849 if ( !Hyp->_is_nil() ) {
850 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
851 myStudyAPI.SetName( SHyp, NameAlgo);
854 catch (const SALOME::SALOME_Exception& S_ex) {
855 QtCatchCorbaException(S_ex);
857 myActiveStudy->updateObjBrowser(true);
861 //=============================================================================
865 //=============================================================================
866 void SMESHGUI::CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length )
868 QApplication::setOverrideCursor( Qt::waitCursor );
870 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
871 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
872 if ( !LL->_is_nil() )
873 LL->SetLength( Length );
875 catch (const SALOME::SALOME_Exception& S_ex) {
876 QtCatchCorbaException(S_ex);
878 myActiveStudy->updateObjBrowser(true);
879 QApplication::restoreOverrideCursor();
882 //=============================================================================
886 //=============================================================================
887 void SMESHGUI::CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea )
889 QApplication::setOverrideCursor( Qt::waitCursor );
891 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
892 SMESH::SMESH_MaxElementArea_var MaxElArea = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
893 if ( !MaxElArea->_is_nil() )
894 MaxElArea->SetMaxElementArea( MaxArea );
896 catch (SALOME::SALOME_Exception& S_ex) {
897 QtCatchCorbaException(S_ex);
900 myActiveStudy->updateObjBrowser(true);
901 QApplication::restoreOverrideCursor();
904 //=============================================================================
908 //=============================================================================
909 void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume )
911 QApplication::setOverrideCursor( Qt::waitCursor );
913 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
914 SMESH::SMESH_MaxElementVolume_var MaxElVolume = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
915 if ( !MaxElVolume->_is_nil() )
916 MaxElVolume->SetMaxElementVolume( MaxVolume );
918 catch (const SALOME::SALOME_Exception& S_ex) {
919 QtCatchCorbaException(S_ex);
921 myActiveStudy->updateObjBrowser(true);
922 QApplication::restoreOverrideCursor();
925 //=============================================================================
929 //=============================================================================
930 void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments )
932 QApplication::setOverrideCursor( Qt::waitCursor );
934 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
935 SMESH::SMESH_NumberOfSegments_var NbS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
936 if ( !NbS->_is_nil() )
937 NbS->SetNumberOfSegments( nbSegments );
939 catch (const SALOME::SALOME_Exception& S_ex) {
940 QtCatchCorbaException(S_ex);
942 myActiveStudy->updateObjBrowser(true);
943 QApplication::restoreOverrideCursor();
946 //=============================================================================
950 //=============================================================================
951 int SMESHGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName )
953 int nbSel = Sel->IObjectCount() ;
955 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
956 aName = IObject->getName();
958 aName = tr( "SMESH_OBJECTS_SELECTED" ).arg( nbSel );
963 //=============================================================================
967 //=============================================================================
968 int SMESHGUI::GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName )
971 int nbSel = Sel->IObjectCount() ;
973 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
974 if ( !IObject->hasEntry() )
977 Standard_Boolean res;
978 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
982 TColStd_MapOfInteger MapIndex;
983 Sel->GetIndex( IObject, MapIndex );
984 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
986 nbNodes = MapIndex.Extent();
987 for ( ; ite.More(); ite.Next() ) {
988 aName = aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) + " ";
996 //=============================================================================
1000 //=============================================================================
1001 int SMESHGUI::GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName )
1004 int nbSel = Sel->IObjectCount() ;
1006 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1007 if ( !IObject->hasEntry() )
1010 Standard_Boolean res;
1011 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1015 TColStd_MapOfInteger MapIndex;
1016 Sel->GetIndex( IObject, MapIndex );
1017 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1019 nbElements = MapIndex.Extent();
1020 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1021 for ( ; ite.More(); ite.Next() ) {
1022 int idVTK = ite.Key();
1023 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1024 aName = aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1033 //=============================================================================
1037 //=============================================================================
1038 int SMESHGUI::GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName )
1041 int nbSel = Sel->IObjectCount() ;
1043 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1044 if ( !IObject->hasEntry() )
1047 Standard_Boolean res;
1048 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1052 TColStd_MapOfInteger MapIndex;
1053 Sel->GetIndex( IObject, MapIndex );
1054 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1056 nbElements = MapIndex.Extent();
1057 for ( ; ite.More(); ite.Next() ) {
1058 aName = aName + QString("%1").arg(ite.Key()) + " ";
1067 //=============================================================================
1071 //=============================================================================
1072 SMESH_Actor* SMESHGUI::FindActorByEntry(QString entry,
1073 Standard_Boolean& testResult,
1074 bool onlyInActiveView)
1076 int nbSf = myActiveStudy->getStudyFramesCount();
1077 for ( int i = 0; i < nbSf; i++ ) {
1078 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
1079 if ( sf->getTypeView() == VIEW_VTK ) {
1080 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1081 vtkActorCollection* theActors = Renderer->GetActors();
1082 theActors->InitTraversal();
1083 vtkActor *ac = theActors->GetNextActor();
1084 while(!(ac==NULL)) {
1085 if ( ac->IsA("SMESH_Actor") ) {
1086 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1087 if ( anActor->hasIO() ) {
1088 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1089 if ( strcmp( IO->getEntry(), entry ) == 0 ) {
1090 if ( onlyInActiveView ) {
1091 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
1102 ac = theActors->GetNextActor();
1107 MESSAGE ( " Actor Not Found " )
1109 return SMESH_Actor::New();
1112 //=============================================================================
1116 //=============================================================================
1117 SMESH_Actor* SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1118 Standard_Boolean& testResult,
1119 bool onlyInActiveView)
1121 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
1122 if ( SM->_is_nil() ) {
1123 MESSAGE ( " Actor Not Found " )
1126 return SMESH_Actor::New();
1129 return FindActorByEntry( SM->GetID(), testResult, onlyInActiveView);
1132 //=============================================================================
1136 //=============================================================================
1137 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO,
1138 Standard_Boolean& testResult)
1140 SMESH::SMESH_Mesh_var aMesh;
1141 testResult = false ;
1144 if ( IO->hasEntry() ) {
1145 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1146 SALOMEDS::GenericAttribute_var anAttr;
1147 SALOMEDS::AttributeIOR_var anIOR;
1148 if ( !obj->_is_nil() ) {
1149 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1150 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1151 aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1152 if ( !aMesh->_is_nil() ) {
1154 return SMESH::SMESH_Mesh::_duplicate( aMesh );
1159 return SMESH::SMESH_Mesh::_nil();
1162 //=============================================================================
1166 //=============================================================================
1167 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO,
1168 Standard_Boolean& testResult)
1170 SMESH::SMESH_subMesh_var aSubMesh;
1171 testResult = false ;
1174 if ( IO->hasEntry() ) {
1175 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1176 SALOMEDS::GenericAttribute_var anAttr;
1177 SALOMEDS::AttributeIOR_var anIOR;
1178 if ( !obj->_is_nil() ) {
1179 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1180 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1181 aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1182 if ( !aSubMesh->_is_nil() ) {
1184 return SMESH::SMESH_subMesh::_duplicate( aSubMesh );
1189 return SMESH::SMESH_subMesh::_nil();
1192 //=============================================================================
1196 //=============================================================================
1197 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO,
1198 Standard_Boolean& testResult )
1200 SMESH::SMESH_Hypothesis_var aHyp ;
1201 testResult = false ;
1204 if ( IO->hasEntry() ) {
1205 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1206 SALOMEDS::GenericAttribute_var anAttr;
1207 SALOMEDS::AttributeIOR_var anIOR;
1208 if ( !obj->_is_nil() ) {
1209 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1210 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1211 aHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()));
1212 if ( !aHyp->_is_nil() ) {
1214 return SMESH::SMESH_Hypothesis::_duplicate( aHyp );
1219 return SMESH::SMESH_Hypothesis::_nil();
1224 //=============================================================================
1228 //=============================================================================
1229 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO,
1230 Standard_Boolean& testResult )
1232 GEOM::GEOM_Shape_var aShape ;
1233 testResult = false ;
1236 if ( IO->hasEntry() ) {
1237 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1238 SALOMEDS::GenericAttribute_var anAttr;
1239 SALOMEDS::AttributeIOR_var anIOR;
1240 if ( !obj->_is_nil() ) {
1241 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1242 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1243 aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
1244 if ( !aShape->_is_nil() ) {
1246 return GEOM::GEOM_Shape::_duplicate( aShape );
1251 return GEOM::GEOM_Shape::_nil();
1255 //=============================================================================
1259 //=============================================================================
1260 void SMESHGUI::SetViewMode(int commandId)
1262 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1263 int nbSel = Sel->IObjectCount();
1265 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1266 for ( ; It.More(); It.Next() ) {
1267 Handle(SALOME_InteractiveObject) IObject = It.Value();
1268 if ( IObject->hasEntry() ) {
1269 Standard_Boolean res;
1270 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1272 switch (commandId) {
1274 ChangeRepresentation( ac, 0 );
1278 ChangeRepresentation( ac, 1 );
1282 ChangeRepresentation( ac, 2 );
1286 ChangeRepresentation( ac, 3 );
1293 if ( commandId == 1133 ) {
1294 ChangeRepresentation( SMESH_Actor::New(), 4 );
1299 //=============================================================================
1303 //=============================================================================
1304 void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
1306 if (ac->DataSource == NULL && type != 4 )
1310 if ( ac->getMapper() == NULL ) {
1316 QApplication::setOverrideCursor( Qt::waitCursor );
1317 if (ac->getDisplayMode()==2) {
1318 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1319 meshMapper->SetInput(ac->DataSource);
1321 ac->setDisplayMode(0);
1322 ac->GetProperty()->SetRepresentationToWireframe();
1323 // ac->SetActorProperty( ac->GetProperty() );
1324 QApplication::restoreOverrideCursor();
1328 QApplication::setOverrideCursor( Qt::waitCursor );
1329 if (ac->getDisplayMode()==2) {
1330 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1331 meshMapper->SetInput(ac->DataSource);
1333 ac->setDisplayMode(1);
1334 ac->GetProperty()->SetRepresentationToSurface();
1335 QApplication::restoreOverrideCursor();
1336 // ac->SetActorProperty( ac->GetProperty() );
1340 // if (!(ac->getDisplayMode()==2)) {
1341 // ChangeRepresentation(ac, 1);
1342 QApplication::setOverrideCursor( Qt::waitCursor );
1343 ac->setDisplayMode(2);
1344 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1345 meshMapper->SetInput(ac->DataSource);
1346 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1347 shrink->SetInput(meshMapper->GetInput());
1348 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1350 meshMapper->SetInput( shrink->GetOutput() );
1351 ac->SetMapper( meshMapper );
1352 QApplication::restoreOverrideCursor();
1360 float backfacecolor[3];
1362 ac->GetColor(color[0],color[1],color[2]);
1363 QColor c(color[0]*255,color[1]*255,color[2]*255);
1364 ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
1365 QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1366 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1367 QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1368 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
1369 QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1371 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1372 if ( Edgewidth == 0 )
1374 int intValue = ac->GetNodeSize() ;
1375 float Shrink = ac->GetShrinkFactor();
1377 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "" ) ;
1378 aDlg->SetColor(1,c);
1379 aDlg->SetColor(2,e);
1380 aDlg->SetColor(3,n);
1381 aDlg->SetColor(4,b);
1382 aDlg->SetIntValue(1,Edgewidth);
1383 aDlg->SetIntValue(2,intValue);
1384 aDlg->SetIntValue(3,int(Shrink*100.));
1386 if ( aDlg->exec() ) {
1387 QApplication::setOverrideCursor( Qt::waitCursor );
1388 QColor color = aDlg->GetColor(1);
1389 QColor edgecolor = aDlg->GetColor(2);
1390 QColor nodecolor = aDlg->GetColor(3);
1391 QColor backfacecolor = aDlg->GetColor(4);
1392 /* actor color and backface color */
1393 ac->GetProperty()->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1394 ac->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1395 ac->GetBackfaceProperty()->SetColor(float(backfacecolor.red())/255.,float(backfacecolor.green())/255.,float(backfacecolor.blue())/255.);
1398 ac->EdgeDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1399 float(edgecolor.green())/255.,
1400 float(edgecolor.blue())/255.);
1401 ac->EdgeShrinkDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1402 float(edgecolor.green())/255.,
1403 float(edgecolor.blue())/255.);
1404 ac->SetEdgeColor(float(edgecolor.red())/255.,
1405 float(edgecolor.green())/255.,
1406 float(edgecolor.blue())/255.);
1408 /* Shrink factor and size edges */
1409 ac->SetShrinkFactor( aDlg->GetIntValue(3)/100. );
1410 ac->EdgeDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1411 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1413 /* Nodes color and size */
1414 ac->SetNodeColor(float(nodecolor.red())/255.,
1415 float(nodecolor.green())/255.,
1416 float(nodecolor.blue())/255.);
1417 ac->SetNodeSize(aDlg->GetIntValue(2)) ;
1419 if (ac->getDisplayMode()==2) {
1420 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1421 meshMapper->SetInput(ac->DataSource);
1422 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1423 shrink->SetInput(meshMapper->GetInput());
1424 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1426 meshMapper->SetInput( shrink->GetOutput() );
1427 ac->SetMapper( meshMapper );
1431 QApplication::restoreOverrideCursor();
1436 EmitSignalDeactivateDialog() ;
1437 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1438 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg( QAD_Application::getDesktop(), "", Sel) ;
1442 QApplication::setOverrideCursor( Qt::waitCursor );
1443 ac->GetProperty()->SetRepresentationToPoints();
1444 QApplication::restoreOverrideCursor();
1449 QApplication::setOverrideCursor( Qt::waitCursor );
1450 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1451 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1452 theRenderer->Render();
1454 QApplication::restoreOverrideCursor();
1457 //=============================================================================
1461 //=============================================================================
1462 void SMESHGUI::UpdateView()
1464 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1467 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1468 theRenderer->Render();
1471 //=============================================================================
1475 //=============================================================================
1476 void SMESHGUI::DisplayActor(SMESH_Actor* ac, bool visibility)
1478 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1481 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1483 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1484 vtkActorCollection* theActors = theRenderer->GetActors();
1485 theActors->InitTraversal();
1486 if ( theActors->IsItemPresent(ac) == 0 ) {
1487 vtkProperty* prop = vtkProperty::New();
1488 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1489 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1490 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. ) ;
1492 prop->SetPointSize( QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
1493 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
1494 ac->SetProperty( prop );
1495 ac->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1496 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1497 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. );
1499 // prop->BackfaceCullingOn();
1500 vtkProperty* backprop = vtkProperty::New();
1501 backprop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed").toFloat()/255.,
1502 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").toFloat()/255.,
1503 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").toFloat()/255. ) ;
1504 ac->SetBackfaceProperty(backprop);
1506 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1509 ac->SetShrinkFactor( intValue/100. );
1511 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1512 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1514 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1515 if ( DisplayMode.compare("Wireframe") == 0 ){
1516 ac->setDisplayMode(0);
1517 ChangeRepresentation( ac, 0 );
1518 } else if ( DisplayMode.compare("Shading") == 0 ){
1519 ac->setDisplayMode(1);
1520 ChangeRepresentation( ac, 1 );
1521 } else if ( DisplayMode.compare("Shrink") == 0 ) {
1522 ac->setDisplayMode(2);
1523 ChangeRepresentation( ac, 2 );
1525 theRenderer->AddActor(ac);
1527 if (ac->GetMapper())
1528 ac->GetMapper()->Update();
1531 // if ( visibility )
1532 ac->SetVisibility(visibility);
1533 // ac->VisibilityOn();
1535 // ac->VisibilityOff();
1537 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1541 //=============================================================================
1545 //=============================================================================
1546 void SMESHGUI::EraseActor(SMESH_Actor* ac)
1548 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1551 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1553 //NRI- : 02/12/2002 : Fixed bugId 882
1554 // ac->EdgeDevice->VisibilityOff();
1555 // ac->EdgeShrinkDevice->VisibilityOff();
1556 // ac->VisibilityOff();
1557 ac->SetVisibility( false );
1559 theRenderer->Render();
1562 //=============================================================================
1566 //=============================================================================
1567 bool SMESHGUI::AddActorInSelection(SMESH_Actor* ac)
1569 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1570 Sel->ClearIObjects();
1572 return Sel->AddIObject( ac->getIO() );
1577 //=============================================================================
1581 //=============================================================================
1582 QString SMESHGUI::CheckHomogeneousSelection()
1584 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1587 SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
1588 for (; Itinit.More(); Itinit.Next()) {
1589 List.Append(Itinit.Value());
1592 QString RefType = CheckTypeObject( Sel->firstIObject() );
1593 SALOME_ListIteratorOfListIO It( List );
1594 for (; It.More(); It.Next()) {
1595 Handle(SALOME_InteractiveObject) IObject = It.Value();
1596 QString Type = CheckTypeObject( IObject );
1597 if ( Type.compare( RefType ) != 0 )
1598 return "Heterogeneous Selection";
1601 Sel->ClearIObjects();
1602 SALOME_ListIteratorOfListIO It1( List );
1603 for(;It1.More();It1.Next()) {
1604 int res = Sel->AddIObject( It1.Value() );
1606 myActiveStudy->highlight( It1.Value(), false );
1608 myActiveStudy->highlight( It1.Value(), true );
1613 //=============================================================================
1617 //=============================================================================
1618 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO)
1620 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
1621 if (!sobj->_is_nil()) {
1622 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1623 if (strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected
1628 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1629 Sel->ClearIObjects();
1631 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter( HYPOTHESIS );
1632 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter( ALGORITHM );
1633 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
1634 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
1635 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
1636 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter( SUBMESH_VERTEX );
1637 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter( SUBMESH_EDGE );
1638 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter( SUBMESH_FACE );
1639 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter( SUBMESH_SOLID );
1640 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter( SUBMESH_COMPOUND );
1642 Sel->AddFilter(aHypFilter);
1643 if ( Sel->AddIObject( IO ) != -1 ) {
1644 Sel->ClearFilters();
1645 return "Hypothesis";
1648 Sel->ClearFilters();
1649 Sel->AddFilter(anAlgoFilter);
1650 if ( Sel->AddIObject( IO ) != -1 ) {
1651 Sel->ClearFilters();
1655 Sel->ClearFilters();
1656 Sel->AddFilter(aMeshFilter);
1657 if ( Sel->AddIObject( IO ) != -1 ) {
1658 Sel->ClearFilters();
1662 Sel->ClearFilters();
1663 Sel->AddFilter(aSubMeshFilter);
1664 if ( Sel->AddIObject( IO ) != -1 ) {
1665 Sel->ClearFilters();
1669 Sel->ClearFilters();
1670 Sel->AddFilter(aSubMeshVextexFilter);
1671 if ( Sel->AddIObject( IO ) != -1 ) {
1672 Sel->ClearFilters();
1673 return "SubMeshVertex";
1676 Sel->ClearFilters();
1677 Sel->AddFilter(aSubMeshEdgeFilter);
1678 if ( Sel->AddIObject( IO ) != -1 ){
1679 Sel->ClearFilters();
1680 return "SubMeshEdge";
1683 Sel->ClearFilters();
1684 Sel->AddFilter(aSubMeshFaceFilter);
1685 if ( Sel->AddIObject( IO ) != -1 ) {
1686 Sel->ClearFilters();
1687 return "SubMeshFace";
1690 Sel->ClearFilters();
1691 Sel->AddFilter(aSubMeshSolidFilter);
1692 if ( Sel->AddIObject( IO ) != -1 ) {
1693 Sel->ClearFilters();
1694 return "SubMeshSolid";
1697 Sel->ClearFilters();
1698 Sel->AddFilter(aSubMeshCompoundFilter);
1699 if ( Sel->AddIObject( IO ) != -1 ) {
1700 Sel->ClearFilters();
1701 return "SubMeshCompound";
1704 Sel->ClearFilters();
1705 Sel->AddIObject( IO );
1709 //=============================================================================
1713 //=============================================================================
1714 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1716 /* Create or retrieve an object SMESHGUI */
1717 SMESHGUI::GetOrCreateSMESHGUI(parent);
1719 // NRI : Temporary added
1720 if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
1725 // QAD_Viewer3d* v3d;
1726 OCCViewer_Viewer3d* v3d;
1728 Handle(AIS_InteractiveContext) ic;
1729 vtkRenderer* Renderer;
1730 vtkRenderWindow* RenWin;
1732 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1733 v3d =((OCCViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1734 ic = v3d->getAISContext();
1735 } else if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1736 Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1737 RenWin = Renderer->GetRenderWindow();
1740 switch (theCommandID)
1743 smeshGUI->OnEditDelete();
1750 Import_Document(parent,theCommandID);//NBU
1751 //Import_Mesh(parent,theCommandID);
1755 case 122: // EXPORT MED
1759 Export_Mesh(parent, theCommandID);
1763 case 200: // SCALAR BAR
1765 smeshGUI->DisplayScalarBar(false);
1770 SMESHGUI_EditScalarBarDlg *aDlg = new SMESHGUI_EditScalarBarDlg( parent, "", false ) ;
1776 smeshGUI->DisplayScalarBar( true );
1780 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
1786 smeshGUI->SetViewMode(theCommandID);
1790 case 214 : // UPDATE
1798 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1799 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1801 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1802 for(;It.More();It.Next()) {
1803 Handle(SALOME_InteractiveObject) IOS = It.Value();
1804 if ( IOS->hasEntry() ) {
1805 Standard_Boolean res;
1806 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IOS->getEntry(), res, true );
1807 if ( res ) smeshGUI->EraseActor( ac );
1811 Sel->ClearIObjects();
1812 smeshGUI->myActiveStudy->updateObjBrowser( true );
1815 case 301 : // DISPLAY
1817 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1819 QApplication::setOverrideCursor( Qt::waitCursor );
1820 SALOMEDS::SObject_var fatherSF =
1821 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1823 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1824 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1826 for(;It.More();It.Next()) {
1827 Handle(SALOME_InteractiveObject) IObject = It.Value();
1828 if ( IObject->hasEntry() ) {
1829 Standard_Boolean res;
1830 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1832 smeshGUI->DisplayActor( ac, true );
1833 smeshGUI->DisplayEdges( ac );
1834 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1838 QApplication::restoreOverrideCursor();
1843 case 302 : // DISPLAY ONLY
1845 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1846 QApplication::setOverrideCursor( Qt::waitCursor );
1847 vtkActorCollection* theActors = Renderer->GetActors();
1848 theActors->InitTraversal();
1849 vtkActor *ac = theActors->GetNextActor();
1850 while(!(ac==NULL)) {
1851 if ( ac->IsA("SMESH_Actor") ) {
1852 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1853 if(!anActor->isHighlighted()) {
1854 //anActor->VisibilityOff();
1855 //NRI- : 02/12/2002 : Fixed bugId 882
1856 // anActor->EdgeDevice->VisibilityOff();
1857 // anActor->EdgeShrinkDevice->VisibilityOff();
1858 anActor->SetVisibility( false );
1861 ac = theActors->GetNextActor();
1864 // Display selection
1865 SALOMEDS::SObject_var fatherSF = smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1867 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1868 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1870 for(;It.More();It.Next()) {
1871 Handle(SALOME_InteractiveObject) IObject = It.Value();
1872 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1874 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
1875 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
1877 if(myRenderInter->isInViewer(IObject)) {
1878 if ( IObject->hasEntry() ) {
1879 Standard_Boolean res;
1880 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1882 smeshGUI->DisplayActor( ac, true );
1883 smeshGUI->DisplayEdges( ac );
1884 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1889 smeshGUI->myActiveStudy->updateObjBrowser( true );
1890 QApplication::restoreOverrideCursor();
1897 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1898 smeshGUI->EmitSignalDeactivateDialog() ;
1899 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1900 Sel->ClearIObjects();
1901 smeshGUI->myDesktop->SetSelectionMode(1, true);
1902 parent->menuBar()->setItemChecked(9010, false );
1903 parent->menuBar()->setItemChecked(9011, false );
1904 smeshGUI->ViewNodes();
1905 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg( parent, "", Sel ) ;
1907 QApplication::restoreOverrideCursor();
1908 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1909 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
1914 case 405: // MOVE NODE
1916 smeshGUI->myDesktop->SetSelectionMode(1, true);
1917 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1918 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, "", Sel ) ;
1922 case 701: // COMPUTE MESH
1924 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1925 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1926 int nbSel = Sel->IObjectCount();
1928 QApplication::restoreOverrideCursor();
1932 SMESH::SMESH_Mesh_var aM;
1933 SMESH::SMESH_subMesh_var aSubM;
1934 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1935 if ( IObject->hasEntry() ) {
1936 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1937 SALOMEDS::GenericAttribute_var anAttr;
1938 SALOMEDS::AttributeIOR_var anIOR;
1939 if ( !aMorSM->_is_nil() ) {
1940 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
1941 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1942 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : IOR = " << anIOR->Value() )
1943 CORBA::Object_var cobj;
1945 cobj = _orb->string_to_object(anIOR->Value());
1946 if ( CORBA::is_nil(cobj) ) {
1947 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : nil object" )
1950 catch(CORBA::COMM_FAILURE& ex) {
1951 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : exception (1)" )
1953 aM = SMESH::SMESH_Mesh::_narrow(cobj);
1954 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1955 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1956 if ( !aM->_is_nil() ) {
1957 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1958 if ( !refShape->_is_nil() ) {
1959 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1961 QApplication::restoreOverrideCursor();
1962 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1963 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1967 smeshGUI->myComponentMesh->Compute( aM, refShape);
1968 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1969 // TO Do : change icon of all submeshes
1971 catch (const SALOME::SALOME_Exception& S_ex) {
1972 QtCatchCorbaException(S_ex);
1975 } else if ( !aSubM->_is_nil() ) {
1976 aM = aSubM->GetFather();
1977 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1978 if ( !refShape->_is_nil() ) {
1979 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1981 QApplication::restoreOverrideCursor();
1982 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1983 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1987 smeshGUI->myComponentMesh->Compute( aM, refShape);
1988 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1989 // TO Do : change icon of all submeshes
1991 catch (const SALOME::SALOME_Exception& S_ex) {
1992 QtCatchCorbaException(S_ex);
2000 // Check whether the actor for the mesh exists at least in one view
2001 Standard_Boolean res;
2002 SMESH_Actor* ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2004 smeshGUI->InitActor( aM );
2006 // Check whether the actor belongs to the active view
2007 VTKViewer_RenderWindowInteractor* rwInter =
2008 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2010 // The actor belongs to inactive view -> create a copy and add it in the active view
2011 if (!rwInter->isInViewer(IObject)) {
2012 SMESH_Actor* acCopy = SMESH_Actor::New();
2013 acCopy->ShallowCopy(ac);
2015 smeshGUI->DisplayActor( acCopy, false );
2019 if ( smeshGUI->myAutomaticUpdate ) {
2020 SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
2021 if ( Mesh != NULL ) {
2025 smeshGUI->DisplayActor( Mesh, true );
2026 smeshGUI->DisplayEdges( Mesh, true );
2027 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
2031 QApplication::restoreOverrideCursor();
2032 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2033 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2035 QApplication::restoreOverrideCursor();
2039 case 702: // ADD SUB MESH
2041 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2042 smeshGUI->EmitSignalDeactivateDialog() ;
2043 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2044 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg( parent, "", Sel ) ;
2046 QApplication::restoreOverrideCursor();
2047 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2048 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2053 case 703: // INIT MESH
2055 smeshGUI->EmitSignalDeactivateDialog() ;
2056 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2057 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg( parent, "", Sel ) ;
2061 case 704: // EDIT Hypothesis
2063 smeshGUI->EmitSignalDeactivateDialog() ;
2064 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2065 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2069 case 705: // EDIT Global Hypothesis
2071 smeshGUI->EmitSignalDeactivateDialog() ;
2072 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2073 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2077 case 706: // EDIT Local Hypothesis
2079 smeshGUI->EmitSignalDeactivateDialog() ;
2080 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2081 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2085 case 806: // ORIENTATION ELEMENTS
2087 smeshGUI->EmitSignalDeactivateDialog() ;
2088 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2089 smeshGUI->myDesktop->SetSelectionMode(3, true);
2090 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg( parent, "", Sel ) ;
2094 case 807: // DIAGONAL INVERSION
2096 smeshGUI->EmitSignalDeactivateDialog() ;
2097 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2098 Sel->ClearIObjects();
2099 smeshGUI->myDesktop->SetSelectionMode(2, true);
2100 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg( parent, "", Sel ) ;
2104 case 900: // MESH INFOS
2106 smeshGUI->EmitSignalDeactivateDialog() ;
2107 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2108 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg( parent, "", Sel ) ;
2112 case 1001: // AUTOMATIC UPDATE PREFERENCES
2114 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001) );
2115 if ( parent->menuBar()->isItemChecked(1001) ) {
2116 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","true");
2117 smeshGUI->myAutomaticUpdate = true;
2119 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","false");
2120 smeshGUI->myAutomaticUpdate = false;
2125 case 1003: // MESH PREFERENCES
2127 smeshGUI->SetDisplaySettings();
2133 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2134 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2135 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2136 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2137 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2138 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2139 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2140 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2141 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2143 if ( Width == 0 ) Width = 0.17;
2144 if ( Height == 0 ) Height = 0.8;
2145 if ( NumberOfLabels == 0 ) NumberOfLabels = 5;
2146 if ( NumberOfColors == 0) NumberOfColors = 64;
2148 SMESHGUI_Preferences_ScalarBarDlg *aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, "", true) ;
2150 if ( Bold.compare("true") == 0 )
2151 aDlg->Bold->setChecked(true); else aDlg->Bold->setChecked(false);
2152 if ( Italic.compare("true") == 0 )
2153 aDlg->Italic->setChecked(true); else aDlg->Italic->setChecked(false);
2154 if ( Shadow.compare("true") == 0 )
2155 aDlg->Shadow->setChecked(true); else aDlg->Shadow->setChecked(false);
2157 if ( Orientation.compare("Horizontal") == 0 )
2158 aDlg->RadioHoriz->setChecked(true); else aDlg->RadioVert->setChecked(true);
2160 int NbItems = aDlg->ComboBox1->count();
2162 aDlg->ComboBox1->setCurrentItem( i );
2163 while ( i < NbItems ) {
2164 if ( FontFamily.compare( aDlg->ComboBox1->text( i ) ) == 0 )
2165 aDlg->ComboBox1->setCurrentItem( i );
2169 aDlg->LineEditWidth->setText( QString("%1").arg(Width) );
2170 aDlg->LineEditHeight->setText( QString("%1").arg(Height) );
2172 aDlg->SpinBoxLabels->setValue( NumberOfLabels );
2173 aDlg->SpinBoxColors->setValue( NumberOfColors );
2176 if ( aDlg->result() ) {
2177 if ( aDlg->RadioHoriz->isChecked() )
2178 Orientation = "Horizontal"; else Orientation = "Vertical";
2179 if ( aDlg->Bold->isChecked() )
2180 Bold = "true"; else Bold = "false";
2181 if ( aDlg->Italic->isChecked() )
2182 Italic = "true"; else Italic = "false";
2183 if ( aDlg->Shadow->isChecked() )
2184 Shadow = "true"; else Shadow = "false";
2186 FontFamily = aDlg->ComboBox1->currentText();
2187 Width = aDlg->LineEditWidth->text().toFloat();
2188 Height = aDlg->LineEditHeight->text().toFloat();
2189 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2190 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2193 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
2194 if ( aScalarBar != NULL ) {
2195 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2196 FontFamily, Orientation,
2197 Width, Height, NumberOfColors, NumberOfLabels);
2200 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2201 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2202 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2203 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2204 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2205 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2206 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2207 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2208 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2213 case 1100: // EDIT HYPOTHESIS
2215 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2216 int nbSel = Sel->IObjectCount() ;
2219 Standard_Boolean res;
2220 SMESH::SMESH_Hypothesis_var Hyp = smeshGUI->ConvertIOinSMESHHypothesis( Sel->firstIObject(), res );
2222 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2223 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2224 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2225 SALOMEDS::Study::ListOfSObject_var listSOmesh = smeshGUI->GetMeshesUsingAlgoOrHypothesis( Hyp) ;
2228 QString Name = Hyp->GetName();
2230 if ( Name.compare("LocalLength") == 0 ) {
2231 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
2232 double beforeLength = LL->GetLength() ;
2233 double Length = smeshGUI->Parameter( res,
2235 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2238 if ( res && Length != beforeLength ) {
2239 LL->SetLength( Length );
2240 for( int i=0; i<listSOmesh->length(); i++ ) {
2241 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2246 } else if ( Name.compare("NumberOfSegments") == 0 ) {
2247 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
2248 int beforeNbSeg = NOS->GetNumberOfSegments() ;
2249 int NbSeg = smeshGUI->Parameter( res,
2251 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2255 if ( res && NbSeg != beforeNbSeg ) {
2256 NOS->SetNumberOfSegments( NbSeg );
2257 for( int i=0; i<listSOmesh->length(); i++ ) {
2258 SALOMEDS::SObject_var SO = listSOmesh[i] ;
2259 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2264 } else if ( Name.compare("MaxElementArea") == 0 ) {
2265 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
2266 double beforeMaxArea = MEA->GetMaxElementArea() ;
2267 double MaxArea = smeshGUI->Parameter( res,
2269 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2272 if ( res && MaxArea != beforeMaxArea ) {
2273 MEA->SetMaxElementArea( MaxArea );
2274 for( int i=0; i<listSOmesh->length(); i++ ) {
2275 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2280 } else if ( Name.compare("MaxElementVolume") == 0 ) {
2281 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
2282 double beforeMaxVolume = MEV->GetMaxElementVolume() ;
2283 double MaxVolume = smeshGUI->Parameter( res,
2285 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2288 if ( res && MaxVolume != beforeMaxVolume ) {
2289 MEV->SetMaxElementVolume( MaxVolume );
2290 for( int i=0; i<listSOmesh->length(); i++ ) {
2291 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2296 } else if ( Name.compare("Regular_1D") == 0 ) {
2297 } else if ( Name.compare("MEFISTO_2D") == 0 ) {
2306 case 1101: // RENAME
2308 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2309 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2310 for ( ; It.More(); It.Next() ) {
2311 Handle(SALOME_InteractiveObject) IObject = It.Value();
2313 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2314 SALOMEDS::GenericAttribute_var anAttr;
2315 SALOMEDS::AttributeName_var aName;
2316 if ( !obj->_is_nil() ) {
2317 if (obj->FindAttribute(anAttr, "AttributeName")) {
2318 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2319 QString newName = QString( aName->Value() );
2320 newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName);
2321 if ( !newName.isEmpty() ) {
2322 QApplication::setOverrideCursor( Qt::waitCursor );
2323 smeshGUI->myActiveStudy->renameIObject( IObject, newName );
2325 QApplication::restoreOverrideCursor();
2332 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2334 QApplication::setOverrideCursor( Qt::waitCursor );
2335 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2336 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2337 for ( int i=0; It.More(); It.Next(), i++ ) {
2338 Handle(SALOME_InteractiveObject) IObject = It.Value();
2339 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh( IObject );
2341 Sel->ClearIObjects();
2342 smeshGUI->myActiveStudy->updateObjBrowser( true );
2343 QApplication::restoreOverrideCursor();
2347 case 401: // GEOM::EDGE
2349 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2350 smeshGUI->EmitSignalDeactivateDialog() ;
2351 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2352 Sel->ClearIObjects();
2353 smeshGUI->myDesktop->SetSelectionMode(1, true);
2354 parent->menuBar()->setItemChecked(9010, false );
2355 parent->menuBar()->setItemChecked(9011, false );
2356 smeshGUI->ViewNodes();
2357 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg( parent, "", Sel ) ;
2359 QApplication::restoreOverrideCursor();
2360 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2361 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2365 case 4021: // TRIANGLE
2367 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2368 smeshGUI->EmitSignalDeactivateDialog() ;
2369 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2370 Sel->ClearIObjects();
2371 smeshGUI->myDesktop->SetSelectionMode(1, true);
2372 parent->menuBar()->setItemChecked(9010, false );
2373 parent->menuBar()->setItemChecked(9011, false );
2374 smeshGUI->ViewNodes();
2375 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 3 ) ;
2377 QApplication::restoreOverrideCursor();
2378 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2379 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2385 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2386 smeshGUI->EmitSignalDeactivateDialog() ;
2387 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2388 Sel->ClearIObjects();
2389 smeshGUI->myDesktop->SetSelectionMode(1, true);
2390 parent->menuBar()->setItemChecked(9010, false );
2391 parent->menuBar()->setItemChecked(9011, false );
2392 smeshGUI->ViewNodes();
2393 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 4 ) ;
2395 QApplication::restoreOverrideCursor();
2396 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2397 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2403 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2404 smeshGUI->EmitSignalDeactivateDialog() ;
2405 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2406 Sel->ClearIObjects();
2407 smeshGUI->myDesktop->SetSelectionMode(1, true);
2408 parent->menuBar()->setItemChecked(9010, false );
2409 parent->menuBar()->setItemChecked(9011, false );
2410 smeshGUI->ViewNodes();
2411 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 4 ) ;
2413 QApplication::restoreOverrideCursor();
2414 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2415 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2421 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2422 smeshGUI->EmitSignalDeactivateDialog() ;
2423 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2424 Sel->ClearIObjects();
2425 smeshGUI->myDesktop->SetSelectionMode(1, true);
2426 parent->menuBar()->setItemChecked(9010, false );
2427 parent->menuBar()->setItemChecked(9011, false );
2428 smeshGUI->ViewNodes();
2429 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 8 ) ;
2431 QApplication::restoreOverrideCursor();
2432 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2433 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2438 case 4041: // REMOVES NODES
2440 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2441 smeshGUI->EmitSignalDeactivateDialog() ;
2442 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2443 Sel->ClearIObjects();
2444 smeshGUI->myDesktop->SetSelectionMode(1, true);
2445 parent->menuBar()->setItemChecked(9010, false );
2446 parent->menuBar()->setItemChecked(9011, false );
2447 smeshGUI->ViewNodes();
2448 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg( parent, "", Sel ) ;
2450 QApplication::restoreOverrideCursor();
2451 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2452 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2456 case 4042: // REMOVES ELEMENTS
2458 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2459 smeshGUI->EmitSignalDeactivateDialog() ;
2460 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2461 Sel->ClearIObjects();
2462 smeshGUI->myDesktop->SetSelectionMode(3, true);
2463 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg( parent, "", Sel ) ;
2465 QApplication::restoreOverrideCursor();
2466 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2467 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2472 case 5000: // HYPOTHESIS - ALGO
2474 smeshGUI->CreateAlgorithm("Regular_1D","Wire Discretisation");
2479 smeshGUI->CreateAlgorithm("MEFISTO_2D","Triangle (Mefisto)");
2484 smeshGUI->CreateAlgorithm("Quadrangle_2D","Quadrangle (Mapping)");
2489 smeshGUI->CreateAlgorithm("Hexa_3D","Hexaedral (i,j,k)");
2493 case 5030: // HYPOTHESIS - LOCAL LENGTH
2495 smeshGUI->EmitSignalDeactivateDialog() ;
2496 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2497 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg( parent, "" ) ;
2500 case 5031: // HYPOTHESIS - NB SEGMENTS
2502 smeshGUI->EmitSignalDeactivateDialog() ;
2503 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2504 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg( parent, "" ) ;
2508 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
2510 smeshGUI->EmitSignalDeactivateDialog() ;
2511 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2512 SMESHGUI_MaxElementAreaDlg *aDlg = new SMESHGUI_MaxElementAreaDlg( parent, "" ) ;
2516 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
2518 smeshGUI->EmitSignalDeactivateDialog() ;
2519 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2520 SMESHGUI_MaxElementVolumeDlg *aDlg = new SMESHGUI_MaxElementVolumeDlg( parent, "" ) ;
2524 case 6016: // CONTROLS
2532 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2533 int nbSel = Sel->IObjectCount();
2536 smeshGUI->Control(theCommandID);
2542 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2543 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2544 SMESHGUI_EdgesConnectivityDlg *Dlg = new SMESHGUI_EdgesConnectivityDlg( parent, "", Sel ) ;
2546 QApplication::restoreOverrideCursor();
2547 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2548 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2555 if ( !parent->menuBar()->isItemChecked(9010) ) {
2556 QApplication::setOverrideCursor( Qt::waitCursor );
2557 parent->menuBar()->setItemChecked(9011, false );
2559 smeshGUI->EraseSimulationActors();
2560 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2562 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2563 int nbSel = Sel->IObjectCount() ;
2565 Standard_Boolean res;
2566 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2568 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2570 // It's necessary to display SMDS IDs instead of VTK ones, so
2571 // vtkIdFilter is unacceptable here. We have to do it manually :(
2572 vtkUnstructuredGrid* ptGrid = vtkUnstructuredGrid::New();
2573 ptGrid->CopyStructure(MeshActor->DataSource);
2575 int numPts = MeshActor->DataSource->GetNumberOfPoints();
2577 // Loop over points and generate ids
2578 vtkIntArray *ptIds = vtkIntArray::New();
2579 ptIds->SetNumberOfValues(numPts);
2581 for (int id=0; id < numPts; id++) {
2582 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
2583 ptIds->SetValue(id, idSMDS);
2586 vtkScalars* newScalars = vtkScalars::New();
2587 newScalars->SetData(ptIds);
2588 ptGrid->GetPointData()->SetScalars(newScalars);
2590 newScalars->Delete();
2593 vtkMaskPoints* mask = vtkMaskPoints::New();
2594 mask->SetInput(ptGrid);
2595 mask->SetOnRatio( 1 );
2596 // mask->SetMaximumNumberOfPoints( 50 );
2597 // mask->RandomModeOn();
2599 vtkSelectVisiblePoints* visPts = vtkSelectVisiblePoints::New();
2600 visPts->SetInput(mask->GetOutput());
2601 visPts->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2602 //visPts->SetSelectInvisible(1);
2603 visPts->SelectInvisibleOff();
2604 visPts->SetTolerance(0.1);
2606 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2607 ldm->SetInput(visPts->GetOutput());
2608 ldm->SetLabelFormat("%g");
2609 ldm->SetLabelModeToLabelScalars();
2610 //ldm->SetLabelModeToLabelFieldData();
2612 ldm->SetFontFamilyToTimes();
2613 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2618 vtkActor2D* pointLabels = vtkActor2D::New();
2619 pointLabels->SetMapper(ldm);
2620 pointLabels->GetProperty()->SetColor(0,1,0);
2624 smeshGUI->mySimulationActors2D->AddItem( pointLabels );
2625 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( pointLabels );
2629 QApplication::setOverrideCursor( Qt::waitCursor );
2630 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2631 smeshGUI->EraseSimulationActors();
2632 smeshGUI->ScalarVisibilityOff();
2634 QApplication::restoreOverrideCursor();
2639 if ( !parent->menuBar()->isItemChecked(9011) ) {
2640 QApplication::setOverrideCursor( Qt::waitCursor );
2641 parent->menuBar()->setItemChecked(9010, false );
2643 smeshGUI->EraseSimulationActors();
2644 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2646 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2647 int nbSel = Sel->IObjectCount() ;
2649 Standard_Boolean res;
2650 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2652 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2654 // It's necessary to display SMDS IDs instead of VTK ones, so
2655 // vtkIdFilter is unacceptable here. We have to do it manually :(
2656 vtkUnstructuredGrid* elGrid = vtkUnstructuredGrid::New();
2657 elGrid->CopyStructure(MeshActor->DataSource);
2659 int numCells = MeshActor->DataSource->GetNumberOfCells();
2661 // Loop over points and generate ids
2662 vtkIntArray *cellIds = vtkIntArray::New();
2663 cellIds->SetNumberOfValues(numCells);
2665 for (int id=0; id < numCells; id++) {
2666 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
2667 cellIds->SetValue(id, idSMDS);
2670 vtkScalars* newScalars = vtkScalars::New();
2671 newScalars->SetData(cellIds);
2672 elGrid->GetCellData()->SetScalars(newScalars);
2674 newScalars->Delete();
2677 vtkCellCenters* cc = vtkCellCenters::New();
2678 cc->SetInput(elGrid);
2680 vtkSelectVisiblePoints* visCells = vtkSelectVisiblePoints::New();
2681 visCells->SetInput(cc->GetOutput());
2682 visCells->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2683 visCells->SelectInvisibleOff();
2684 visCells->SetTolerance(0.1);
2685 // visCells->SetSelectInvisible(1);
2687 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2688 ldm->SetInput(visCells->GetOutput());
2689 ldm->SetLabelFormat("%g");
2690 ldm->SetLabelModeToLabelScalars();
2692 ldm->SetFontFamilyToTimes();
2693 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2698 vtkActor2D* cellLabels = vtkActor2D::New();
2699 cellLabels->SetMapper(ldm);
2700 cellLabels->GetProperty()->SetColor(1,0,0);
2705 smeshGUI->mySimulationActors2D->AddItem( cellLabels );
2706 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( cellLabels );
2710 QApplication::setOverrideCursor( Qt::waitCursor );
2711 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2712 smeshGUI->EraseSimulationActors();
2713 smeshGUI->ScalarVisibilityOff();
2715 QApplication::restoreOverrideCursor();
2719 case 10001: // DISPLAY MODE PREFERENCE
2721 parent->menuBar()->setItemChecked(10001, !parent->menuBar()->isItemChecked(10001) );
2722 parent->menuBar()->setItemChecked(10002, false );
2723 parent->menuBar()->setItemChecked(10003, false );
2724 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2729 parent->menuBar()->setItemChecked(10002, !parent->menuBar()->isItemChecked(10002) );
2730 parent->menuBar()->setItemChecked(10001, false );
2731 parent->menuBar()->setItemChecked(10003, false );
2732 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2737 parent->menuBar()->setItemChecked(10003, !parent->menuBar()->isItemChecked(10003) );
2738 parent->menuBar()->setItemChecked(10002, false );
2739 parent->menuBar()->setItemChecked(10001, false );
2740 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
2746 smeshGUI->myActiveStudy->updateObjBrowser(true);
2751 //=============================================================================
2752 /*! function : GetMeshesUsingAlgoOrHypothesis()
2753 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
2754 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
2756 //=============================================================================
2757 SALOMEDS::Study::ListOfSObject* SMESHGUI::GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp )
2759 SALOMEDS::Study::ListOfSObject_var listSOmesh = new SALOMEDS::Study::ListOfSObject ;
2760 listSOmesh->length(0) ;
2761 unsigned int index = 0 ;
2762 if( !AlgoOrHyp->_is_nil() ) {
2763 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms( AlgoOrHyp );
2764 if( !SO_Hypothesis->_is_nil() ) {
2765 SALOMEDS::Study::ListOfSObject_var listSO = smeshGUI->myStudy->FindDependances(SO_Hypothesis) ;
2766 for( unsigned int i=0; i<listSO->length(); i++ ) {
2767 SALOMEDS::SObject_var SO = listSO[i] ;
2768 if( !SO->_is_nil() ) {
2769 SALOMEDS::SObject_var SOfatherFather = SO->GetFather()->GetFather() ;
2770 if( !SOfatherFather->_is_nil() ) {
2772 listSOmesh->length(index) ;
2773 listSOmesh[index-1] = SOfatherFather ;
2779 return listSOmesh._retn() ;
2783 //=============================================================================
2787 //=============================================================================
2788 void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
2792 Mesh_Reader* myReader;
2794 if (theCommandID==113) {
2795 filter = tr("MED files (*.med)");
2796 myExtension = string("MED");
2797 myReader = new DriverMED_R_SMESHDS_Mesh;
2799 else if (theCommandID==112) {
2800 filter = tr("IDEAS files (*.unv)");
2801 myExtension = string("UNV");
2803 else if (theCommandID==111) {
2804 filter = tr("DAT files (*.dat)");
2805 myExtension = string("MED");
2806 myReader = new DriverDAT_R_SMESHDS_Mesh;
2809 QString filename = QAD_FileDlg::getFileName(parent,
2814 if ( !filename.isEmpty() ) {
2815 QApplication::setOverrideCursor( Qt::waitCursor );
2816 string myClass = string("SMESHDS_Mesh");
2817 // Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
2819 int myMeshId = (smeshGUI->myDocument)->NewMesh();
2820 Handle(SMDS_Mesh) myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
2822 myReader->SetFile(string(filename.latin1()));
2823 myReader->SetMesh(myMesh);
2824 myReader->SetMeshId(myMeshId);
2827 QApplication::restoreOverrideCursor();
2831 //=============================================================================
2835 //=============================================================================
2836 void SMESHGUI::Export_Mesh(QAD_Desktop* parent, int theCommandID)
2838 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2839 int nbSel = Sel->IObjectCount() ;
2841 Standard_Boolean res;
2842 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2843 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh( IObject, res );
2845 if (theCommandID==122) { // EXPORT MED
2846 QString filename = QAD_FileDlg::getFileName(parent,
2848 tr("MED files (*.med)"),
2851 if ( !filename.isEmpty() ) {
2852 QApplication::setOverrideCursor( Qt::waitCursor );
2853 aMesh->ExportMED( filename.latin1() );
2854 QApplication::restoreOverrideCursor();
2857 else if (theCommandID==121) { // EXPORT DAT
2858 QString filename = QAD_FileDlg::getFileName(parent,
2860 tr("DAT files (*.dat)"),
2863 if ( !filename.isEmpty() ) {
2864 QApplication::setOverrideCursor( Qt::waitCursor );
2865 aMesh->ExportDAT( filename.latin1() );
2866 QApplication::restoreOverrideCursor();
2869 else if (theCommandID==123) { // EXPORT UNV
2870 QString filename = QAD_FileDlg::getFileName(parent,
2872 tr("IDEAS files (*.unv)"),
2875 if ( !filename.isEmpty() ) {
2876 QApplication::setOverrideCursor( Qt::waitCursor );
2877 aMesh->ExportUNV( filename.latin1() );
2878 QApplication::restoreOverrideCursor();
2881 aMesh->ExportDAT( filename.latin1() );
2883 QApplication::restoreOverrideCursor();
2885 if ( IObject->hasEntry() )
2888 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2889 SALOMEDS::GenericAttribute_var anAttr;
2890 SALOMEDS::AttributeComment_var aFileName;
2891 SALOMEDS::StudyBuilder_var aStudyBuilder = smeshGUI->myStudy->NewBuilder();
2892 anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
2893 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
2894 aFileName->SetValue(filename.latin1());
2901 //=============================================================================
2905 //=============================================================================
2906 void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
2910 Document_Reader* myReader;
2912 if (theCommandID==113) {
2913 filter = tr("MED files (*.med)");
2914 myExtension = string("MED");
2915 myReader = new DriverMED_R_SMESHDS_Document;
2917 else if (theCommandID==112) {
2918 filter = tr("IDEAS files (*.unv)");
2919 myExtension = string("UNV");
2920 myReader = new DriverUNV_R_SMESHDS_Document;
2922 else if (theCommandID==111) {
2923 filter = tr("DAT files (*.dat)");
2924 myExtension = string("DAT");
2925 myReader = new DriverDAT_R_SMESHDS_Document;
2928 QString filename = QAD_FileDlg::getFileName(parent,
2931 tr("Import document"),
2933 if ( !filename.isEmpty() ) {
2934 QApplication::setOverrideCursor( Qt::waitCursor );
2935 string myClass = string("SMESHDS_Document");
2936 // Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
2937 Handle(SMESHDS_Document) newDocument = new SMESHDS_Document(1);
2939 myReader->SetFile(string(filename.latin1()));
2940 myReader->SetDocument(smeshGUI->myDocument);
2942 QApplication::restoreOverrideCursor();
2946 void SMESHGUI::Export_Document(QAD_Desktop* parent, int theCommandID)
2949 Document_Writer* myWriter;
2952 if (theCommandID==122) {
2953 filter = tr("MED files (*.med)");
2954 myExtension = string("MED");
2955 myWriter = new DriverMED_W_SMESHDS_Document;
2957 else if (theCommandID==121) {
2958 filter = tr("DAT files (*.dat)");
2959 myExtension = string("DAT");
2960 myWriter = new DriverDAT_W_SMESHDS_Document;
2961 } else if (theCommandID==123) {
2962 filter = tr("IDEAS files (*.unv)");
2963 myExtension = string("UNV");
2964 myWriter = new DriverUNV_W_SMESHDS_Document;
2967 QString filename = QAD_FileDlg::getFileName(parent,
2970 tr("Export document"),
2972 if ( !filename.isEmpty() ) {
2973 QApplication::setOverrideCursor( Qt::waitCursor );
2974 string myClass = string("SMESHDS_Document");
2975 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
2977 myWriter->SetFile(string(filename.latin1()));
2978 myWriter->SetDocument(smeshGUI->myDocument);
2980 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
2981 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
2982 //myWriter->SetDocument(myDocument);
2985 QApplication::restoreOverrideCursor();
2989 //=============================================================================
2993 //=============================================================================
2994 bool SMESHGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
2996 SMESHGUI::GetOrCreateSMESHGUI(parent);
3001 //=============================================================================
3005 //=============================================================================
3006 bool SMESHGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3008 SMESHGUI::GetOrCreateSMESHGUI(parent);
3014 //=============================================================================
3018 //=============================================================================
3019 bool SMESHGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3021 SMESHGUI::GetOrCreateSMESHGUI(parent);
3027 //=============================================================================
3031 //=============================================================================
3032 bool SMESHGUI::SetSettings( QAD_Desktop* parent )
3034 SMESHGUI::GetOrCreateSMESHGUI(parent);
3037 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3038 if ( DisplayMode.compare("") == 0 ) {
3039 DisplayMode = "Shading";
3040 QAD_CONFIG->addSetting("SMESH:DisplayMode","Shading");
3043 if ( DisplayMode.compare("Wireframe") == 0 ){
3044 parent->menuBar()->setItemChecked(10003, false );
3045 parent->menuBar()->setItemChecked(10002, false );
3046 parent->menuBar()->setItemChecked(10001, true );
3047 } else if ( DisplayMode.compare("Shading") == 0 ){
3048 parent->menuBar()->setItemChecked(10003, false );
3049 parent->menuBar()->setItemChecked(10002, true );
3050 parent->menuBar()->setItemChecked(10001, false );
3051 } else if ( DisplayMode.compare("Shrink") == 0 ) {
3052 parent->menuBar()->setItemChecked(10003, true );
3053 parent->menuBar()->setItemChecked(10002, false );
3054 parent->menuBar()->setItemChecked(10001, false );
3057 /* Automatic Update */
3058 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3059 if ( AutoUpdate.compare("true") == 0 ) {
3060 parent->menuBar()->setItemChecked(1001, true );
3061 smeshGUI->myAutomaticUpdate = true;
3063 parent->menuBar()->setItemChecked(1001, false );
3064 smeshGUI->myAutomaticUpdate = false;
3068 parent->menuBar()->setItemEnabled( 11, false); // IMPORT
3074 //=============================================================================
3078 //=============================================================================
3079 void SMESHGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
3081 /* Create or retrieve an object SMESHGUI */
3082 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3084 // NRI : Temporary added
3085 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3086 // theObject = "NothingSelected";
3087 // theContext = "NothingSelected";
3091 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3092 int nbSel = Sel->IObjectCount();
3094 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3095 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
3096 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1) ) {
3097 theObject = "ScalarBar";
3100 theObject = "NothingSelected";
3101 theContext = "NothingSelected";
3104 theObject = "NothingSelected";
3105 theContext = "NothingSelected";
3107 } else if (nbSel == 1 ) {
3108 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3111 theObject = smeshGUI->CheckHomogeneousSelection();
3116 //=============================================================================
3120 //=============================================================================
3121 bool SMESHGUI::CustomPopup( QAD_Desktop* parent,
3123 const QString& theContext,
3124 const QString& theParent,
3125 const QString& theObject )
3127 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3128 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3130 /* Create or retrieve an object SMESHGUI */
3131 SMESHGUI::GetOrCreateSMESHGUI(parent);
3133 // NRI : Temporary added
3134 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3139 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3140 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3141 int nbSel = Sel->IObjectCount();
3144 if (studyFrame->getTypeView() != VIEW_VTK)
3147 } else if (nbSel == 1 ) {
3148 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3149 // First check type of active viewer (VTK required)
3150 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3152 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3154 int id = popup->idAt(0);
3155 if (id <= QAD_TopLabel_Popup_ID)
3156 popup->removeItemAt(0);
3160 if (theObject.compare("Component") == 0) {
3161 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3166 // Remove common popup items for Submesh, Hypothesis and Algorithm
3167 if (theObject.compare("SubMesh") == 0 ||
3168 theObject.compare("Hypothesis") == 0 ||
3169 theObject.compare("Algorithm") == 0 ) {
3170 popup->removeItem(QAD_Display_Popup_ID);
3171 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3172 popup->removeItem(QAD_Erase_Popup_ID);
3173 int id = popup->idAt(popup->count()-1); // last item
3174 if (id < 0 && id != -1) popup->removeItem(id); // separator
3177 if (theObject.compare("Component") == 0) {
3178 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3182 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3183 QFont f = QApplication::font();
3186 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3188 if ( theParent.compare("Viewer")==0 ) {
3189 if (popup->idAt(0) == id) {
3190 popup->removeItem(id);
3191 popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), id, 0 );
3194 Standard_Boolean res;
3195 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3196 if ( res && studyFrame->getTypeView() == VIEW_VTK) {
3197 VTKViewer_RenderWindowInteractor* myRenderInter=
3198 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3199 if ( myRenderInter->isVisible( IObject ) ) {
3200 popup->removeItem(QAD_Display_Popup_ID);
3202 popup->removeItem(QAD_Erase_Popup_ID);
3205 popup->removeItem(QAD_Erase_Popup_ID);
3206 if (!res) {// mesh not computed -> can't display it
3207 popup->removeItem(QAD_Display_Popup_ID);
3208 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3209 popup->removeItemAt(popup->count() - 1);//separator
3212 } else if ( theParent.compare("ObjectBrowser")==0 ) {
3213 if (theObject.compare("Mesh") == 0 ||
3214 theObject.compare("SubMesh") == 0 ||
3215 theObject.compare("Hypothesis") == 0 ||
3216 theObject.compare("Algorithm") == 0 ) {
3217 popup->removeItemAt(0);
3219 if (popup->idAt(0) == id) {
3220 popup->removeItem(id);
3221 popup->removeItemAt(0);//separator
3225 Standard_Boolean res;
3226 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3227 if ( res && studyFrame->getTypeView() == VIEW_VTK ) {
3228 VTKViewer_RenderWindowInteractor* myRenderInter=
3229 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3230 if ( myRenderInter->isVisible( IObject ) ) {
3231 popup->removeItem(QAD_Display_Popup_ID);
3233 popup->removeItem(QAD_Erase_Popup_ID);
3236 if (theObject.compare("Mesh") == 0 ||
3237 theObject.compare("SubMesh") == 0 ||
3238 theObject.compare("Hypothesis") == 0 ||
3239 theObject.compare("Algorithm") == 0 ) {
3241 popup->removeItem(QAD_Erase_Popup_ID);
3242 if (!res) {// mesh not computed -> can't display it
3243 popup->removeItem(QAD_Display_Popup_ID);
3244 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3245 popup->removeItemAt(popup->count() - 1);//separator
3251 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3252 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3253 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3255 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3257 int id = popup->idAt(0);
3258 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3259 popup->removeItemAt(0);
3263 if (parentComp.isNull()) { // objects from several components are selected
3264 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3265 popup->removeItem(QAD_Display_Popup_ID);
3266 popup->removeItem(QAD_Erase_Popup_ID);
3267 int id = popup->idAt(popup->count()-1); // last item
3268 if (id < 0 && id != -1) popup->removeItem(id); // separator
3273 QString type = smeshGUI->CheckHomogeneousSelection();
3274 if ( type.compare("Heterogeneous Selection") != 0 ) {
3275 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3276 QFont f = QApplication::font();
3278 popup->removeItem(id);
3279 popup->insertItem( new CustomItem ( QString("%1 ").arg(nbSel) + type + " (s) ", f), id, 0 );
3285 //=============================================================================
3286 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3287 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3289 //=============================================================================
3290 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3292 /* Create or retrieve an object SMESHGUI */
3293 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3295 QAD_StudyFrame* activeFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3296 if (activeFrame->getTypeView() == VIEW_VTK) {
3298 SALOMEDS::SObject_var fatherSF =
3299 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
3301 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3302 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3304 // for(;It.More();It.Next()) {
3305 // Handle(SALOME_InteractiveObject) IObject = It.Value();
3306 Handle(SALOME_InteractiveObject) IObject = theIO;
3307 if ( IObject->hasEntry() ) {
3308 // Look for the actor in all views
3309 Standard_Boolean res;
3310 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3312 // Actor not found at all -> mesh is not computed -> do nothing!!!
3314 /*SMESH::SMESH_Mesh_var aM;
3315 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3316 SALOMEDS::SObject_var father = aMorSM->GetFather();
3317 SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
3319 // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
3320 if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
3323 SALOMEDS::GenericAttribute_var anAttr;
3324 SALOMEDS::AttributeIOR_var anIOR;
3325 if ( !aMorSM->_is_nil() ) {
3326 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
3327 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3328 aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
3332 if (!aM->_is_nil()) {
3333 smeshGUI->InitActor(aM);
3334 ac = smeshGUI->ReadScript(aM);
3338 smeshGUI->DisplayActor( ac, true );
3339 smeshGUI->DisplayEdges( ac );
3340 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3343 } else { // The actor exists in some view
3344 // Check whether the actor belongs to the active view
3345 VTKViewer_RenderWindowInteractor* rwInter =
3346 ((VTKViewer_ViewFrame*)activeFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3348 // The actor belongs to inactive view -> create a copy and display it in the active view
3349 if (!rwInter->isInViewer(IObject)) {
3350 SMESH_Actor* acCopy = SMESH_Actor::New();
3351 acCopy->ShallowCopy(ac);
3354 smeshGUI->DisplayActor( ac, false );
3355 smeshGUI->DisplayEdges( ac );
3356 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3361 MESSAGE("BuildPresentation() must not be called while non-VTK view is active")
3365 //=============================================================================
3369 //=============================================================================
3370 void SMESHGUI::setOrb()
3373 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
3374 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
3375 _orb = init( 0 , 0 );
3377 INFOS("internal error : orb not found");
3380 ASSERT(! CORBA::is_nil(_orb));
3384 //=============================================================================
3388 //=============================================================================
3389 SMESH_Actor* SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
3391 SMESH_Actor* MeshActor;
3392 if ( !aMesh->_is_nil() ) {
3393 Standard_Boolean result;
3394 MeshActor = FindActor(aMesh, result, true);
3396 SMESH::log_array_var aSeq = aMesh->GetLog(true);
3398 if (aSeq->length() == 0) {
3399 MESSAGE("ReadScript(): log is empty")
3403 for (unsigned int ind = 0; ind < aSeq->length();ind++) {
3404 switch ( aSeq[ind].commandType )
3406 case SMESH::ADD_NODE :
3408 AddNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3411 case SMESH::ADD_EDGE :
3413 // AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3416 case SMESH::ADD_TRIANGLE :
3418 AddTriangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3421 case SMESH::ADD_QUADRANGLE :
3423 AddQuadrangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3426 case SMESH::ADD_TETRAHEDRON :
3428 AddTetras( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3431 case SMESH::ADD_PYRAMID :
3435 case SMESH::ADD_PRISM :
3439 case SMESH::ADD_HEXAHEDRON :
3441 AddHexaedres( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3444 case SMESH::REMOVE_NODE :
3446 RemoveNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3449 case SMESH::REMOVE_ELEMENT :
3451 RemoveElements( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3463 //=============================================================================
3467 //=============================================================================
3468 void SMESHGUI::Dump(SMESH_Actor* Mactor)
3470 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3471 vtkPoints *Pts = ugrid->GetPoints();
3472 int nbPts = Pts->GetNumberOfPoints();
3473 int nbCells = ugrid->GetNumberOfCells();
3477 In = fopen("/tmp/dumpMesh","w+");
3478 fprintf(In,"%d %d\n",nbPts,nbCells);
3479 for ( int i = 0; i < nbPts; i++ ) {
3480 float *p = ugrid->GetPoint(i);
3481 fprintf(In,"%d %e %e %e\n",i, p[0], p[1], p[2] );
3484 for ( int i = 0; i < nbCells; i++ ) {
3485 fprintf(In,"%d %d",i,ugrid->GetCell(i)->GetCellType());
3486 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3487 for (j=0; j<Id->GetNumberOfIds(); j++) {
3488 fprintf(In," %d",Id->GetId(j));
3496 //=============================================================================
3500 //=============================================================================
3501 void SMESHGUI::AddNodes( SMESH_Actor* Mactor, int number,
3502 const SMESH::double_array& coords,
3503 const SMESH::long_array& indexes)
3505 QApplication::setOverrideCursor( Qt::waitCursor );
3506 if ( Mactor->GetMapper() == NULL ) {
3507 vtkPoints *Pts = vtkPoints::New();
3508 SMESH_Grid *ugrid = SMESH_Grid::New();
3513 while ( i <= number ) {
3514 int idVTK = Pts->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3515 //Mactor->AddNode( indexes[i-1], idVTK );
3516 ugrid->AddNode( indexes[i-1], idVTK );
3520 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3521 ugrid->SetPoints(Pts);
3522 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3523 PtsMapper->SetInput( ugrid );
3524 Mactor->DataSource = PtsMapper->GetInput();
3525 Mactor->SetMapper(PtsMapper);
3527 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3528 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3531 while ( i <= number ) {
3532 int idVTK = ugrid->GetPoints()->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3533 ugrid->AddNode( indexes[i-1], idVTK );
3537 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3538 PtsMapper->SetInput( ugrid );
3539 Mactor->DataSource = PtsMapper->GetInput();
3540 Mactor->SetMapper(PtsMapper);
3542 QApplication::restoreOverrideCursor();
3545 //=============================================================================
3549 //=============================================================================
3550 void SMESHGUI::AddNode(SMESH_Actor* Mactor, int idnode, float x, float y, float z)
3552 QApplication::setOverrideCursor( Qt::waitCursor );
3553 MESSAGE ( "SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z )
3554 if ( Mactor->GetMapper() == NULL ) {
3555 vtkPoints *Pts = vtkPoints::New();
3556 int idVTK = Pts->InsertNextPoint( x, y, z );
3557 //Mactor->AddNode( idnode, idVTK );
3558 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3559 SMESH_Grid *ugrid = SMESH_Grid::New();
3561 ugrid->AddNode( idnode, idVTK );
3562 ugrid->SetPoints(Pts);
3563 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3564 PtsMapper->SetInput( ugrid );
3565 Mactor->DataSource = PtsMapper->GetInput();
3566 Mactor->SetMapper(PtsMapper);
3568 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3569 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3570 int idVTK = ugrid->GetPoints()->InsertNextPoint( x, y, z );
3571 //Mactor->AddNode( idnode, idVTK );
3572 ugrid->AddNode( idnode, idVTK );
3573 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3574 PtsMapper->SetInput( ugrid );
3575 Mactor->DataSource = PtsMapper->GetInput();
3576 Mactor->SetMapper(PtsMapper);
3578 QApplication::restoreOverrideCursor();
3581 //=============================================================================
3585 //=============================================================================
3586 void SMESHGUI::RemoveNode(SMESH_Actor* Mactor, int idnode)
3588 MESSAGE ( " OLD RemoveNode method " )
3589 // int id = Mactor->GetIdVTKNode( idnode );
3590 // MESSAGE ( " RemoveNode id VTK " << id )
3591 // if ( Mactor->GetMapper() != NULL ) {
3592 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3593 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3594 // vtkPoints *Pts = ugrid->GetPoints();
3595 // vtkPoints *newPts = vtkPoints::New();
3596 // int nbPts = Pts->GetNumberOfPoints();
3597 // bool findPt = false;
3598 // for ( int i = 0; i < nbPts; i++ ) {
3601 // newPts->InsertPoint(i, Pts->GetPoint(i) );
3603 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
3606 // Mactor->RemoveNode( idnode );
3610 // newUgrid->SetPoints(newPts);
3611 // int nbCells = ugrid->GetNumberOfCells();
3612 // for ( int i = 0; i < nbCells; i++ ) {
3613 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3614 // vtkIdList *newIds = vtkIdList::New();
3615 // int nbIds = Ids->GetNumberOfIds();
3616 // newIds->SetNumberOfIds(nbIds);
3617 // for ( int j = 0; j < nbIds; j++ ) {
3618 // int theid = Ids->GetId(j);
3619 // if ( theid > id ) {
3620 // newIds->SetId( j, theid-1 );
3622 // newIds->SetId( j, theid );
3624 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3625 // Mactor->RemoveElement( idSMDSel, false );
3626 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3627 // Mactor->AddElement( idSMDSel, idVTKel );
3631 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3632 // Mapper->SetInput( newUgrid );
3633 // Mactor->DataSource = Mapper->GetInput();
3634 // Mactor->SetMapper(Mapper);
3640 //=============================================================================
3644 //=============================================================================
3645 void SMESHGUI::RemoveNodes(SMESH_Actor* Mactor, int number,
3646 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3648 QApplication::setOverrideCursor( Qt::waitCursor );
3650 while ( i <= number ) {
3651 Mactor->RemoveNode( indexes[i-1] );
3655 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
3656 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
3657 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
3659 if ( Mactor->GetMapper() != NULL ) {
3660 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3661 SMESH_Grid *newUgrid = SMESH_Grid::New();
3662 newUgrid->CopyMaps(ugrid);
3664 vtkPoints *Pts = ugrid->GetPoints();
3665 vtkPoints *newPts = vtkPoints::New();
3666 int nbPts = Pts->GetNumberOfPoints();
3668 for ( int i = 0; i < nbPts; i++ ) {
3669 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
3670 if ( idSMESHDSNode != -1 ) {
3671 newPts->InsertPoint(j, Pts->GetPoint(i) );
3673 newMapVTKNodes.Bind(j, idSMESHDSNode);
3674 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
3676 MapOldNodesToNewNodes.Bind(i,j);
3681 newUgrid->SetIdsVTKNode(newMapVTKNodes);
3682 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
3683 newUgrid->SetPoints(newPts);
3685 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3686 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3688 int nbCells = ugrid->GetNumberOfCells();
3689 for ( int i = 0; i < nbCells; i++ ) {
3690 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3691 vtkIdList *newIds = vtkIdList::New();
3692 int nbIds = Ids->GetNumberOfIds();
3693 newIds->SetNumberOfIds(nbIds);
3695 for ( int j = 0; j < nbIds; j++ ) {
3696 int theid = Ids->GetId(j);
3697 if ( MapOldNodesToNewNodes.IsBound( theid ) ) {
3698 newIds->SetId( j, MapOldNodesToNewNodes.Find( theid ) );
3705 // Filtering out cells based on non-existing nodes
3707 int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3708 int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3710 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
3711 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
3715 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3716 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3718 // Copy new data to the old DatSource: keep the single DataSource for all actors
3719 ugrid->DeepCopy(newUgrid);
3721 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3722 Mapper->SetInput( ugrid );
3723 Mactor->SetMapper(Mapper);
3725 // Commented to avoid multiple viewer updates when called by ReadScript()
3729 QApplication::restoreOverrideCursor();
3732 //=============================================================================
3736 //=============================================================================
3737 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3739 QApplication::setOverrideCursor( Qt::waitCursor );
3740 Standard_Boolean result;
3741 SMESH_Actor* ac = FindActor( aMesh, result, true );
3743 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3744 anArrayOfIdeces->length(MapIndex.Extent());
3745 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3747 for ( ; ite.More(); ite.Next() ) {
3748 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
3749 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
3752 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3753 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3756 if ( myAutomaticUpdate ) {
3757 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3758 if ( Mesh != NULL ) {
3759 smeshGUI->DisplayActor( Mesh );
3760 smeshGUI->DisplayEdges( Mesh );
3761 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3762 AddActorInSelection( Mesh );
3765 QApplication::restoreOverrideCursor();
3768 //=============================================================================
3772 //=============================================================================
3773 void SMESHGUI::RemoveElement(SMESH_Actor* Mactor, int idelement)
3775 MESSAGE ( " OLD RemoveElement method " )
3776 // int id = Mactor->GetIdVTKElement( idelement );
3777 // MESSAGE ( " RemoveElement id VTK : " << id )
3778 // if ( Mactor->GetMapper() != NULL ) {
3779 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3780 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3782 // int nbCells = ugrid->GetNumberOfCells();
3783 // for ( int i = 0; i < nbCells; i++ ) {
3785 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3786 // ugrid->GetCell(i)->GetPointIds() );
3788 // Mactor->RemoveElement( idelement );
3790 // newUgrid->SetPoints(ugrid->GetPoints());
3792 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3793 // Mapper->SetInput( newUgrid );
3794 // Mactor->DataSource = Mapper->GetInput();
3795 // Mactor->SetMapper(Mapper);
3801 //=============================================================================
3805 //=============================================================================
3806 void SMESHGUI::RemoveElements(SMESH_Actor* Mactor, int number,
3807 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3809 QApplication::setOverrideCursor( Qt::waitCursor );
3811 while ( i <= number ) {
3812 Mactor->RemoveElement( indexes[i-1] );
3815 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3816 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3818 if ( Mactor->GetMapper() != NULL ) {
3819 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3820 SMESH_Grid* newUgrid = SMESH_Grid::New();
3821 newUgrid->CopyMaps(ugrid);
3823 int nbCells = ugrid->GetNumberOfCells();
3824 for ( int i = 0; i < nbCells; i++ ) {
3825 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
3826 if ( idSMESHDSElement != -1 ) {
3827 int newId = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3828 ugrid->GetCell(i)->GetPointIds() );
3829 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
3830 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
3834 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3835 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3837 newUgrid->SetPoints(ugrid->GetPoints());
3839 // Copy new data to the old DatSource: keep the single DataSource for all actors
3840 ugrid->DeepCopy(newUgrid);
3842 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3843 Mapper->SetInput( ugrid );
3844 Mactor->SetMapper(Mapper);
3846 // Commented to avoid multiple viewer updates when called by ReadScript()
3849 QApplication::restoreOverrideCursor();
3852 //=============================================================================
3856 //=============================================================================
3857 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3859 QApplication::setOverrideCursor( Qt::waitCursor );
3860 Standard_Boolean result;
3861 SMESH_Actor* ac = FindActor( aMesh, result, true );
3863 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3864 anArrayOfIdeces->length(MapIndex.Extent());
3865 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3867 for ( ; ite.More(); ite.Next() ) {
3868 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
3869 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
3873 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3874 aMeshEditor->RemoveElements(anArrayOfIdeces);
3877 if ( myAutomaticUpdate ) {
3878 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3879 if ( Mesh != NULL ) {
3880 smeshGUI->DisplayActor( Mesh );
3881 smeshGUI->DisplayEdges( Mesh );
3882 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3883 AddActorInSelection( Mesh );
3889 QApplication::restoreOverrideCursor();
3893 //=============================================================================
3897 //=============================================================================
3898 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3900 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3903 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3904 Standard_Boolean result;
3905 SMESH_Actor* ac = FindActor( aMesh, result, true );
3907 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3908 SMESH_Grid* UGrid = SMESH_Grid::New();
3909 SMESH_Grid* oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
3910 UGrid->CopyMaps(oldGrid);
3912 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3913 gf->SetInput( ac->DataSource );
3915 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3916 Mapper->SetInput( gf->GetOutput() );
3919 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3920 for ( ; ite.More(); ite.Next() ) {
3921 Mapper->GetInput()->ReverseCell( ite.Key() );
3924 UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
3925 int nbCells = Mapper->GetInput()->GetNumberOfCells();
3926 for ( int i = 0; i < nbCells; i++ ) {
3927 UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
3930 // Copy new data to the old DatSource: keep the single DataSource for all actors
3931 oldGrid->DeepCopy(UGrid);
3933 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
3934 //NewMapper->SetInput( UGrid );
3935 NewMapper->SetInput( oldGrid );
3936 NewMapper->Update();
3938 //ac->DataSource = NewMapper->GetInput();
3939 ac->SetMapper( NewMapper );
3941 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3943 QApplication::restoreOverrideCursor();
3947 //=============================================================================
3951 //=============================================================================
3952 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3954 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3957 QApplication::setOverrideCursor( Qt::waitCursor );
3958 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3959 Standard_Boolean result;
3961 SMESH_Actor* ac = FindActor( aMesh, result, true );
3963 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3964 SMESH_Grid* UGrid = SMESH_Grid::New();
3965 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3966 gf->SetInput( ac->DataSource );
3968 vtkExtractEdges *edges = vtkExtractEdges::New();
3969 edges->SetInput( ac->DataSource );
3971 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3972 Mapper->SetInput( edges->GetOutput() );
3975 int nb = Mapper->GetInput()->GetNumberOfCells();
3976 //MESSAGE ( "nb : " << nb )
3978 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3979 for ( ; ite.More(); ite.Next() ) {
3980 vtkCell* StartEdge = Mapper->GetInput()->GetCell(ite.Key());
3981 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
3982 int CellType = StartEdge->GetCellType();
3983 //MESSAGE( "DCQ : Cell Type = " << CellType)
3984 int nbPoints = StartEdge->GetNumberOfPoints();
3986 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
3987 if ( nbPoints == 2 ) {
3988 vtkUnstructuredGrid* StartUGrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
3990 vtkIdList *IdCells = vtkIdList::New();
3991 vtkIdList *IdPoints = StartEdge->GetPointIds();
3995 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),p1);
3996 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),p2);
3998 int idp1 = StartUGrid->FindPoint(p1);
3999 int idp2 = StartUGrid->FindPoint(p2);
4001 StartUGrid->GetPointCells( idp1, IdCells );
4003 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4004 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4006 //MESSAGE ( " pt 0 : " << idp1 )
4007 //MESSAGE ( " pt 1 : " << idp2 )
4009 vtkIdList *IdPts = vtkIdList::New();
4010 if (IdCells->GetNumberOfIds() >= 2) {
4011 int nbCells = IdCells->GetNumberOfIds();
4012 //MESSAGE ( " nbCells : " << nbCells )
4013 for (int j=0; j<nbCells; j++) {
4014 StartUGrid->GetCellPoints( IdCells->GetId(j), IdPts );
4015 if ( IdPts->IsId( idp2 ) == -1 ) {
4016 IdCells->DeleteId( IdCells->GetId(j) );
4021 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4023 vtkIdList *IdPts0 = vtkIdList::New();
4024 vtkIdList *IdPts1 = vtkIdList::New();
4026 if (IdCells->GetNumberOfIds() == 2) {
4027 StartUGrid->GetCellPoints( IdCells->GetId(0), IdPts0 );
4028 StartUGrid->GetCellPoints( IdCells->GetId(1), IdPts1 );
4031 TColStd_MapOfInteger EndMapIndex;
4032 for (int j = 0; j < 3; j++ ) {
4033 if ( IdPts0->GetId(j) != idp1 && IdPts0->GetId(j) != idp2 ) {
4034 EndMapIndex.Add( IdPts0->GetId(j) );
4036 if ( IdPts1->GetId(j) != idp1 && IdPts1->GetId(j) != idp2 ) {
4037 EndMapIndex.Add( IdPts1->GetId(j) );
4041 bool MyAU = myAutomaticUpdate ;
4042 myAutomaticUpdate = false ;
4044 EndMapIndex.Add( idp1 );
4045 TColStd_MapIteratorOfMapOfInteger ite1( EndMapIndex );
4047 while ( ite1.More() ) {
4048 if ( ite1.Key() == idp1 )
4053 bool reverse1 = ( i == 2 );
4054 this->AddFace( aMesh, EndMapIndex, reverse1 );
4056 EndMapIndex.Remove( idp1 );
4057 EndMapIndex.Add( idp2 );
4058 TColStd_MapIteratorOfMapOfInteger ite2( EndMapIndex );
4060 while ( ite2.More() ) {
4061 if ( ite2.Key() == idp2 )
4066 bool reverse2 = ( i == 2 );
4067 this->AddFace( aMesh, EndMapIndex, !(reverse1 == reverse2) );
4069 myAutomaticUpdate = MyAU ;
4070 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4073 TColStd_MapOfInteger StartMapIndex;
4074 StartMapIndex.Add( IdCells->GetId(0) );
4075 StartMapIndex.Add( IdCells->GetId(1) );
4076 this->RemoveElements( aMesh, StartMapIndex );
4084 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4085 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4086 // for ( int i = 0; i < nbCells; i++ ) {
4087 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4090 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4091 // NewMapper->SetInput( UGrid );
4092 // NewMapper->Update();
4094 // ac->DataSource = NewMapper->GetInput();
4095 // ac->SetMapper( NewMapper );
4097 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4099 QApplication::restoreOverrideCursor();
4103 //=============================================================================
4107 //=============================================================================
4108 void SMESHGUI::AddEdges( SMESH_Actor* Mactor, int number,
4109 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4111 QApplication::setOverrideCursor( Qt::waitCursor );
4112 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4113 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4116 while ( i <= number ) {
4117 vtkIdList *Ids = vtkIdList::New();
4118 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4119 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4120 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4121 Mactor->AddElement( indexes[j-1], id );
4125 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4126 EdgeMapper->SetInput( ugrid );
4127 Mactor->DataSource = EdgeMapper->GetInput();
4128 Mactor->SetMapper(EdgeMapper);
4129 QApplication::restoreOverrideCursor();
4132 //=============================================================================
4136 //=============================================================================
4137 void SMESHGUI::AddEdge(SMESH_Actor* Mactor, int idedge, int idnode1, int idnode2)
4139 QApplication::setOverrideCursor( Qt::waitCursor );
4140 MESSAGE ( "SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" << idnode2 )
4141 vtkIdList *Ids = vtkIdList::New();
4142 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4143 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4145 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4146 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4147 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4148 Mactor->AddElement( idedge, id );
4150 MESSAGE ( " Edge VTK id " << id )
4152 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4153 EdgeMapper->SetInput( ugrid );
4154 Mactor->DataSource = EdgeMapper->GetInput();
4155 Mactor->SetMapper(EdgeMapper);
4156 QApplication::restoreOverrideCursor();
4159 //=============================================================================
4163 //=============================================================================
4164 void SMESHGUI::AddTriangles( SMESH_Actor* Mactor, int number,
4165 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4167 QApplication::setOverrideCursor( Qt::waitCursor );
4168 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4169 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4172 while ( i <= number ) {
4173 vtkIdList *Ids = vtkIdList::New();
4174 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4175 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4176 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4177 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4178 Mactor->AddElement( indexes[j-1], id );
4182 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4183 TriMapper->SetInput( ugrid );
4184 Mactor->DataSource = TriMapper->GetInput();
4185 Mactor->SetMapper(TriMapper);
4186 QApplication::restoreOverrideCursor();
4188 void SMESHGUI::AddTriangle(SMESH_Actor* Mactor, int idtri, int idnode1, int idnode2, int idnode3)
4190 QApplication::setOverrideCursor( Qt::waitCursor );
4191 vtkIdList *Ids = vtkIdList::New();
4192 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4193 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4194 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4196 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4197 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4198 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4199 Mactor->AddElement( idtri, id );
4201 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4202 TriMapper->SetInput( ugrid );
4203 Mactor->DataSource = TriMapper->GetInput();
4204 Mactor->SetMapper(TriMapper);
4205 QApplication::restoreOverrideCursor();
4208 //=============================================================================
4212 //=============================================================================
4213 void SMESHGUI::AddQuadrangles( SMESH_Actor* Mactor, int number,
4214 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4216 QApplication::setOverrideCursor( Qt::waitCursor );
4217 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4218 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4221 while ( i <= number ) {
4222 vtkIdList *Ids = vtkIdList::New();
4223 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4224 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4225 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4226 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4227 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4228 Mactor->AddElement( indexes[j-1], id );
4232 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4233 QuadMapper->SetInput( ugrid );
4234 Mactor->DataSource = QuadMapper->GetInput();
4235 Mactor->SetMapper(QuadMapper);
4236 QApplication::restoreOverrideCursor();
4240 //=============================================================================
4244 //=============================================================================
4245 void SMESHGUI::AddQuadrangle(SMESH_Actor* Mactor, int idquad, int idnode1, int idnode2,
4246 int idnode3, int idnode4)
4248 QApplication::setOverrideCursor( Qt::waitCursor );
4249 vtkIdList *Ids = vtkIdList::New();
4250 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4251 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4252 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4253 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4255 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4256 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4257 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4258 Mactor->AddElement( idquad, id );
4260 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4261 QuadMapper->SetInput( ugrid );
4262 Mactor->DataSource = QuadMapper->GetInput();
4263 Mactor->SetMapper(QuadMapper);
4264 QApplication::restoreOverrideCursor();
4268 //=============================================================================
4272 //=============================================================================
4273 void SMESHGUI::AddTetras( SMESH_Actor* Mactor, int number,
4274 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4276 QApplication::setOverrideCursor( Qt::waitCursor );
4277 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4278 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4281 while ( i <= number ) {
4282 vtkIdList *Ids = vtkIdList::New();
4283 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4284 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4285 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4286 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4287 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4288 Mactor->AddElement( indexes[j-1], id );
4292 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4293 TetraMapper->SetInput( ugrid );
4294 Mactor->DataSource = TetraMapper->GetInput();
4295 Mactor->SetMapper(TetraMapper);
4296 QApplication::restoreOverrideCursor();
4300 //=============================================================================
4304 //=============================================================================
4305 void SMESHGUI::AddTetra(SMESH_Actor* Mactor, int idtetra, int idnode1, int idnode2,
4306 int idnode3, int idnode4)
4308 QApplication::setOverrideCursor( Qt::waitCursor );
4309 MESSAGE ( "SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" << idnode2
4310 << ";" << idnode3 << ";" << idnode4 )
4311 vtkIdList *Ids = vtkIdList::New();
4312 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4313 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4314 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4315 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4317 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4318 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4319 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4320 Mactor->AddElement( idtetra, id );
4322 MESSAGE ( " Tetra VTK id " << id )
4324 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4325 TetraMapper->SetInput( ugrid );
4326 Mactor->DataSource = TetraMapper->GetInput();
4327 Mactor->SetMapper(TetraMapper);
4328 QApplication::restoreOverrideCursor();
4332 //=============================================================================
4336 //=============================================================================
4337 void SMESHGUI::AddHexaedres( SMESH_Actor* Mactor, int number,
4338 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4340 QApplication::setOverrideCursor( Qt::waitCursor );
4341 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4342 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4345 while ( i <= number ) {
4346 vtkIdList *Ids = vtkIdList::New();
4347 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4348 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4349 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4350 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4351 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+4] ) );
4352 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+5] ) );
4353 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+6] ) );
4354 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+7] ) );
4355 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4356 Mactor->AddElement( indexes[j-1], id );
4360 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4361 HexaMapper->SetInput( ugrid );
4362 Mactor->DataSource = HexaMapper->GetInput();
4363 Mactor->SetMapper(HexaMapper);
4364 QApplication::restoreOverrideCursor();
4368 //=============================================================================
4372 //=============================================================================
4373 void SMESHGUI::AddHexaedre(SMESH_Actor* Mactor, int idhexa, int idnode1, int idnode2,
4374 int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
4376 QApplication::setOverrideCursor( Qt::waitCursor );
4377 MESSAGE ( "SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" << idnode2
4378 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" << idnode6
4379 << ";" << idnode7 << ";" << idnode8)
4381 vtkIdList *Ids = vtkIdList::New();
4382 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4383 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4384 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4385 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4386 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode5 ) );
4387 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode6 ) );
4388 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode7 ) );
4389 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode8 ) );
4391 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4392 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4393 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4394 Mactor->AddElement( idhexa, id );
4396 MESSAGE ( " Hexa VTK id " << id )
4398 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4399 HexaMapper->SetInput( ugrid );
4400 Mactor->DataSource = HexaMapper->GetInput();
4401 Mactor->SetMapper(HexaMapper);
4402 QApplication::restoreOverrideCursor();
4405 //=====================================================================================
4407 //=====================================================================================
4410 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
4412 return SMESHGUI::OnGUIEvent(theCommandID, parent);
4415 bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4417 return SMESHGUI::OnKeyPress (pe, parent, studyFrame);
4420 bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4422 return SMESHGUI::OnMousePress (pe, parent, studyFrame);
4425 bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4427 return SMESHGUI::OnMouseMove (pe, parent, studyFrame);
4430 bool SetSettings ( QAD_Desktop* parent )
4432 return SMESHGUI::SetSettings( parent );
4435 bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
4436 const QString & theParent, const QString & theObject )
4438 return SMESHGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
4441 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
4443 SMESHGUI::DefinePopup( theContext, theParent, theObject );
4446 bool activeStudyChanged ( QAD_Desktop* parent )
4448 SMESHGUI::activeStudyChanged( parent );
4451 void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
4453 SMESHGUI::BuildPresentation(theIO);
4456 void supportedViewType(int* buffer, int bufferSize)
4458 if (!buffer || !bufferSize) return;
4459 buffer[0] = (int)VIEW_VTK;
4465 //=============================================================================
4469 //=============================================================================
4470 void SMESHGUI::ViewNodes()
4472 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4475 EraseSimulationActors();
4476 mySimulationActors = vtkActorCollection::New();
4477 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4478 vtkActorCollection* theActors = theRenderer->GetActors();
4479 theActors->InitTraversal();
4480 vtkActor *ac = theActors->GetNextActor();
4481 while(!(ac==NULL)) {
4482 if ( ac->IsA("SMESH_Actor") ) {
4483 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
4484 if ( anActor->GetVisibility() == 1 ) {
4485 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4486 gf->SetInput( anActor->DataSource );
4487 vtkMaskPoints *verts = vtkMaskPoints::New();
4488 verts->SetInput(gf->GetOutput());
4489 verts->GenerateVerticesOn();
4490 verts->SetOnRatio(1);
4492 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4493 vertMapper->SetInput(verts->GetOutput());
4494 vertMapper->ScalarVisibilityOff();
4496 vtkActor *vertActor = vtkActor::New();
4497 vertActor->SetMapper(vertMapper);
4500 anActor->GetNodeColor(r, g, b ) ;
4501 vertActor->GetProperty()->SetColor( r, g, b ) ;
4503 vertActor->GetProperty()->SetPointSize( anActor->GetNodeSize() );
4505 vertActor->PickableOff();
4507 mySimulationActors->AddItem( vertActor );
4508 theRenderer->AddActor( vertActor );
4511 ac = theActors->GetNextActor();
4514 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4519 //=============================================================================
4523 //=============================================================================
4524 void SMESHGUI::Control(int theCommandID)
4526 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4529 QApplication::setOverrideCursor( Qt::waitCursor );
4530 DisplayScalarBar( false );
4532 vtkScalars *scalars = vtkScalars::New();
4533 vtkDataSetMapper* meshMapper = 0;
4534 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4535 int nbSel = Sel->IObjectCount();
4536 Standard_Boolean result;
4537 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
4538 SMESH_Actor* MeshActor = FindActorByEntry(IObject->getEntry(), result, true);
4540 // Mesh may be not updated after Compute
4541 if (!MeshActor->DataSource || !MeshActor->GetMapper()) {
4542 QApplication::restoreOverrideCursor();
4546 bool ValidateScalars = false;
4549 switch (theCommandID)
4551 case 6001: //Length Edges
4553 type = tr( "SMESH_CONTROL_LENGTH_EDGES");
4554 meshMapper = (vtkDataSetMapper*)MeshActor->EdgeDevice->GetMapper();
4555 vtkUnstructuredGrid* grid = (vtkUnstructuredGrid*)meshMapper->GetInput();
4556 MESSAGE ( " init minimum length " << grid->GetNumberOfCells() )
4557 for (int i=0; i<grid->GetNumberOfCells(); i++ ) {
4558 vtkCell* cell = grid->GetCell(i);
4559 float len = SMESHGUI_ComputeScalarValue::LengthEdges(cell);
4560 if (len == 0) continue;
4562 ValidateScalars = true;
4563 scalars->InsertScalar(i,len);
4566 if (ValidateScalars && (MeshActor->getDisplayMode()!=0))
4567 ChangeRepresentation( MeshActor, 1 );// limitation; in Wireframe, colored edges are not visible
4570 case 6011: // Area Elements
4572 type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
4573 for (int i=0; i< MeshActor->GetMapper()->GetInput()->GetNumberOfCells(); i++ ) {
4574 vtkCell* cell = MeshActor->GetMapper()->GetInput()->GetCell(i);
4575 float area = SMESHGUI_ComputeScalarValue::AreaElements(cell);
4576 if (area == 0) continue;
4578 ValidateScalars = true;
4579 scalars->InsertScalar(i,area);
4582 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4583 ChangeRepresentation( MeshActor, 1 );
4588 type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
4589 for (int i=0; i< MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4590 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4591 float taper = SMESHGUI_ComputeScalarValue::Taper(cell);
4592 if (taper == 0) continue;
4594 ValidateScalars = true;
4595 scalars->InsertScalar(i,taper);
4600 case 6013: // Aspect ratio
4602 type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
4603 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4604 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4605 float aspect = SMESHGUI_ComputeScalarValue::AspectRatio(cell);
4606 if (aspect == 0) continue;
4608 ValidateScalars = true;
4609 scalars->InsertScalar(i,aspect);
4612 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4613 ChangeRepresentation( MeshActor, 1 );
4616 case 6014: // Minimum angle
4618 type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
4619 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4620 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4621 float angle = SMESHGUI_ComputeScalarValue::MinimumAngle(cell);
4622 if (angle == 0) continue;
4624 ValidateScalars = true;
4625 scalars->InsertScalar(i,angle);
4628 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4629 ChangeRepresentation( MeshActor, 1 );
4634 type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
4635 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4636 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4637 float Warp = SMESHGUI_ComputeScalarValue::Warp(cell);
4638 if (Warp == 0) continue;
4640 ValidateScalars = true;
4641 scalars->InsertScalar(i,Warp);
4648 type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
4649 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4650 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4651 float angle = SMESHGUI_ComputeScalarValue::Skew(cell);
4652 if (angle == 0) continue;
4654 ValidateScalars = true;
4655 scalars->InsertScalar(i,angle);
4662 if ( !ValidateScalars ) {
4663 QApplication::restoreOverrideCursor();
4668 scalars->GetRange(range);
4670 vtkLookupTable* wat = vtkLookupTable::New();
4671 wat->SetRange( range );
4674 scalars->SetLookupTable(wat);
4676 if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
4677 meshMapper->SetScalarModeToUseCellData();
4678 meshMapper->GetInput()->GetCellData()->SetScalars(scalars);
4679 meshMapper->SetScalarRange( range );
4680 meshMapper->ScalarVisibilityOn();
4682 vtkScalarBarActor* aScalarBar = GetScalarBar();
4683 if ( aScalarBar == NULL ) {
4684 aScalarBar = vtkScalarBarActor::New();
4685 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
4686 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
4687 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
4688 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
4689 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
4690 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
4691 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
4692 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
4693 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
4695 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily, Orientation,
4696 Width, Height, NumberOfColors, NumberOfLabels);
4697 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4698 theRenderer->AddActor2D(aScalarBar);
4700 aScalarBar->SetLookupTable( wat );
4701 aScalarBar->SetTitle( type.latin1() );
4705 DisplayScalarBar( true );
4707 QApplication::restoreOverrideCursor();
4711 //=============================================================================
4715 //=============================================================================
4716 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
4717 QString Bold, QString Italic,
4718 QString Shadow, QString FontFamily,
4719 QString Orientation, float Width, float Height,
4720 int NbColors, int NbLabels )
4722 if ( Bold.isNull() || Bold.isEmpty() || (Bold.compare( "true" ) == 0) )
4723 theScalarBar->BoldOn();
4725 theScalarBar->BoldOff();
4727 if ( Italic.isNull() || Italic.isEmpty() || (Italic.compare( "true" ) == 0) )
4728 theScalarBar->ItalicOn();
4730 theScalarBar->ItalicOff();
4732 if ( Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare( "true" ) == 0) )
4733 theScalarBar->ShadowOn();
4735 theScalarBar->ShadowOff();
4737 if ( FontFamily.compare( "Arial" ) == 0 )
4738 theScalarBar->SetFontFamilyToArial();
4739 else if ( FontFamily.compare( "Courier" ) == 0 )
4740 theScalarBar->SetFontFamilyToCourier();
4741 else if ( FontFamily.compare( "Times" ) == 0 )
4742 theScalarBar->SetFontFamilyToTimes();
4744 theScalarBar->SetFontFamilyToArial();
4746 if ( Orientation.isNull() || Orientation.isEmpty() || (Orientation.compare( "Vertical" ) == 0) )
4747 theScalarBar->SetOrientationToVertical();
4749 theScalarBar->SetOrientationToHorizontal();
4752 theScalarBar->SetWidth((Width == 0)? 0.17 : Width);
4753 theScalarBar->SetHeight((Height == 0)? 0.8 : Height);
4755 theScalarBar->SetNumberOfLabels((NbLabels == 0)? 5 : NbLabels);
4756 theScalarBar->SetMaximumNumberOfColors((NbColors == 0)? 64 : NbColors);
4760 //=============================================================================
4764 //=============================================================================
4765 void SMESHGUI::DisplayScalarBar(bool visibility)
4767 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4770 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4771 vtkScalarBarActor* aScalarBar = GetScalarBar();
4773 if ( aScalarBar == NULL ) {
4774 MESSAGE("myScalarBar is NULL");
4779 aScalarBar->VisibilityOn();
4781 aScalarBar->VisibilityOff();
4782 //Turn off mesh coloring (influences on all views)
4783 vtkActorCollection* actorList=theRenderer->GetActors();
4784 actorList->InitTraversal();
4785 vtkActor *ac = actorList->GetNextActor();
4787 if (ac->GetMapper() != NULL) {
4788 ac->GetMapper()->ScalarVisibilityOff();
4790 ac = actorList->GetNextActor();
4792 // Turn off ScalarBar in all views
4793 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
4794 for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
4795 if (aFrame->getTypeView() == VIEW_VTK) {
4796 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
4797 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
4798 actor2DList->InitTraversal();
4799 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
4800 while (aActor2d != NULL) {
4801 if (aActor2d->IsA("vtkScalarBarActor")) {
4802 aActor2d->VisibilityOff();
4805 actor2DList->GetNextActor2D();
4810 myActiveStudy->update3dViewers();
4814 //=============================================================================
4818 //=============================================================================
4819 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
4821 vtkScalarBarActor* aScalarBar = GetScalarBar();
4822 if ( aScalarBar == NULL ) {
4823 MESSAGE("myScalarBar is NULL");
4826 DisplayScalarBar(false);
4828 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
4829 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4830 vtkActorCollection* aActorList = aRenderer->GetActors();
4831 aActorList->InitTraversal();
4832 vtkActor *aActor = aActorList->GetNextActor();
4833 while(aActor != NULL) {
4834 if (aActor->IsA("SMESH_Actor")) {
4835 SMESH_Actor* aMeshActor = SMESH_Actor::SafeDownCast(aActor);
4836 vtkDataSetMapper* aMeshMapper = (vtkDataSetMapper*) (aMeshActor->getMapper());
4837 if ((aMeshMapper != NULL)) {
4838 aMeshMapper->SetScalarRange( MinRange, MaxRange );
4839 aMeshMapper->ScalarVisibilityOn();
4842 aActor = aActorList->GetNextActor();
4844 DisplayScalarBar(true);
4848 //=============================================================================
4852 //=============================================================================
4853 void SMESHGUI::SetDisplaySettings()
4855 EmitSignalDeactivateDialog() ;
4856 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "") ;
4858 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
4859 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
4860 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
4861 QColor color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4862 aDlg->SetColor(1,color);
4864 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
4865 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
4866 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4867 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4868 aDlg->SetColor(2,color);
4870 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4871 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4872 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4873 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4874 aDlg->SetColor(3,color);
4876 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4877 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4878 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4879 color = QColor (SBr.toInt(), SBg.toInt(), SBb.toInt());
4880 aDlg->SetColor(4,color);
4882 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4883 aDlg->SetIntValue(1,intValue.toInt());
4884 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4885 aDlg->SetIntValue(2,intValue.toInt());
4886 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4887 aDlg->SetIntValue(3,intValue.toInt());
4889 if ( aDlg->exec() ) {
4890 QColor colorFill = aDlg->GetColor( 1 );
4891 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4892 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4893 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4895 QColor colorOutline = aDlg->GetColor( 2 );
4896 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4897 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4898 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4900 QColor colorNode = aDlg->GetColor( 3 );
4901 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4902 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4903 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4905 QColor colorBackFace = aDlg->GetColor( 4 );
4906 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4907 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4908 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4910 int width = aDlg->GetIntValue( 1 );
4911 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4913 int nodes_size = aDlg->GetIntValue( 2 );
4914 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4916 int shrink_coeff = aDlg->GetIntValue( 3 );
4917 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4923 //=======================================================================
4924 // function : Parameter()
4925 // purpose : return a parameter (double) from a dialog box
4927 // aValue : is a double used as a default value displayed
4928 // aLabel : is the title for aValue1
4929 // aTitle : is the main title
4930 // bottom : maximum value to be entered
4931 // top : minimum value to be entered
4932 // decimals : number of decimals
4933 //=======================================================================
4934 double SMESHGUI::Parameter( Standard_Boolean& res,
4935 const double aValue,
4938 const double bottom,
4940 const int decimals )
4942 SMESHGUI_aParameterDlg* Dialog =
4943 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4946 bottom, top, decimals,
4948 Dialog->setValue( aValue );
4950 res = ( Dialog->exec() == QDialog::Accepted );
4952 X = Dialog->getDblValue();
4956 //=======================================================================
4957 // function : Parameter()
4958 // purpose : return a parameter (int) from a dialog box
4960 // aValue : is a int used as a default value displayed
4961 // aLabel : is the title for aValue1
4962 // aTitle : is the main title
4963 // bottom : maximum value to be entered
4964 // top : minimum value to be entered
4965 //=======================================================================
4966 int SMESHGUI::Parameter( Standard_Boolean& res,
4973 SMESHGUI_aParameterDlg* Dialog =
4974 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4979 Dialog->setValue( aValue );
4981 res = ( Dialog->exec() == QDialog::Accepted );
4983 X = Dialog->getIntValue();
4987 //=============================================================================
4991 //=============================================================================
4992 void SMESHGUI::DisplayEdges(SMESH_Actor* ac, bool visibility)
4994 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4996 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
4999 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5000 gf->SetInput(ac->DataSource);
5001 vtkFeatureEdges *edges = vtkFeatureEdges::New();
5002 edges->SetInput(gf->GetOutput());
5003 edges->BoundaryEdgesOn();
5004 edges->ManifoldEdgesOn();
5006 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5007 edgeMapper->SetInput(edges->GetOutput());
5008 edgeMapper->ScalarVisibilityOff();
5010 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5011 vtkActorCollection* actorList=theRenderer->GetActors();
5013 int test=actorList->IsItemPresent(ac->EdgeDevice);
5015 vtkProperty* prop = vtkProperty::New();
5016 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5017 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5018 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5019 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5020 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5021 ac->EdgeDevice->SetProperty(prop);
5022 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5023 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5024 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5025 ac->EdgeDevice->SetMapper(edgeMapper);
5027 theRenderer->AddActor(ac->EdgeDevice);
5029 ac->EdgeDevice->SetMapper(edgeMapper);
5030 edgeMapper->Update();
5033 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5034 shrink->SetInput(ac->DataSource);
5035 shrink->SetShrinkFactor(ac->GetShrinkFactor());
5036 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5037 Shrinkgf->SetInput( shrink->GetOutput() );
5038 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5039 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5040 ShrinkEdges->BoundaryEdgesOn();
5041 ShrinkEdges->ManifoldEdgesOn();
5043 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5044 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5045 ShrinkEdgeMapper->ScalarVisibilityOff();
5047 test=actorList->IsItemPresent(ac->EdgeShrinkDevice);
5049 vtkProperty* prop = vtkProperty::New();
5050 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5051 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5052 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5053 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5054 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5055 ac->EdgeShrinkDevice->SetProperty(prop);
5056 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5057 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5058 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5059 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5061 theRenderer->AddActor(ac->EdgeShrinkDevice);
5063 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5064 ShrinkEdgeMapper->Update();
5067 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5072 //=============================================================================
5076 //=============================================================================
5077 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5079 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh( aMesh );
5080 SALOMEDS::GenericAttribute_var anAttr;
5081 SALOMEDS::AttributeName_var aName;
5082 if ( !aSO_M->_is_nil() ) {
5083 if (aSO_M->FindAttribute(anAttr, "AttributeName") ) {
5084 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5085 Standard_Boolean result;
5086 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5088 SMESH_Actor* amesh = SMESH_Actor::New();
5089 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(aSO_M->GetID(),
5093 amesh->setName( aName->Value() );
5094 DisplayActor(amesh, false);
5101 //=============================================================================
5105 //=============================================================================
5106 void SMESHGUI::Update()
5108 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
5109 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5111 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5112 int nbSel = Sel->IObjectCount();
5114 vtkActorCollection* actorList=theRenderer->GetActors();
5115 actorList->InitTraversal();
5116 vtkActor *ac = actorList->GetNextActor();
5117 while(!(ac==NULL)) {
5118 if ( ac->IsA("SMESH_Actor") ) {
5119 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5120 if ( anActor->hasIO() ) {
5121 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5125 ac = actorList->GetNextActor();
5128 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5129 for ( ; It.More(); It.Next() ) {
5130 Handle(SALOME_InteractiveObject) IO = It.Value();
5134 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5137 QApplication::restoreOverrideCursor();
5141 //=============================================================================
5145 //=============================================================================
5146 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject)& IO)
5148 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5151 if ( IO->hasEntry() ) {
5152 Standard_Boolean res;
5153 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh( IO, res );
5155 SMESH_Actor* ac = FindActorByEntry( IO->getEntry(), res, false );
5157 // Check whether the actor belongs to the active view
5158 VTKViewer_RenderWindowInteractor* rwInter =
5159 ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5161 // The actor belongs to inactive view -> create a copy and display it in the active view
5162 if (!rwInter->isInViewer(IO)) {
5163 SMESH_Actor* acCopy = SMESH_Actor::New();
5164 acCopy->ShallowCopy(ac);
5166 smeshGUI->DisplayActor( acCopy, false );
5168 ac = ReadScript( aMesh );
5175 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
5183 //=============================================================================
5187 //=============================================================================
5188 vtkActor* SMESHGUI::SimulationMoveNode(SMESH_Actor* Mactor, int idnode)
5190 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5193 mySimulationActors = vtkActorCollection::New();
5194 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5196 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5197 vtkIdList *IdCells = vtkIdList::New();
5198 ugrid->GetPointCells( idnode, IdCells );
5200 vtkPoints *Pts = vtkPoints::New();
5201 Pts = ugrid->GetPoints();
5203 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
5204 ugridSimulation->SetPoints( Pts );
5205 vtkIdList *IdPts = vtkIdList::New();
5206 for (int j=0; j<IdCells->GetNumberOfIds(); j++) {
5207 ugrid->GetCellPoints( IdCells->GetId(j), IdPts );
5208 ugridSimulation->InsertNextCell( ugrid->GetCellType( IdCells->GetId(j) ), IdPts );
5211 vtkProperty* prop = vtkProperty::New();
5212 prop->SetColor( 1., 0., 0. );
5213 prop->SetRepresentationToWireframe();
5215 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
5216 if ( Edgewidth == 0 )
5218 prop->SetLineWidth( Edgewidth+1 );
5220 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5221 Mapper->SetInput( ugridSimulation );
5222 vtkActor* ac = vtkActor::New();
5223 ac->SetMapper( Mapper );
5224 ac->SetProperty( prop );
5226 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
5227 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
5229 mySimulationActors->AddItem( ac );
5230 theRenderer->AddActor( ac );
5232 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5239 //=============================================================================
5243 //=============================================================================
5244 void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5246 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5249 EraseSimulationActors();
5250 mySimulationActors = vtkActorCollection::New();
5251 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5252 Standard_Boolean result;
5253 SMESH_Actor* ac = FindActor( aMesh, result, true );
5256 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5257 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5259 vtkPoints *Pts = ugrid->GetPoints();
5260 vtkPoints *newPts = vtkPoints::New();
5261 int nbPts = Pts->GetNumberOfPoints();
5262 for ( int i = 0; i < nbPts; i++ ) {
5263 newPts->InsertPoint(i, Pts->GetPoint(i) );
5266 newugrid->SetPoints(newPts);
5267 newugrid->GetPoints()->InsertNextPoint( x, y, z );
5269 vtkMaskPoints* verts = vtkMaskPoints::New();
5270 verts->SetInput(newugrid);
5271 verts->SetGenerateVertices(1);
5272 verts->SetOnRatio(1);
5274 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
5275 vertMapper->SetInput( verts->GetOutput() );
5276 vertMapper->ScalarVisibilityOff();
5278 vtkActor* node = vtkActor::New();
5279 node->SetMapper( vertMapper );
5281 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5282 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5283 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5284 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5285 if ( !nodecolor.isValid() )
5286 nodecolor = QColor(0.,1.,0.);
5288 node->GetProperty()->SetColor( float(nodecolor.red())/255.,
5289 float(nodecolor.green())/255.,
5290 float(nodecolor.blue())/255.);
5292 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
5296 node->GetProperty()->SetPointSize( intValue );
5298 node->VisibilityOn();
5300 mySimulationActors->AddItem( node );
5301 theRenderer->AddActor(node);
5304 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5308 //=============================================================================
5312 //=============================================================================
5313 void SMESHGUI::DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z)
5315 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5318 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5319 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
5320 pt[0] = x; pt[1] = y; pt[2] = z;
5322 ac->GetMapper()->ImmediateModeRenderingOn();
5323 ac->GetProperty()->SetRepresentationToWireframe();
5325 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5331 //=============================================================================
5335 //=============================================================================
5336 void SMESHGUI::MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z)
5338 Standard_Boolean result;
5340 SMESH_Actor* MeshActor = FindActor(aMesh, result, true);
5346 //=============================================================================
5350 //=============================================================================
5351 void SMESHGUI::ScalarVisibilityOff()
5353 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5356 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5357 vtkActorCollection* actorList=theRenderer->GetActors();
5359 actorList->InitTraversal();
5360 vtkActor *ac = actorList->GetNextActor();
5361 while(!(ac==NULL)) {
5362 if ( ac->IsA("SMESH_Actor") ) {
5363 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5364 if ( anActor->GetVisibility() == 1 ) {
5365 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (anActor->getMapper());
5366 meshMapper->ScalarVisibilityOff();
5367 meshMapper->SetInput( anActor->DataSource );
5368 ChangeRepresentation( anActor, anActor->getDisplayMode() );
5371 ac = actorList->GetNextActor();
5374 theRenderer->Render();
5378 //=============================================================================
5382 //=============================================================================
5383 void SMESHGUI::DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5385 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5388 EraseSimulationActors();
5389 mySimulationActors = vtkActorCollection::New();
5390 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5391 Standard_Boolean result;
5392 SMESH_Actor* ac = FindActor( aMesh, result, true );
5394 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5398 vtkIdList *Ids = vtkIdList::New();
5399 for ( ; ite.More(); ite.Next() ) {
5400 idNodes[i] = ite.Key();
5404 Ids->InsertId( 0, idNodes[0] );
5405 pts[0] = idNodes[0];
5406 Ids->InsertId( 1, idNodes[1] );
5407 pts[1] = idNodes[1];
5409 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5410 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5411 newugrid->SetPoints( ugrid->GetPoints() ) ;
5412 newugrid->InsertNextCell(VTK_LINE, 2, pts);
5414 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5415 Mapper->SetInput( newugrid );
5418 vtkActor* edge = vtkActor::New();
5419 edge->SetMapper( Mapper );
5420 edge->SetProperty( ac->GetProperty() );
5421 edge->SetBackfaceProperty( ac->GetBackfaceProperty() );
5422 edge->VisibilityOn();
5423 mySimulationActors->AddItem( edge );
5424 theRenderer->AddActor(edge);
5427 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5432 //=============================================================================
5436 //=============================================================================
5437 void SMESHGUI::DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5439 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5442 EraseSimulationActors();
5443 mySimulationActors = vtkActorCollection::New();
5444 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5445 Standard_Boolean result;
5446 SMESH_Actor* ac = FindActor( aMesh, result, true );
5448 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5452 vtkIdList *Ids = vtkIdList::New();
5453 for ( ; ite.More(); ite.Next() ) {
5454 idNodes[i] = ite.Key();
5459 Ids->InsertId( 0, idNodes[2] );
5460 pts[0] = idNodes[2];
5461 Ids->InsertId( 1, idNodes[1] );
5462 pts[1] = idNodes[1];
5463 Ids->InsertId( 2, idNodes[0] );
5464 pts[2] = idNodes[0];
5466 Ids->InsertId( 0, idNodes[0] );
5467 pts[0] = idNodes[0];
5468 Ids->InsertId( 1, idNodes[1] );
5469 pts[1] = idNodes[1];
5470 Ids->InsertId( 2, idNodes[2] );
5471 pts[2] = idNodes[2];
5473 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5474 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5475 newugrid->SetPoints( ugrid->GetPoints() ) ;
5476 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
5478 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5479 Mapper->SetInput( newugrid );
5482 vtkActor* tri = vtkActor::New();
5483 tri->SetMapper( Mapper );
5484 tri->SetProperty( ac->GetProperty() );
5485 tri->SetBackfaceProperty( ac->GetBackfaceProperty() );
5486 tri->VisibilityOn();
5487 mySimulationActors->AddItem( tri );
5488 theRenderer->AddActor(tri);
5491 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5496 //=============================================================================
5500 //=============================================================================
5501 void SMESHGUI::DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5503 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5506 EraseSimulationActors();
5507 mySimulationActors = vtkActorCollection::New();
5508 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5509 Standard_Boolean result;
5510 SMESH_Actor* ac = FindActor( aMesh, result, true );
5512 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5515 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5518 vtkIdList *Ids = vtkIdList::New();
5519 for ( ; ite.More(); ite.Next() ) {
5520 idNodes[i] = ite.Key();
5524 float *p0 = ugrid->GetPoint(idNodes[0]);
5525 float *p1 = ugrid->GetPoint(idNodes[1]);
5526 float *p2 = ugrid->GetPoint(idNodes[2]);
5527 float *p3 = ugrid->GetPoint(idNodes[3]);
5529 gp_Pnt P0(p0[0],p0[1],p0[2]);
5531 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5532 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5533 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5535 gp_Vec Cross1 = V1 ^ V2;
5536 gp_Vec Cross2 = V2 ^ V3;
5539 if ( Cross1.Dot(Cross2) < 0 ) {
5540 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5541 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5545 if ( Cross1.Dot(Cross2) < 0 ) {
5547 idNodes[2] = idNodes[3];
5551 idNodes[1] = idNodes[2];
5557 Ids->InsertId( 0, idNodes[3] );
5558 Ids->InsertId( 1, idNodes[2] );
5559 Ids->InsertId( 2, idNodes[1] );
5560 Ids->InsertId( 3, idNodes[0] );
5562 Ids->InsertId( 0, idNodes[0] );
5563 Ids->InsertId( 1, idNodes[1] );
5564 Ids->InsertId( 2, idNodes[2] );
5565 Ids->InsertId( 3, idNodes[3] );
5568 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5569 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5570 newugrid->SetPoints( ugrid->GetPoints() ) ;
5571 newugrid->InsertNextCell(VTK_QUAD, Ids);
5573 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5574 Mapper->SetInput( newugrid );
5577 vtkActor* quad = vtkActor::New();
5578 quad->SetMapper( Mapper );
5579 quad->SetProperty( ac->GetProperty() );
5580 quad->SetBackfaceProperty( ac->GetBackfaceProperty() );
5581 quad->VisibilityOn();
5582 mySimulationActors->AddItem( quad );
5583 theRenderer->AddActor(quad);
5585 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5590 //=============================================================================
5594 //=============================================================================
5595 void SMESHGUI::DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5597 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5600 EraseSimulationActors();
5601 mySimulationActors = vtkActorCollection::New();
5602 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5603 Standard_Boolean result;
5604 SMESH_Actor* ac = FindActor( aMesh, result, true );
5606 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5609 vtkIdList *Ids = vtkIdList::New();
5610 for ( ; ite.More(); ite.Next() ) {
5611 idNodes[i] = ite.Key();
5615 Ids->InsertId( 0, idNodes[0] );
5616 Ids->InsertId( 1, idNodes[1] );
5617 Ids->InsertId( 2, idNodes[2] );
5618 Ids->InsertId( 3, idNodes[3] );
5620 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5621 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5622 newugrid->SetPoints( ugrid->GetPoints() ) ;
5623 newugrid->InsertNextCell(VTK_TETRA, Ids);
5625 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5626 Mapper->SetInput( newugrid );
5629 vtkActor* tetra = vtkActor::New();
5630 tetra->SetMapper( Mapper );
5631 tetra->SetProperty( ac->GetProperty() );
5632 tetra->SetBackfaceProperty( ac->GetBackfaceProperty() );
5633 tetra->VisibilityOn();
5634 mySimulationActors->AddItem( tetra );
5635 theRenderer->AddActor(tetra);
5637 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5642 //=============================================================================
5646 //=============================================================================
5647 void SMESHGUI::DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5649 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5652 EraseSimulationActors();
5653 mySimulationActors = vtkActorCollection::New();
5654 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5655 Standard_Boolean result;
5656 SMESH_Actor* ac = FindActor( aMesh, result, true );
5658 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5661 vtkIdList *Ids = vtkIdList::New();
5662 for ( ; ite.More(); ite.Next() ) {
5663 idNodes[i] = ite.Key();
5667 Ids->InsertId( 0, idNodes[0] );
5668 Ids->InsertId( 1, idNodes[1] );
5669 Ids->InsertId( 2, idNodes[2] );
5670 Ids->InsertId( 3, idNodes[3] );
5671 Ids->InsertId( 4, idNodes[4] );
5672 Ids->InsertId( 5, idNodes[5] );
5673 Ids->InsertId( 6, idNodes[6] );
5674 Ids->InsertId( 7, idNodes[7] );
5676 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5677 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5678 newugrid->SetPoints( ugrid->GetPoints() ) ;
5679 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5681 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5682 Mapper->SetInput( newugrid );
5685 vtkActor* hexa = vtkActor::New();
5686 hexa->SetMapper( Mapper );
5687 hexa->SetProperty( ac->GetProperty() );
5688 hexa->SetBackfaceProperty( ac->GetBackfaceProperty() );
5689 hexa->VisibilityOn();
5690 mySimulationActors->AddItem( hexa );
5691 theRenderer->AddActor(hexa);
5693 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5698 //=============================================================================
5702 //=============================================================================
5703 void SMESHGUI::AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5705 QApplication::setOverrideCursor( Qt::waitCursor );
5706 Standard_Boolean result;
5707 SMESH_Actor* ac = FindActor( aMesh, result, true );
5709 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5710 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5711 anArrayOfIdeces->length(MapIndex.Extent());
5714 for ( ; ite.More(); ite.Next() ) {
5715 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5720 if ( MapIndex.Extent() == 4 ) {
5723 TColStd_MapIteratorOfMapOfInteger ite1( MapIndex );
5724 for ( ; ite1.More(); ite1.Next() ) {
5725 idNodes[i] = ite1.Key();
5729 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5730 float *p0 = ugrid->GetPoint(idNodes[0]);
5731 float *p1 = ugrid->GetPoint(idNodes[1]);
5732 float *p2 = ugrid->GetPoint(idNodes[2]);
5733 float *p3 = ugrid->GetPoint(idNodes[3]);
5735 gp_Pnt P0(p0[0],p0[1],p0[2]);
5737 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5738 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5739 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5741 gp_Vec Cross1 = V1 ^ V2;
5742 gp_Vec Cross2 = V2 ^ V3;
5744 if ( Cross1.Dot(Cross2) < 0 ) {
5746 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5747 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5751 if ( Cross1.Dot(Cross2) < 0 ) {
5752 tmp = anArrayOfIdeces[2];
5753 anArrayOfIdeces[2] = anArrayOfIdeces[3];
5754 anArrayOfIdeces[3] = tmp;
5756 tmp = anArrayOfIdeces[1];
5757 anArrayOfIdeces[1] = anArrayOfIdeces[2];
5758 anArrayOfIdeces[2] = tmp;
5765 for (i=0; i < (MapIndex.Extent()/2); i++) {
5766 tmp = anArrayOfIdeces[i];
5767 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent()-i-1];
5768 anArrayOfIdeces[MapIndex.Extent()-i-1] = tmp;
5771 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5772 aMeshEditor->AddFace(anArrayOfIdeces);
5774 if ( myAutomaticUpdate ) {
5775 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5776 if ( Mesh != NULL ) {
5777 smeshGUI->DisplayActor( Mesh );
5778 smeshGUI->DisplayEdges( Mesh );
5779 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5780 AddActorInSelection( Mesh );
5783 QApplication::restoreOverrideCursor();
5787 //=============================================================================
5791 //=============================================================================
5792 void SMESHGUI::AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5794 QApplication::setOverrideCursor( Qt::waitCursor );
5795 Standard_Boolean result;
5796 SMESH_Actor* ac = FindActor( aMesh, result, true );
5798 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5799 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5800 anArrayOfIdeces->length(MapIndex.Extent());
5803 for ( ; ite.More(); ite.Next() ) {
5804 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5808 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5809 aMeshEditor->AddVolume(anArrayOfIdeces);
5811 if ( myAutomaticUpdate ) {
5812 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5813 if ( Mesh != NULL ) {
5814 smeshGUI->DisplayActor( Mesh );
5815 smeshGUI->DisplayEdges( Mesh );
5816 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5817 AddActorInSelection( Mesh );
5820 QApplication::restoreOverrideCursor();
5824 //=============================================================================
5828 //=============================================================================
5829 void SMESHGUI::AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5831 QApplication::setOverrideCursor( Qt::waitCursor );
5832 Standard_Boolean result;
5833 SMESH_Actor* ac = FindActor( aMesh, result, true );
5835 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5836 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5837 anArrayOfIdeces->length(MapIndex.Extent());
5840 for ( ; ite.More(); ite.Next() ) {
5841 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5845 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5846 aMeshEditor->AddEdge(anArrayOfIdeces);
5848 if ( myAutomaticUpdate ) {
5849 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5850 if ( Mesh != NULL ) {
5851 smeshGUI->DisplayActor( Mesh );
5852 smeshGUI->DisplayEdges( Mesh );
5853 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5854 AddActorInSelection( Mesh );
5857 QApplication::restoreOverrideCursor();
5860 //=============================================================================
5864 //=============================================================================
5865 void SMESHGUI::AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5867 QApplication::setOverrideCursor( Qt::waitCursor );
5868 Standard_Boolean result;
5869 SMESH_Actor* ac = FindActor( aMesh, result, true );
5871 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5872 aMeshEditor->AddNode(x,y,z);
5874 if ( myAutomaticUpdate ) {
5875 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5876 if ( Mesh != NULL ) {
5877 smeshGUI->DisplayActor( Mesh );
5878 smeshGUI->DisplayEdges( Mesh );
5879 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5880 AddActorInSelection( Mesh );
5884 QApplication::restoreOverrideCursor();
5887 //=============================================================================
5891 //=============================================================================
5892 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor *ac)
5894 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5897 EraseSimulationActors();
5898 mySimulationActors2D = vtkActor2DCollection::New();
5900 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5902 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
5903 gs2->SetGlyphTypeToTriangle();
5906 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
5907 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
5908 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
5910 legend->SetNumberOfEntries(4);
5911 legend->SetEntryString( 0, tr( "SMESH_BOUNDARYEDGES" ) );
5912 legend->SetEntrySymbol( 0, gs2->GetOutput() );
5913 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.) );
5914 legend->SetEntryString( 1, tr( "SMESH_MANIFOLDEDGES" ) );
5915 legend->SetEntrySymbol( 1, gs2->GetOutput() );
5916 legend->SetEntryColor(1, ac->GetMapper()->GetLookupTable()->GetColor(0.666667) );
5917 legend->SetEntryString( 2, tr( "SMESH_NONMANIFOLDEDGES" ) );
5918 legend->SetEntrySymbol( 2, gs2->GetOutput() );
5919 legend->SetEntryColor(2, ac->GetMapper()->GetLookupTable()->GetColor(0.222222) );
5920 legend->SetEntryString( 3, tr( "SMESH_FEATUREEDGES" ) );
5921 legend->SetEntrySymbol( 3, gs2->GetOutput() );
5922 legend->SetEntryColor(3, ac->GetMapper()->GetLookupTable()->GetColor(0.444444) );
5923 legend->SetPadding( 5 );
5924 // legend->GetProperty()->SetColor();
5926 mySimulationActors2D->AddItem( legend );
5927 theRenderer->AddActor2D( legend );
5930 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5933 //===============================================================================
5934 // function : OnEditDelete()
5936 //===============================================================================
5937 void SMESHGUI::OnEditDelete()
5939 if ( QAD_MessageBox::warn2
5940 ( QAD_Application::getDesktop(),
5941 tr ("SMESH_WRN_WARNING"),
5942 tr ("SMESH_REALLY_DELETE"),
5943 tr ("SMESH_BUT_YES"), tr ("SMESH_BUT_NO"), 1, 0, 0 ) != 1 )
5946 int nbSf = myActiveStudy->getStudyFramesCount();
5948 Standard_Boolean found;
5949 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5950 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
5951 SALOMEDS::GenericAttribute_var anAttr;
5952 SALOMEDS::AttributeIOR_var anIOR;
5954 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5955 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5956 for(;It.More();It.Next()) {
5957 Handle(SALOME_InteractiveObject) IObject = It.Value();
5958 if ( IObject->hasEntry() ) {
5959 SALOMEDS::SObject_var SO = myStudy->FindObjectID( IObject->getEntry() );
5961 /* Erase child graphical objects */
5962 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5963 for (; it->More();it->Next()) {
5964 SALOMEDS::SObject_var CSO= it->Value();
5965 if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
5966 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5968 for ( int i = 0; i < nbSf; i++ ) {
5969 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5970 if ( sf->getTypeView() == VIEW_VTK ) {
5971 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5972 SMESH_Actor* ac = smeshGUI->FindActorByEntry( CSO->GetID(), found, false );
5974 Renderer->RemoveActor(ac->EdgeDevice);
5975 Renderer->RemoveActor(ac->EdgeShrinkDevice);
5976 Renderer->RemoveActor(ac);
5983 /* Erase main graphical object */
5984 for ( int i = 0; i < nbSf; i++ ) {
5985 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5986 if ( sf->getTypeView() == VIEW_VTK ) {
5987 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5988 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
5989 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), found, false );
5991 Renderer->RemoveActor(ac->EdgeDevice);
5992 Renderer->RemoveActor(ac->EdgeShrinkDevice);
5994 myRenderInter->Remove( IObject );
5998 /* Erase objects in Study */
5999 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
6000 if ( !obj->_is_nil() ) {
6001 QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
6003 aStudyBuilder->RemoveObject(obj);
6007 } /* IObject->hasEntry() */
6010 /* Clear any previous selection */
6011 Sel->ClearIObjects() ;
6012 myActiveStudy->updateObjBrowser();