1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI.cxx
25 // Author : Nicolas REJNERI
31 #include "SMESHGUI_AddHypothesisDlg.h"
32 #include "SMESHGUI_AddAlgorithmDlg.h"
33 #include "SMESHGUI_InitMeshDlg.h"
34 #include "SMESHGUI_LocalLengthDlg.h"
35 #include "SMESHGUI_NbSegmentsDlg.h"
36 #include "SMESHGUI_AddSubMeshDlg.h"
37 #include "SMESHGUI_NodesDlg.h"
38 #include "SMESHGUI_TransparencyDlg.h"
39 #include "SMESHGUI_RemoveNodesDlg.h"
40 #include "SMESHGUI_RemoveElementsDlg.h"
41 #include "SMESHGUI_MeshInfosDlg.h"
42 #include "SMESHGUI_Preferences_ColorDlg.h"
43 #include "SMESHGUI_MaxElementAreaDlg.h"
44 #include "SMESHGUI_MaxElementVolumeDlg.h"
45 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
46 #include "SMESHGUI_EditScalarBarDlg.h"
47 #include "SMESHGUI_aParameterDlg.h"
48 #include "SMESHGUI_ComputeScalarValue.h"
49 #include "SMESHGUI_MoveNodesDlg.h"
50 #include "SMESHGUI_OrientationElementsDlg.h"
51 #include "SMESHGUI_DiagonalInversionDlg.h"
52 #include "SMESHGUI_EdgesConnectivityDlg.h"
53 #include "SMESHGUI_AddFaceDlg.h"
54 #include "SMESHGUI_AddEdgeDlg.h"
55 #include "SMESHGUI_AddVolumeDlg.h"
56 #include "SMESHGUI_EditHypothesesDlg.h"
58 #include "SMESH_Grid.h"
61 #include "Utils_ORB_INIT.hxx"
62 #include "Utils_SINGLETON.hxx"
65 #include "QAD_Tools.h"
66 #include "QAD_Config.h"
67 #include "QAD_Settings.h"
68 #include "QAD_RightFrame.h"
69 #include "QAD_MessageBox.h"
70 #include "QAD_Resource.h"
71 #include "QAD_FileDlg.h"
72 #include "SALOMEGUI_Desktop.h"
73 #include "SALOMEGUI_NameDlg.h"
75 #include "OCCViewer_ViewPort.h"
76 #include "OCCViewer_ViewPort3d.h"
77 #include "OCCViewer_Viewer3d.h"
79 #include "GEOM_Client.hxx"
80 #include "GEOM_InteractiveObject.hxx"
82 #include "SALOME_NamingService.hxx"
83 #include "SALOME_ListIteratorOfListIO.hxx"
84 #include "SALOME_InteractiveObject.hxx"
86 #include "SALOMEGUI_ImportOperation.h"
87 #include "SALOMEGUI_QtCatchCorbaException.hxx"
88 #include "utilities.h"
90 #include "SMDS_Mesh.hxx"
91 #include "SMESHDS_Document.hxx"
92 #include "Document_Reader.h"
93 #include "Document_Writer.h"
94 #include "Mesh_Reader.h"
95 #include "Mesh_Writer.h"
97 #include "DriverDAT_R_SMESHDS_Document.h"
98 #include "DriverMED_R_SMESHDS_Document.h"
99 #include "DriverUNV_R_SMESHDS_Document.h"
100 #include "DriverDAT_W_SMESHDS_Document.h"
101 #include "DriverMED_W_SMESHDS_Document.h"
102 #include "DriverUNV_W_SMESHDS_Document.h"
103 #include "DriverDAT_R_SMESHDS_Mesh.h"
104 #include "DriverMED_R_SMESHDS_Mesh.h"
105 #include "DriverUNV_R_SMESHDS_Mesh.h"
106 #include "DriverDAT_W_SMESHDS_Mesh.h"
107 #include "DriverMED_W_SMESHDS_Mesh.h"
108 #include "DriverUNV_W_SMESHDS_Mesh.h"
111 #define INCLUDE_MENUITEM_DEF
112 #include <qapplication.h>
113 #include <qlineedit.h>
114 #include <qmenudata.h>
115 #include <qmenubar.h>
116 #include <qpopupmenu.h>
119 #include <qcheckbox.h>
120 #include <qcolordialog.h>
121 #include <qmessagebox.h>
122 #include <qspinbox.h>
126 #include <qradiobutton.h>
129 #include "VTKViewer_Common.h"
130 #include "VTKViewer_ViewFrame.h"
131 #include <vtkLegendBoxActor.h>
132 #include <vtkFeatureEdges.h>
133 #include <vtkDoubleArray.h>
136 // Open CASCADE Includes
137 #include <gp_Pnt.hxx>
138 #include <gp_Vec.hxx>
140 static GEOM_Client ShapeReader;
141 static SMESHGUI* smeshGUI = 0;
142 static CORBA::ORB_var _orb;
145 //=============================================================================
149 //=============================================================================
150 class CustomItem : public QCustomMenuItem
153 CustomItem( const QString& s, const QFont& f )
154 : string( s ), font( f ){};
157 void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
160 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
165 return QFontMetrics( font ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
172 //=============================================================================
176 //=============================================================================
177 SMESHGUI::SMESHGUI() :
182 //=============================================================================
186 //=============================================================================
187 SMESHGUI::~SMESHGUI()
192 //=============================================================================
196 //=============================================================================
197 SMESHGUI* SMESHGUI::GetSMESHGUI( )
202 //=============================================================================
206 //=============================================================================
207 SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
209 if( smeshGUI == 0 ) {
211 smeshGUI = new SMESHGUI;
212 smeshGUI->myActiveDialogBox = 0 ;
213 smeshGUI->myState = -1 ;
214 smeshGUI->myDesktop = desktop ;
215 smeshGUI->myActiveStudy = desktop->getActiveStudy();
217 Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
218 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
220 Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");
221 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
223 /* GetCurrentStudy */
224 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
226 smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
227 // smeshGUI->myComponentGeom->NbLabels();
229 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
231 smeshGUI->myStudyAPI = SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
233 smeshGUI->myDocument = new SMESHDS_Document(1);//NBU
235 smeshGUI->mySimulationActors = vtkActorCollection::New();
236 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
238 /* study may have changed */
239 smeshGUI->myActiveStudy = desktop->getActiveStudy();
240 smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
243 /* Automatic Update */
244 if ( desktop->menuBar()->isItemChecked(1001) )
245 smeshGUI->myAutomaticUpdate = true;
247 smeshGUI->myAutomaticUpdate = false;
252 //=============================================================================
256 //=============================================================================
257 void SMESHGUI::SetState(int aState )
258 { this->myState = aState ; return ; }
261 //=============================================================================
265 //=============================================================================
266 void SMESHGUI::ResetState()
267 { this->myState = -1 ; return ; }
270 //=============================================================================
274 //=============================================================================
275 void SMESHGUI::EmitSignalDeactivateDialog()
277 emit this->SignalDeactivateActiveDialog() ;
281 //=============================================================================
285 //=============================================================================
286 void SMESHGUI::EmitSignalCloseAllDialogs()
288 emit this->SignalCloseAllDialogs() ;
293 //=============================================================================
297 //=============================================================================
298 QDialog* SMESHGUI::GetActiveDialogBox()
300 return this->myActiveDialogBox ;
303 //=============================================================================
307 //=============================================================================
308 void SMESHGUI::SetActiveDialogBox(QDialog* aDlg)
310 this->myActiveDialogBox = (QDialog*)aDlg ;
315 //=============================================================================
319 //=============================================================================
320 QAD_Study* SMESHGUI::GetActiveStudy()
322 return this->myActiveStudy ;
326 //=============================================================================
330 //=============================================================================
331 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
333 return SALOMEDS::Study::_narrow( myStudy );
336 //=============================================================================
340 //=============================================================================
341 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
346 //=============================================================================
350 //=============================================================================
351 QAD_Desktop* SMESHGUI::GetDesktop()
353 return this->myDesktop ;
356 //=============================================================================
360 //=============================================================================
361 vtkScalarBarActor* SMESHGUI::GetScalarBar()
363 vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
364 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
365 actor2DList->InitTraversal();
366 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
367 while (aActor2d != NULL) {
368 if (aActor2d->IsA("vtkScalarBarActor"))
369 return vtkScalarBarActor::SafeDownCast(aActor2d);
370 actor2DList->GetNextActor2D();
375 //=============================================================================
379 //=============================================================================
380 void SMESHGUI::activeStudyChanged( QAD_Desktop* parent )
382 MESSAGE ("SMESHGUI::activeStudyChanged init.")
383 /* Create or retrieve an object SMESHGUI */
384 SMESHGUI::GetOrCreateSMESHGUI(parent);
386 smeshGUI->EmitSignalCloseAllDialogs() ;
387 MESSAGE( "Active study changed : SMESHGUI nullified" << endl ) ;
391 //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
392 MESSAGE ("SMESHGUI::activeStudyChanged done.")
396 //=============================================================================
400 //=============================================================================
401 bool SMESHGUI::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
403 /* Here the position is on the bottom right corner - 10 */
404 aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
405 QAD_Desktop* PP = QAD_Application::getDesktop() ;
406 x = abs ( PP->x() + PP->size().width() - aDlg->size().width() - 10 ) ;
407 y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ;
412 //=============================================================================
416 //=============================================================================
417 void SMESHGUI::EraseSimulationActors()
419 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
420 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
421 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
423 if ( mySimulationActors != NULL ) {
425 mySimulationActors->InitTraversal();
426 vtkActor *ac = mySimulationActors->GetNextActor();
428 theRenderer->RemoveActor(ac);
429 ac = mySimulationActors->GetNextActor();
431 mySimulationActors->RemoveAllItems();
433 if ( mySimulationActors2D != NULL ) {
434 mySimulationActors2D->InitTraversal();
435 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
437 theRenderer->RemoveActor2D(ac);
438 ac = mySimulationActors2D->GetNextActor2D();
440 mySimulationActors2D->RemoveAllItems();
446 //=============================================================================
450 //=============================================================================
451 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
454 if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
455 SMESH::SMESH_Mesh_var aMesh = myComponentMesh->Init( myComponentGeom, myStudyId, aShape);
457 if ( !aMesh->_is_nil() ) {
458 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh ( aMesh );
459 myStudyAPI.SetName( SM, NameMesh );
461 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
462 // not after loading from file, so let's use more reliable way to retrieve SObject
463 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
464 SALOMEDS::SObject_var SObject = myStudy->FindObjectIOR(ShapeIOR);
465 if ( !SObject->_is_nil() && !SM->_is_nil() ) {
466 myStudyAPI.SetShape( SM, SObject );
468 return SMESH::SMESH_Mesh::_narrow(aMesh);
472 catch (const SALOME::SALOME_Exception& S_ex) {
473 QtCatchCorbaException(S_ex);
475 myActiveStudy->updateObjBrowser(true);
476 return SMESH::SMESH_Mesh::_nil();
479 //=============================================================================
483 //=============================================================================
484 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh, GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
487 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
488 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
489 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
490 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
492 if ( !SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() && !aSubMesh->_is_nil() && !aMesh->_is_nil() ) {
493 SALOMEDS::SObject_var SO = myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh, aShape->ShapeType() );
494 myStudyAPI.SetName(SO, NameMesh);
496 SMESH_Actor* amesh = SMESH_Actor::New();
497 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(SO->GetID(),
501 amesh->setName( strdup(NameMesh) );
502 DisplayActor(amesh, false);
503 return SMESH::SMESH_subMesh::_narrow( aSubMesh );
506 catch (const SALOME::SALOME_Exception& S_ex) {
507 QtCatchCorbaException(S_ex);
509 myActiveStudy->updateObjBrowser(true);
510 return SMESH::SMESH_subMesh::_nil();
514 //=============================================================================
518 //=============================================================================
519 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis( QString TypeHypothesis,
520 QString NameHypothesis )
522 SMESH::SMESH_Hypothesis_var Hyp;
524 Hyp = myComponentMesh->CreateHypothesis( TypeHypothesis, myStudyId );
525 if ( !Hyp->_is_nil() ) {
526 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis( Hyp );
527 myStudyAPI.SetName( SHyp, NameHypothesis);
530 catch (const SALOME::SALOME_Exception& S_ex) {
531 QtCatchCorbaException(S_ex);
534 return SMESH::SMESH_Hypothesis::_narrow( Hyp );
537 //=============================================================================
541 //=============================================================================
542 void SMESHGUI::AddHypothesisOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
544 if ( !aMesh->_is_nil() ) {
545 QApplication::setOverrideCursor( Qt::waitCursor );
546 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
547 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
549 bool res = aMesh->AddHypothesis( aShape, aHyp );
551 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
552 if ( !SM->_is_nil() && !SH->_is_nil() ) {
553 myStudyAPI.SetHypothesis( SM, SH );
554 myStudyAPI.ModifiedMesh( SM, false );
556 QApplication::restoreOverrideCursor();
558 QApplication::restoreOverrideCursor();
559 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
560 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
563 catch (const SALOME::SALOME_Exception& S_ex) {
564 QtCatchCorbaException(S_ex);
567 myActiveStudy->updateObjBrowser(true);
568 QApplication::restoreOverrideCursor();
571 //=============================================================================
575 //=============================================================================
576 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( const Handle(SALOME_InteractiveObject)& IObject )
578 if ( IObject->hasReference() ) {
579 SMESH::SMESH_Hypothesis_var anHyp;
580 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getEntry() );
581 SALOMEDS::GenericAttribute_var anAttr;
582 SALOMEDS::AttributeIOR_var anIOR;
584 if ( !SO_Hypothesis->_is_nil() ) {
585 QApplication::setOverrideCursor( Qt::waitCursor );
586 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
587 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
588 anHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()) );
591 SALOMEDS::SObject_var SO_Applied_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getReference());
592 if ( !SO_Applied_Hypothesis->_is_nil() ) {
593 SALOMEDS::SObject_var MorSM = smeshGUI->myStudyAPI.GetMeshOrSubmesh( SO_Applied_Hypothesis );
594 if ( !MorSM->_is_nil() ) {
595 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
597 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
598 if ( !aShape->_is_nil() ) {
599 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
600 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
601 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
602 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
603 if ( !aMesh->_is_nil() ) {
604 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
606 QApplication::restoreOverrideCursor();
607 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
608 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
610 } else if ( !aSubMesh->_is_nil() ) {
611 aMesh = aSubMesh->GetFather();
612 if ( !aMesh->_is_nil() ) {
613 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
615 QApplication::restoreOverrideCursor();
616 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
617 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
621 if ( myAutomaticUpdate ) {
622 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
623 if ( Mesh != NULL ) {
627 DisplayActor( Mesh );
628 DisplayEdges( Mesh );
629 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
635 smeshGUI->myStudyAPI.UnSetHypothesis( SO_Applied_Hypothesis );
638 } else if ( IObject->hasEntry() ) {
639 MESSAGE ( "IObject entry " << IObject->getEntry() )
641 QApplication::restoreOverrideCursor();
644 //=============================================================================
648 //=============================================================================
649 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( SALOMEDS::SObject_ptr MorSM, SMESH::SMESH_Hypothesis_ptr anHyp )
651 SALOMEDS::SObject_var AHR, aRef;
652 SALOMEDS::GenericAttribute_var anAttr;
653 SALOMEDS::AttributeIOR_var anIOR;
655 if ( !MorSM->_is_nil() ) {
656 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
657 if ( !aShape->_is_nil() ) {
658 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
659 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
660 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
661 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
662 if ( !aMesh->_is_nil() ) {
663 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
665 QApplication::restoreOverrideCursor();
666 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
667 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
669 } else if ( !aSubMesh->_is_nil() ) {
670 aMesh = aSubMesh->GetFather();
671 if ( !aMesh->_is_nil() ) {
672 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
674 QApplication::restoreOverrideCursor();
675 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
676 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
680 if ( myAutomaticUpdate ) {
681 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
682 if ( Mesh != NULL ) {
686 DisplayActor( Mesh );
687 DisplayEdges( Mesh );
688 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
694 if ( MorSM->FindSubObject (2, AHR)) {
695 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
696 for (; it->More();it->Next()) {
697 SALOMEDS::SObject_var Obj = it->Value();
698 if ( Obj->ReferencedObject(aRef) ) {
699 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
700 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
701 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
702 smeshGUI->myStudyAPI.UnSetHypothesis( Obj );
709 if ( MorSM->FindSubObject (3, AHR)) {
710 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
711 for (; it->More();it->Next()) {
712 SALOMEDS::SObject_var Obj = it->Value();
713 if ( Obj->ReferencedObject(aRef) ) {
714 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
715 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
716 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
717 smeshGUI->myStudyAPI.UnSetAlgorithm( Obj );
724 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
726 QApplication::restoreOverrideCursor();
729 //=============================================================================
733 //=============================================================================
734 void SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
736 if ( !aMesh->_is_nil() ) {
737 QApplication::setOverrideCursor( Qt::waitCursor );
738 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
739 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
741 bool res = aMesh->AddHypothesis( aShape, aHyp );
743 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
744 if ( !SM->_is_nil() && !SH->_is_nil() ) {
745 myStudyAPI.SetAlgorithms( SM, SH );
746 myStudyAPI.ModifiedMesh( SM, false );
749 QApplication::restoreOverrideCursor();
750 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
751 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
754 catch (const SALOME::SALOME_Exception& S_ex) {
755 QtCatchCorbaException(S_ex);
758 myActiveStudy->updateObjBrowser(true);
759 QApplication::restoreOverrideCursor();
762 //=============================================================================
766 //=============================================================================
767 void SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
769 if ( !aSubMesh->_is_nil() ) {
770 QApplication::setOverrideCursor( Qt::waitCursor );
772 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
773 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
774 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
775 if ( !aMesh->_is_nil() ) {
776 bool res = aMesh->AddHypothesis( aShape, aHyp );
778 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
779 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
780 myStudyAPI.SetHypothesis( SsubM, SH );
781 myStudyAPI.ModifiedMesh( SsubM, false );
784 QApplication::restoreOverrideCursor();
785 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
786 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
790 catch (const SALOME::SALOME_Exception& S_ex) {
791 QtCatchCorbaException(S_ex);
794 myActiveStudy->updateObjBrowser(true);
795 QApplication::restoreOverrideCursor();
798 //=============================================================================
802 //=============================================================================
803 void SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
805 if ( !aSubMesh->_is_nil() ) {
806 QApplication::setOverrideCursor( Qt::waitCursor );
808 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
809 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
810 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
811 if ( !aMesh->_is_nil() ) {
812 bool res = aMesh->AddHypothesis( aShape, aHyp );
814 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
815 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
816 myStudyAPI.SetAlgorithms( SsubM, SH );
817 myStudyAPI.ModifiedMesh( SsubM, false );
820 QApplication::restoreOverrideCursor();
821 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
822 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
826 catch (const SALOME::SALOME_Exception& S_ex) {
827 QtCatchCorbaException(S_ex);
830 myActiveStudy->updateObjBrowser(true);
831 QApplication::restoreOverrideCursor();
834 //=============================================================================
838 //=============================================================================
839 void SMESHGUI::CreateAlgorithm( QString TypeAlgo, QString NameAlgo )
841 SMESH::SMESH_Hypothesis_var Hyp;
843 if ( TypeAlgo.compare("Regular_1D") == 0 )
844 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
845 else if ( TypeAlgo.compare("MEFISTO_2D") == 0 )
846 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
847 else if ( TypeAlgo.compare("Quadrangle_2D") == 0 )
848 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
849 else if ( TypeAlgo.compare("Hexa_3D") == 0 )
850 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
851 else if ( TypeAlgo.compare("NETGEN_3D") == 0 )
852 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
854 if ( !Hyp->_is_nil() ) {
855 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
856 myStudyAPI.SetName( SHyp, NameAlgo);
859 catch (const SALOME::SALOME_Exception& S_ex) {
860 QtCatchCorbaException(S_ex);
862 myActiveStudy->updateObjBrowser(true);
866 //=============================================================================
870 //=============================================================================
871 void SMESHGUI::CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length )
873 QApplication::setOverrideCursor( Qt::waitCursor );
875 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
876 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
877 if ( !LL->_is_nil() )
878 LL->SetLength( Length );
880 catch (const SALOME::SALOME_Exception& S_ex) {
881 QtCatchCorbaException(S_ex);
883 myActiveStudy->updateObjBrowser(true);
884 QApplication::restoreOverrideCursor();
887 //=============================================================================
891 //=============================================================================
892 void SMESHGUI::CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea )
894 QApplication::setOverrideCursor( Qt::waitCursor );
896 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
897 SMESH::SMESH_MaxElementArea_var MaxElArea = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
898 if ( !MaxElArea->_is_nil() )
899 MaxElArea->SetMaxElementArea( MaxArea );
901 catch (SALOME::SALOME_Exception& S_ex) {
902 QtCatchCorbaException(S_ex);
905 myActiveStudy->updateObjBrowser(true);
906 QApplication::restoreOverrideCursor();
909 //=============================================================================
913 //=============================================================================
914 void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume )
916 QApplication::setOverrideCursor( Qt::waitCursor );
918 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
919 SMESH::SMESH_MaxElementVolume_var MaxElVolume = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
920 if ( !MaxElVolume->_is_nil() )
921 MaxElVolume->SetMaxElementVolume( MaxVolume );
923 catch (const SALOME::SALOME_Exception& S_ex) {
924 QtCatchCorbaException(S_ex);
926 myActiveStudy->updateObjBrowser(true);
927 QApplication::restoreOverrideCursor();
930 //=============================================================================
934 //=============================================================================
935 void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, int nbSegments )
937 QApplication::setOverrideCursor( Qt::waitCursor );
939 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
940 SMESH::SMESH_NumberOfSegments_var NbS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
941 if ( !NbS->_is_nil() )
942 NbS->SetNumberOfSegments( nbSegments );
944 catch (const SALOME::SALOME_Exception& S_ex) {
945 QtCatchCorbaException(S_ex);
947 myActiveStudy->updateObjBrowser(true);
948 QApplication::restoreOverrideCursor();
951 //=============================================================================
955 //=============================================================================
956 int SMESHGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName )
958 int nbSel = Sel->IObjectCount() ;
960 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
961 aName = IObject->getName();
963 aName = tr( "SMESH_OBJECTS_SELECTED" ).arg( nbSel );
968 //=============================================================================
972 //=============================================================================
973 int SMESHGUI::GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName )
976 int nbSel = Sel->IObjectCount() ;
978 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
979 if ( !IObject->hasEntry() )
982 Standard_Boolean res;
983 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
987 TColStd_MapOfInteger MapIndex;
988 Sel->GetIndex( IObject, MapIndex );
989 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
991 nbNodes = MapIndex.Extent();
992 for ( ; ite.More(); ite.Next() ) {
993 aName = aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) + " ";
1001 //=============================================================================
1005 //=============================================================================
1006 int SMESHGUI::GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName )
1009 int nbSel = Sel->IObjectCount() ;
1011 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1012 if ( !IObject->hasEntry() )
1015 Standard_Boolean res;
1016 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1020 TColStd_MapOfInteger MapIndex;
1021 Sel->GetIndex( IObject, MapIndex );
1022 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1024 nbElements = MapIndex.Extent();
1025 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1026 for ( ; ite.More(); ite.Next() ) {
1027 int idVTK = ite.Key();
1028 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1029 aName = aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1038 //=============================================================================
1042 //=============================================================================
1043 int SMESHGUI::GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName )
1046 int nbSel = Sel->IObjectCount() ;
1048 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1049 if ( !IObject->hasEntry() )
1052 Standard_Boolean res;
1053 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1057 TColStd_MapOfInteger MapIndex;
1058 Sel->GetIndex( IObject, MapIndex );
1059 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1061 nbElements = MapIndex.Extent();
1062 for ( ; ite.More(); ite.Next() ) {
1063 aName = aName + QString("%1").arg(ite.Key()) + " ";
1072 //=============================================================================
1076 //=============================================================================
1077 SMESH_Actor* SMESHGUI::FindActorByEntry(QString entry,
1078 Standard_Boolean& testResult,
1079 bool onlyInActiveView)
1081 int nbSf = myActiveStudy->getStudyFramesCount();
1082 for ( int i = 0; i < nbSf; i++ ) {
1083 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
1084 if ( sf->getTypeView() == VIEW_VTK ) {
1085 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1086 vtkActorCollection* theActors = Renderer->GetActors();
1087 theActors->InitTraversal();
1088 vtkActor *ac = theActors->GetNextActor();
1089 while(!(ac==NULL)) {
1090 if ( ac->IsA("SMESH_Actor") ) {
1091 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1092 if ( anActor->hasIO() ) {
1093 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1094 if ( strcmp( IO->getEntry(), entry ) == 0 ) {
1095 if ( onlyInActiveView ) {
1096 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
1107 ac = theActors->GetNextActor();
1112 MESSAGE ( " Actor Not Found " )
1114 return SMESH_Actor::New();
1117 //=============================================================================
1121 //=============================================================================
1122 SMESH_Actor* SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1123 Standard_Boolean& testResult,
1124 bool onlyInActiveView)
1126 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
1127 if ( SM->_is_nil() ) {
1128 MESSAGE ( " Actor Not Found " )
1131 return SMESH_Actor::New();
1134 return FindActorByEntry( SM->GetID(), testResult, onlyInActiveView);
1137 //=============================================================================
1141 //=============================================================================
1142 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO,
1143 Standard_Boolean& testResult)
1145 SMESH::SMESH_Mesh_var aMesh;
1146 testResult = false ;
1149 if ( IO->hasEntry() ) {
1150 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1151 SALOMEDS::GenericAttribute_var anAttr;
1152 SALOMEDS::AttributeIOR_var anIOR;
1153 if ( !obj->_is_nil() ) {
1154 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1155 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1156 aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1157 if ( !aMesh->_is_nil() ) {
1159 return SMESH::SMESH_Mesh::_duplicate( aMesh );
1164 return SMESH::SMESH_Mesh::_nil();
1167 //=============================================================================
1171 //=============================================================================
1172 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO,
1173 Standard_Boolean& testResult)
1175 SMESH::SMESH_subMesh_var aSubMesh;
1176 testResult = false ;
1179 if ( IO->hasEntry() ) {
1180 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1181 SALOMEDS::GenericAttribute_var anAttr;
1182 SALOMEDS::AttributeIOR_var anIOR;
1183 if ( !obj->_is_nil() ) {
1184 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1185 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1186 aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1187 if ( !aSubMesh->_is_nil() ) {
1189 return SMESH::SMESH_subMesh::_duplicate( aSubMesh );
1194 return SMESH::SMESH_subMesh::_nil();
1197 //=============================================================================
1201 //=============================================================================
1202 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO,
1203 Standard_Boolean& testResult )
1205 SMESH::SMESH_Hypothesis_var aHyp ;
1206 testResult = false ;
1209 if ( IO->hasEntry() ) {
1210 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1211 SALOMEDS::GenericAttribute_var anAttr;
1212 SALOMEDS::AttributeIOR_var anIOR;
1213 if ( !obj->_is_nil() ) {
1214 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1215 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1216 aHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()));
1217 if ( !aHyp->_is_nil() ) {
1219 return SMESH::SMESH_Hypothesis::_duplicate( aHyp );
1224 return SMESH::SMESH_Hypothesis::_nil();
1229 //=============================================================================
1233 //=============================================================================
1234 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO,
1235 Standard_Boolean& testResult )
1237 GEOM::GEOM_Shape_var aShape ;
1238 testResult = false ;
1241 if ( IO->hasEntry() ) {
1242 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1243 SALOMEDS::GenericAttribute_var anAttr;
1244 SALOMEDS::AttributeIOR_var anIOR;
1245 if ( !obj->_is_nil() ) {
1246 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1247 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1248 aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
1249 if ( !aShape->_is_nil() ) {
1251 return GEOM::GEOM_Shape::_duplicate( aShape );
1256 return GEOM::GEOM_Shape::_nil();
1260 //=============================================================================
1264 //=============================================================================
1265 void SMESHGUI::SetViewMode(int commandId)
1267 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1268 int nbSel = Sel->IObjectCount();
1270 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1271 for ( ; It.More(); It.Next() ) {
1272 Handle(SALOME_InteractiveObject) IObject = It.Value();
1273 if ( IObject->hasEntry() ) {
1274 Standard_Boolean res;
1275 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1277 switch (commandId) {
1279 ChangeRepresentation( ac, 0 );
1283 ChangeRepresentation( ac, 1 );
1287 ChangeRepresentation( ac, 2 );
1291 ChangeRepresentation( ac, 3 );
1298 if ( commandId == 1133 ) {
1299 ChangeRepresentation( SMESH_Actor::New(), 4 );
1304 //=============================================================================
1308 //=============================================================================
1309 void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
1311 if (ac->DataSource == NULL && type != 4 )
1315 if ( ac->getMapper() == NULL ) {
1321 QApplication::setOverrideCursor( Qt::waitCursor );
1322 if (ac->getDisplayMode()==2) {
1323 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1324 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1325 meshMapper->SetInput(ac->DataSource);
1326 meshMapper->SetScalarVisibility(isColored); //SAL3899
1328 ac->setDisplayMode(0);
1329 ac->GetProperty()->SetRepresentationToWireframe();
1330 // ac->SetActorProperty( ac->GetProperty() );
1331 QApplication::restoreOverrideCursor();
1335 QApplication::setOverrideCursor( Qt::waitCursor );
1336 if (ac->getDisplayMode()==2) {
1337 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1338 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1339 meshMapper->SetInput(ac->DataSource);
1340 meshMapper->SetScalarVisibility(isColored); //SAL3899
1342 ac->setDisplayMode(1);
1343 ac->GetProperty()->SetRepresentationToSurface();
1344 QApplication::restoreOverrideCursor();
1345 // ac->SetActorProperty( ac->GetProperty() );
1349 // if (!(ac->getDisplayMode()==2)) {
1350 // ChangeRepresentation(ac, 1);
1351 QApplication::setOverrideCursor( Qt::waitCursor );
1352 ac->setDisplayMode(2);
1353 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1354 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1355 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1356 shrink->SetInput(ac->DataSource);
1357 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1359 meshMapper->SetInput( shrink->GetOutput() );
1360 meshMapper->SetScalarVisibility(isColored); //SAL3899
1361 ac->SetMapper( meshMapper );
1362 QApplication::restoreOverrideCursor();
1370 float backfacecolor[3];
1372 ac->GetColor(color[0],color[1],color[2]);
1373 // QColor c(color[0]*255,color[1]*255,color[2]*255);
1374 int c0 = int(color[0]*255);
1375 int c1 = int(color[1]*255);
1376 int c2 = int(color[2]*255);
1377 QColor c( c0, c1, c2 );
1378 ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
1379 // QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1380 c0 = int(edgecolor[0]*255);
1381 c1 = int(edgecolor[1]*255);
1382 c2 = int(edgecolor[2]*255);
1383 QColor e( c0, c1, c2 );
1384 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1385 // QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1386 c0 = int(backfacecolor[0]*255);
1387 c1 = int(backfacecolor[1]*255);
1388 c2 = int(backfacecolor[2]*255);
1389 QColor b( c0, c1, c2 );
1390 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
1391 // QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1392 c0 = int(nodecolor[0]*255);
1393 c1 = int(nodecolor[1]*255);
1394 c2 = int(nodecolor[2]*255);
1395 QColor n( c0, c1, c2 ) ;
1397 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1398 if ( Edgewidth == 0 )
1400 int intValue = ac->GetNodeSize() ;
1401 float Shrink = ac->GetShrinkFactor();
1403 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "" ) ;
1404 aDlg->SetColor(1,c);
1405 aDlg->SetColor(2,e);
1406 aDlg->SetColor(3,n);
1407 aDlg->SetColor(4,b);
1408 aDlg->SetIntValue(1,Edgewidth);
1409 aDlg->SetIntValue(2,intValue);
1410 aDlg->SetIntValue(3,int(Shrink*100.));
1412 if ( aDlg->exec() ) {
1413 QApplication::setOverrideCursor( Qt::waitCursor );
1414 QColor color = aDlg->GetColor(1);
1415 QColor edgecolor = aDlg->GetColor(2);
1416 QColor nodecolor = aDlg->GetColor(3);
1417 QColor backfacecolor = aDlg->GetColor(4);
1418 /* actor color and backface color */
1419 ac->GetProperty()->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1420 ac->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1421 ac->GetBackfaceProperty()->SetColor(float(backfacecolor.red())/255.,float(backfacecolor.green())/255.,float(backfacecolor.blue())/255.);
1424 ac->EdgeDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1425 float(edgecolor.green())/255.,
1426 float(edgecolor.blue())/255.);
1427 ac->EdgeShrinkDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1428 float(edgecolor.green())/255.,
1429 float(edgecolor.blue())/255.);
1430 ac->SetEdgeColor(float(edgecolor.red())/255.,
1431 float(edgecolor.green())/255.,
1432 float(edgecolor.blue())/255.);
1434 /* Shrink factor and size edges */
1435 ac->SetShrinkFactor( aDlg->GetIntValue(3)/100. );
1436 ac->EdgeDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1437 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1439 /* Nodes color and size */
1440 ac->SetNodeColor(float(nodecolor.red())/255.,
1441 float(nodecolor.green())/255.,
1442 float(nodecolor.blue())/255.);
1443 ac->SetNodeSize(aDlg->GetIntValue(2)) ;
1445 if (ac->getDisplayMode()==2) {
1446 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1447 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1448 meshMapper->SetInput(ac->DataSource);
1449 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1450 shrink->SetInput(meshMapper->GetInput());
1451 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1453 meshMapper->SetInput( shrink->GetOutput() );
1454 meshMapper->SetScalarVisibility(isColored); //SAL3899
1455 ac->SetMapper( meshMapper );
1459 QApplication::restoreOverrideCursor();
1464 EmitSignalDeactivateDialog() ;
1465 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1466 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg( QAD_Application::getDesktop(), "", Sel) ;
1470 QApplication::setOverrideCursor( Qt::waitCursor );
1471 ac->GetProperty()->SetRepresentationToPoints();
1472 QApplication::restoreOverrideCursor();
1477 QApplication::setOverrideCursor( Qt::waitCursor );
1478 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1479 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1480 theRenderer->Render();
1482 QApplication::restoreOverrideCursor();
1485 //=============================================================================
1489 //=============================================================================
1490 void SMESHGUI::UpdateView()
1492 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1495 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1496 theRenderer->Render();
1499 //=============================================================================
1503 //=============================================================================
1504 void SMESHGUI::DisplayActor(SMESH_Actor* ac, bool visibility)
1506 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1509 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1511 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1512 vtkActorCollection* theActors = theRenderer->GetActors();
1513 theActors->InitTraversal();
1514 if ( theActors->IsItemPresent(ac) == 0 ) {
1515 vtkProperty* prop = vtkProperty::New();
1516 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1517 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1518 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. ) ;
1520 prop->SetPointSize( QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
1521 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
1522 ac->SetProperty( prop );
1523 ac->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1524 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1525 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. );
1527 // prop->BackfaceCullingOn();
1528 vtkProperty* backprop = vtkProperty::New();
1529 backprop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed").toFloat()/255.,
1530 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").toFloat()/255.,
1531 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").toFloat()/255. ) ;
1532 ac->SetBackfaceProperty(backprop);
1534 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1537 ac->SetShrinkFactor( intValue/100. );
1539 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1540 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1542 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1543 if ( DisplayMode.compare("Wireframe") == 0 ){
1544 ac->setDisplayMode(0);
1545 ChangeRepresentation( ac, 0 );
1546 } else if ( DisplayMode.compare("Shading") == 0 ){
1547 ac->setDisplayMode(1);
1548 ChangeRepresentation( ac, 1 );
1549 } else if ( DisplayMode.compare("Shrink") == 0 ) {
1550 ac->setDisplayMode(2);
1551 ChangeRepresentation( ac, 2 );
1553 theRenderer->AddActor(ac);
1555 if (ac->GetMapper())
1556 ac->GetMapper()->Update();
1559 // if ( visibility )
1560 ac->SetVisibility(visibility);
1561 // ac->VisibilityOn();
1563 // ac->VisibilityOff();
1565 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1569 //=============================================================================
1573 //=============================================================================
1574 void SMESHGUI::EraseActor(SMESH_Actor* ac)
1576 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1579 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1581 //NRI- : 02/12/2002 : Fixed bugId 882
1582 // ac->EdgeDevice->VisibilityOff();
1583 // ac->EdgeShrinkDevice->VisibilityOff();
1584 // ac->VisibilityOff();
1585 ac->SetVisibility( false );
1587 theRenderer->Render();
1590 //=============================================================================
1594 //=============================================================================
1595 bool SMESHGUI::AddActorInSelection(SMESH_Actor* ac)
1597 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1598 Sel->ClearIObjects();
1600 return Sel->AddIObject( ac->getIO() );
1605 //=============================================================================
1609 //=============================================================================
1610 QString SMESHGUI::CheckHomogeneousSelection()
1612 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1615 SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
1616 for (; Itinit.More(); Itinit.Next()) {
1617 List.Append(Itinit.Value());
1620 QString RefType = CheckTypeObject( Sel->firstIObject() );
1621 SALOME_ListIteratorOfListIO It( List );
1622 for (; It.More(); It.Next()) {
1623 Handle(SALOME_InteractiveObject) IObject = It.Value();
1624 QString Type = CheckTypeObject( IObject );
1625 if ( Type.compare( RefType ) != 0 )
1626 return "Heterogeneous Selection";
1629 Sel->ClearIObjects();
1630 SALOME_ListIteratorOfListIO It1( List );
1631 for(;It1.More();It1.Next()) {
1632 int res = Sel->AddIObject( It1.Value() );
1634 myActiveStudy->highlight( It1.Value(), false );
1636 myActiveStudy->highlight( It1.Value(), true );
1641 //=============================================================================
1645 //=============================================================================
1646 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO)
1648 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
1649 if (!sobj->_is_nil()) {
1650 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1651 if (strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected
1656 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1657 Sel->ClearIObjects();
1659 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter( HYPOTHESIS );
1660 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter( ALGORITHM );
1661 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
1662 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
1663 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
1664 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter( SUBMESH_VERTEX );
1665 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter( SUBMESH_EDGE );
1666 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter( SUBMESH_FACE );
1667 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter( SUBMESH_SOLID );
1668 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter( SUBMESH_COMPOUND );
1670 Sel->AddFilter(aHypFilter);
1671 if ( Sel->AddIObject( IO ) != -1 ) {
1672 Sel->ClearFilters();
1673 return "Hypothesis";
1676 Sel->ClearFilters();
1677 Sel->AddFilter(anAlgoFilter);
1678 if ( Sel->AddIObject( IO ) != -1 ) {
1679 Sel->ClearFilters();
1683 Sel->ClearFilters();
1684 Sel->AddFilter(aMeshFilter);
1685 if ( Sel->AddIObject( IO ) != -1 ) {
1686 Sel->ClearFilters();
1690 Sel->ClearFilters();
1691 Sel->AddFilter(aSubMeshFilter);
1692 if ( Sel->AddIObject( IO ) != -1 ) {
1693 Sel->ClearFilters();
1697 Sel->ClearFilters();
1698 Sel->AddFilter(aSubMeshVextexFilter);
1699 if ( Sel->AddIObject( IO ) != -1 ) {
1700 Sel->ClearFilters();
1701 return "SubMeshVertex";
1704 Sel->ClearFilters();
1705 Sel->AddFilter(aSubMeshEdgeFilter);
1706 if ( Sel->AddIObject( IO ) != -1 ){
1707 Sel->ClearFilters();
1708 return "SubMeshEdge";
1711 Sel->ClearFilters();
1712 Sel->AddFilter(aSubMeshFaceFilter);
1713 if ( Sel->AddIObject( IO ) != -1 ) {
1714 Sel->ClearFilters();
1715 return "SubMeshFace";
1718 Sel->ClearFilters();
1719 Sel->AddFilter(aSubMeshSolidFilter);
1720 if ( Sel->AddIObject( IO ) != -1 ) {
1721 Sel->ClearFilters();
1722 return "SubMeshSolid";
1725 Sel->ClearFilters();
1726 Sel->AddFilter(aSubMeshCompoundFilter);
1727 if ( Sel->AddIObject( IO ) != -1 ) {
1728 Sel->ClearFilters();
1729 return "SubMeshCompound";
1732 Sel->ClearFilters();
1733 Sel->AddIObject( IO );
1737 //=============================================================================
1741 //=============================================================================
1742 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1744 /* Create or retrieve an object SMESHGUI */
1745 SMESHGUI::GetOrCreateSMESHGUI(parent);
1747 // NRI : Temporary added
1748 if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
1753 // QAD_Viewer3d* v3d;
1754 OCCViewer_Viewer3d* v3d;
1756 Handle(AIS_InteractiveContext) ic;
1757 vtkRenderer* Renderer;
1758 vtkRenderWindow* RenWin;
1760 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1761 v3d =((OCCViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1762 ic = v3d->getAISContext();
1763 } else if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1764 Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1765 RenWin = Renderer->GetRenderWindow();
1768 switch (theCommandID)
1771 smeshGUI->OnEditDelete();
1778 Import_Document(parent,theCommandID);//NBU
1779 //Import_Mesh(parent,theCommandID);
1783 case 122: // EXPORT MED
1787 Export_Mesh(parent, theCommandID);
1791 case 200: // SCALAR BAR
1793 smeshGUI->DisplayScalarBar(false);
1798 SMESHGUI_EditScalarBarDlg *aDlg = new SMESHGUI_EditScalarBarDlg( parent, "", false ) ;
1804 smeshGUI->DisplayScalarBar( true );
1808 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
1814 smeshGUI->SetViewMode(theCommandID);
1818 case 214 : // UPDATE
1826 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1827 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1829 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1830 for(;It.More();It.Next()) {
1831 Handle(SALOME_InteractiveObject) IOS = It.Value();
1832 if ( IOS->hasEntry() ) {
1833 Standard_Boolean res;
1834 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IOS->getEntry(), res, true );
1835 if ( res ) smeshGUI->EraseActor( ac );
1839 Sel->ClearIObjects();
1840 smeshGUI->myActiveStudy->updateObjBrowser( true );
1843 case 301 : // DISPLAY
1845 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1847 QApplication::setOverrideCursor( Qt::waitCursor );
1848 SALOMEDS::SObject_var fatherSF =
1849 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1851 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1852 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1854 for(;It.More();It.Next()) {
1855 Handle(SALOME_InteractiveObject) IObject = It.Value();
1856 if ( IObject->hasEntry() ) {
1857 Standard_Boolean res;
1858 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1860 smeshGUI->DisplayActor( ac, true );
1861 smeshGUI->DisplayEdges( ac );
1862 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1866 QApplication::restoreOverrideCursor();
1871 case 302 : // DISPLAY ONLY
1873 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1874 QApplication::setOverrideCursor( Qt::waitCursor );
1875 vtkActorCollection* theActors = Renderer->GetActors();
1876 theActors->InitTraversal();
1877 vtkActor *ac = theActors->GetNextActor();
1878 while(!(ac==NULL)) {
1879 if ( ac->IsA("SMESH_Actor") ) {
1880 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1881 if(!anActor->isHighlighted()) {
1882 //anActor->VisibilityOff();
1883 //NRI- : 02/12/2002 : Fixed bugId 882
1884 // anActor->EdgeDevice->VisibilityOff();
1885 // anActor->EdgeShrinkDevice->VisibilityOff();
1886 anActor->SetVisibility( false );
1889 ac = theActors->GetNextActor();
1892 // Display selection
1893 SALOMEDS::SObject_var fatherSF = smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1895 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1896 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1898 for(;It.More();It.Next()) {
1899 Handle(SALOME_InteractiveObject) IObject = It.Value();
1900 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1902 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
1903 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
1905 if(myRenderInter->isInViewer(IObject)) {
1906 if ( IObject->hasEntry() ) {
1907 Standard_Boolean res;
1908 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1910 smeshGUI->DisplayActor( ac, true );
1911 smeshGUI->DisplayEdges( ac );
1912 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1917 smeshGUI->myActiveStudy->updateObjBrowser( true );
1918 QApplication::restoreOverrideCursor();
1925 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1926 smeshGUI->EmitSignalDeactivateDialog() ;
1927 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1928 Sel->ClearIObjects();
1929 smeshGUI->myDesktop->SetSelectionMode(1, true);
1930 parent->menuBar()->setItemChecked(9010, false );
1931 parent->menuBar()->setItemChecked(9011, false );
1932 smeshGUI->ViewNodes();
1933 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg( parent, "", Sel ) ;
1935 QApplication::restoreOverrideCursor();
1936 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1937 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
1942 case 405: // MOVE NODE
1944 smeshGUI->myDesktop->SetSelectionMode(1, true);
1945 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1946 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, "", Sel ) ;
1950 case 701: // COMPUTE MESH
1952 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1953 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1954 int nbSel = Sel->IObjectCount();
1956 QApplication::restoreOverrideCursor();
1960 SMESH::SMESH_Mesh_var aM;
1961 SMESH::SMESH_subMesh_var aSubM;
1962 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1963 if ( IObject->hasEntry() ) {
1964 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1965 SALOMEDS::GenericAttribute_var anAttr;
1966 SALOMEDS::AttributeIOR_var anIOR;
1967 if ( !aMorSM->_is_nil() ) {
1968 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
1969 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1970 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : IOR = " << anIOR->Value() )
1971 CORBA::Object_var cobj;
1973 cobj = _orb->string_to_object(anIOR->Value());
1974 if ( CORBA::is_nil(cobj) ) {
1975 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : nil object" )
1978 catch(CORBA::COMM_FAILURE& ex) {
1979 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : exception (1)" )
1981 aM = SMESH::SMESH_Mesh::_narrow(cobj);
1982 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1983 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1984 if ( !aM->_is_nil() ) {
1985 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1986 if ( !refShape->_is_nil() ) {
1987 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1989 QApplication::restoreOverrideCursor();
1990 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1991 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1995 smeshGUI->myComponentMesh->Compute( aM, refShape);
1996 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1997 // TO Do : change icon of all submeshes
1999 catch (const SALOME::SALOME_Exception& S_ex) {
2000 QtCatchCorbaException(S_ex);
2003 } else if ( !aSubM->_is_nil() ) {
2004 aM = aSubM->GetFather();
2005 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
2006 if ( !refShape->_is_nil() ) {
2007 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
2009 QApplication::restoreOverrideCursor();
2010 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2011 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
2015 smeshGUI->myComponentMesh->Compute( aM, refShape);
2016 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
2017 // TO Do : change icon of all submeshes
2019 catch (const SALOME::SALOME_Exception& S_ex) {
2020 QtCatchCorbaException(S_ex);
2028 // Check whether the actor for the mesh exists at least in one view
2029 Standard_Boolean res;
2030 SMESH_Actor* ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2032 smeshGUI->InitActor( aM );
2034 // Check whether the actor belongs to the active view
2035 VTKViewer_RenderWindowInteractor* rwInter =
2036 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2038 // The actor belongs to inactive view -> create a copy and add it in the active view
2039 if (!rwInter->isInViewer(IObject)) {
2040 SMESH_Actor* acCopy = SMESH_Actor::New();
2041 acCopy->ShallowCopy(ac);
2043 smeshGUI->DisplayActor( acCopy, false );
2047 if ( smeshGUI->myAutomaticUpdate ) {
2048 SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
2049 if ( Mesh != NULL ) {
2053 smeshGUI->DisplayActor( Mesh, true );
2054 smeshGUI->DisplayEdges( Mesh, true );
2055 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
2059 QApplication::restoreOverrideCursor();
2060 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2061 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2063 QApplication::restoreOverrideCursor();
2067 case 702: // ADD SUB MESH
2069 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2070 smeshGUI->EmitSignalDeactivateDialog() ;
2071 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2072 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg( parent, "", Sel ) ;
2074 QApplication::restoreOverrideCursor();
2075 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2076 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2081 case 703: // INIT MESH
2083 smeshGUI->EmitSignalDeactivateDialog() ;
2084 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2085 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg( parent, "", Sel ) ;
2089 case 704: // EDIT Hypothesis
2091 smeshGUI->EmitSignalDeactivateDialog() ;
2092 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2093 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2097 case 705: // EDIT Global Hypothesis
2099 smeshGUI->EmitSignalDeactivateDialog() ;
2100 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2101 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2105 case 706: // EDIT Local Hypothesis
2107 smeshGUI->EmitSignalDeactivateDialog() ;
2108 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2109 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2113 case 806: // ORIENTATION ELEMENTS
2115 smeshGUI->EmitSignalDeactivateDialog() ;
2116 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2117 smeshGUI->myDesktop->SetSelectionMode(3, true);
2118 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg( parent, "", Sel ) ;
2122 case 807: // DIAGONAL INVERSION
2124 smeshGUI->EmitSignalDeactivateDialog() ;
2125 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2126 Sel->ClearIObjects();
2127 smeshGUI->myDesktop->SetSelectionMode(2, true);
2128 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg( parent, "", Sel ) ;
2132 case 900: // MESH INFOS
2134 smeshGUI->EmitSignalDeactivateDialog() ;
2135 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2136 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg( parent, "", Sel ) ;
2140 case 1001: // AUTOMATIC UPDATE PREFERENCES
2142 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001) );
2143 if ( parent->menuBar()->isItemChecked(1001) ) {
2144 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","true");
2145 smeshGUI->myAutomaticUpdate = true;
2147 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","false");
2148 smeshGUI->myAutomaticUpdate = false;
2153 case 1003: // MESH PREFERENCES
2155 smeshGUI->SetDisplaySettings();
2161 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2162 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2163 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2164 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2165 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2166 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2167 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2168 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2169 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2171 if ( Width == 0 ) Width = 0.17;
2172 if ( Height == 0 ) Height = 0.8;
2173 if ( NumberOfLabels == 0 ) NumberOfLabels = 5;
2174 if ( NumberOfColors == 0) NumberOfColors = 64;
2176 SMESHGUI_Preferences_ScalarBarDlg *aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, "", true) ;
2178 if ( Bold.compare("true") == 0 )
2179 aDlg->Bold->setChecked(true); else aDlg->Bold->setChecked(false);
2180 if ( Italic.compare("true") == 0 )
2181 aDlg->Italic->setChecked(true); else aDlg->Italic->setChecked(false);
2182 if ( Shadow.compare("true") == 0 )
2183 aDlg->Shadow->setChecked(true); else aDlg->Shadow->setChecked(false);
2185 if ( Orientation.compare("Horizontal") == 0 )
2186 aDlg->RadioHoriz->setChecked(true); else aDlg->RadioVert->setChecked(true);
2188 int NbItems = aDlg->ComboBox1->count();
2190 aDlg->ComboBox1->setCurrentItem( i );
2191 while ( i < NbItems ) {
2192 if ( FontFamily.compare( aDlg->ComboBox1->text( i ) ) == 0 )
2193 aDlg->ComboBox1->setCurrentItem( i );
2197 aDlg->LineEditWidth->setText( QString("%1").arg(Width) );
2198 aDlg->LineEditHeight->setText( QString("%1").arg(Height) );
2200 aDlg->SpinBoxLabels->setValue( NumberOfLabels );
2201 aDlg->SpinBoxColors->setValue( NumberOfColors );
2204 if ( aDlg->result() ) {
2205 if ( aDlg->RadioHoriz->isChecked() )
2206 Orientation = "Horizontal"; else Orientation = "Vertical";
2207 if ( aDlg->Bold->isChecked() )
2208 Bold = "true"; else Bold = "false";
2209 if ( aDlg->Italic->isChecked() )
2210 Italic = "true"; else Italic = "false";
2211 if ( aDlg->Shadow->isChecked() )
2212 Shadow = "true"; else Shadow = "false";
2214 FontFamily = aDlg->ComboBox1->currentText();
2215 Width = aDlg->LineEditWidth->text().toFloat();
2216 Height = aDlg->LineEditHeight->text().toFloat();
2217 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2218 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2221 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
2222 if ( aScalarBar != NULL ) {
2223 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2224 FontFamily, Orientation,
2225 Width, Height, NumberOfColors, NumberOfLabels);
2228 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2229 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2230 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2231 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2232 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2233 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2234 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2235 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2236 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2241 case 1100: // EDIT HYPOTHESIS
2243 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2244 int nbSel = Sel->IObjectCount() ;
2247 Standard_Boolean res;
2248 SMESH::SMESH_Hypothesis_var Hyp = smeshGUI->ConvertIOinSMESHHypothesis( Sel->firstIObject(), res );
2250 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2251 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2252 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2253 SALOMEDS::Study::ListOfSObject_var listSOmesh = smeshGUI->GetMeshesUsingAlgoOrHypothesis( Hyp) ;
2256 QString Name = Hyp->GetName();
2258 if ( Name.compare("LocalLength") == 0 ) {
2259 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
2260 double beforeLength = LL->GetLength() ;
2261 double Length = smeshGUI->Parameter( res,
2263 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2266 if ( res && Length != beforeLength ) {
2267 LL->SetLength( Length );
2268 for( int i=0; i<listSOmesh->length(); i++ ) {
2269 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2274 } else if ( Name.compare("NumberOfSegments") == 0 ) {
2275 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
2276 int beforeNbSeg = NOS->GetNumberOfSegments() ;
2277 int NbSeg = smeshGUI->Parameter( res,
2279 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2283 if ( res && NbSeg != beforeNbSeg ) {
2284 NOS->SetNumberOfSegments( NbSeg );
2285 for( int i=0; i<listSOmesh->length(); i++ ) {
2286 SALOMEDS::SObject_var SO = listSOmesh[i] ;
2287 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2292 } else if ( Name.compare("MaxElementArea") == 0 ) {
2293 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
2294 double beforeMaxArea = MEA->GetMaxElementArea() ;
2295 double MaxArea = smeshGUI->Parameter( res,
2297 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2300 if ( res && MaxArea != beforeMaxArea ) {
2301 MEA->SetMaxElementArea( MaxArea );
2302 for( int i=0; i<listSOmesh->length(); i++ ) {
2303 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2308 } else if ( Name.compare("MaxElementVolume") == 0 ) {
2309 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
2310 double beforeMaxVolume = MEV->GetMaxElementVolume() ;
2311 double MaxVolume = smeshGUI->Parameter( res,
2313 tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"),
2316 if ( res && MaxVolume != beforeMaxVolume ) {
2317 MEV->SetMaxElementVolume( MaxVolume );
2318 for( int i=0; i<listSOmesh->length(); i++ ) {
2319 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2324 } else if ( Name.compare("Regular_1D") == 0 ) {
2325 } else if ( Name.compare("MEFISTO_2D") == 0 ) {
2334 case 1101: // RENAME
2336 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2337 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2338 for ( ; It.More(); It.Next() ) {
2339 Handle(SALOME_InteractiveObject) IObject = It.Value();
2341 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2342 SALOMEDS::GenericAttribute_var anAttr;
2343 SALOMEDS::AttributeName_var aName;
2344 if ( !obj->_is_nil() ) {
2345 if (obj->FindAttribute(anAttr, "AttributeName")) {
2346 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2347 QString newName = QString( aName->Value() );
2348 newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName);
2349 if ( !newName.isEmpty() ) {
2350 QApplication::setOverrideCursor( Qt::waitCursor );
2351 smeshGUI->myActiveStudy->renameIObject( IObject, newName );
2353 QApplication::restoreOverrideCursor();
2360 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2362 QApplication::setOverrideCursor( Qt::waitCursor );
2363 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2364 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2365 for ( int i=0; It.More(); It.Next(), i++ ) {
2366 Handle(SALOME_InteractiveObject) IObject = It.Value();
2367 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh( IObject );
2369 Sel->ClearIObjects();
2370 smeshGUI->myActiveStudy->updateObjBrowser( true );
2371 QApplication::restoreOverrideCursor();
2375 case 401: // GEOM::EDGE
2377 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2378 smeshGUI->EmitSignalDeactivateDialog() ;
2379 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2380 Sel->ClearIObjects();
2381 smeshGUI->myDesktop->SetSelectionMode(1, true);
2382 parent->menuBar()->setItemChecked(9010, false );
2383 parent->menuBar()->setItemChecked(9011, false );
2384 smeshGUI->ViewNodes();
2385 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg( parent, "", Sel ) ;
2387 QApplication::restoreOverrideCursor();
2388 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2389 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2393 case 4021: // TRIANGLE
2395 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2396 smeshGUI->EmitSignalDeactivateDialog() ;
2397 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2398 Sel->ClearIObjects();
2399 smeshGUI->myDesktop->SetSelectionMode(1, true);
2400 parent->menuBar()->setItemChecked(9010, false );
2401 parent->menuBar()->setItemChecked(9011, false );
2402 smeshGUI->ViewNodes();
2403 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 3 ) ;
2405 QApplication::restoreOverrideCursor();
2406 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2407 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2413 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2414 smeshGUI->EmitSignalDeactivateDialog() ;
2415 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2416 Sel->ClearIObjects();
2417 smeshGUI->myDesktop->SetSelectionMode(1, true);
2418 parent->menuBar()->setItemChecked(9010, false );
2419 parent->menuBar()->setItemChecked(9011, false );
2420 smeshGUI->ViewNodes();
2421 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 4 ) ;
2423 QApplication::restoreOverrideCursor();
2424 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2425 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2431 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2432 smeshGUI->EmitSignalDeactivateDialog() ;
2433 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2434 Sel->ClearIObjects();
2435 smeshGUI->myDesktop->SetSelectionMode(1, true);
2436 parent->menuBar()->setItemChecked(9010, false );
2437 parent->menuBar()->setItemChecked(9011, false );
2438 smeshGUI->ViewNodes();
2439 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 4 ) ;
2441 QApplication::restoreOverrideCursor();
2442 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2443 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2449 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2450 smeshGUI->EmitSignalDeactivateDialog() ;
2451 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2452 Sel->ClearIObjects();
2453 smeshGUI->myDesktop->SetSelectionMode(1, true);
2454 parent->menuBar()->setItemChecked(9010, false );
2455 parent->menuBar()->setItemChecked(9011, false );
2456 smeshGUI->ViewNodes();
2457 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 8 ) ;
2459 QApplication::restoreOverrideCursor();
2460 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2461 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2466 case 4041: // REMOVES NODES
2468 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2469 smeshGUI->EmitSignalDeactivateDialog() ;
2470 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2471 Sel->ClearIObjects();
2472 smeshGUI->myDesktop->SetSelectionMode(1, true);
2473 parent->menuBar()->setItemChecked(9010, false );
2474 parent->menuBar()->setItemChecked(9011, false );
2475 smeshGUI->ViewNodes();
2476 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg( parent, "", Sel ) ;
2478 QApplication::restoreOverrideCursor();
2479 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2480 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2484 case 4042: // REMOVES ELEMENTS
2486 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2487 smeshGUI->EmitSignalDeactivateDialog() ;
2488 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2489 Sel->ClearIObjects();
2490 smeshGUI->myDesktop->SetSelectionMode(3, true);
2491 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg( parent, "", Sel ) ;
2493 QApplication::restoreOverrideCursor();
2494 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2495 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2500 case 5000: // HYPOTHESIS - ALGO
2502 smeshGUI->CreateAlgorithm("Regular_1D","Wire Discretisation");
2507 smeshGUI->CreateAlgorithm("MEFISTO_2D","Triangle (Mefisto)");
2512 smeshGUI->CreateAlgorithm("Quadrangle_2D","Quadrangle (Mapping)");
2517 smeshGUI->CreateAlgorithm("Hexa_3D","Hexahedron (i,j,k)");
2522 smeshGUI->CreateAlgorithm("NETGEN_3D","Tetrahedron (Netgen)");
2526 case 5030: // HYPOTHESIS - LOCAL LENGTH
2528 smeshGUI->EmitSignalDeactivateDialog() ;
2529 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2530 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg( parent, "" ) ;
2533 case 5031: // HYPOTHESIS - NB SEGMENTS
2535 smeshGUI->EmitSignalDeactivateDialog() ;
2536 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2537 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg( parent, "" ) ;
2541 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
2543 smeshGUI->EmitSignalDeactivateDialog() ;
2544 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2545 SMESHGUI_MaxElementAreaDlg *aDlg = new SMESHGUI_MaxElementAreaDlg( parent, "" ) ;
2549 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
2551 smeshGUI->EmitSignalDeactivateDialog() ;
2552 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2553 SMESHGUI_MaxElementVolumeDlg *aDlg = new SMESHGUI_MaxElementVolumeDlg( parent, "" ) ;
2557 case 6016: // CONTROLS
2565 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2566 int nbSel = Sel->IObjectCount();
2569 smeshGUI->Control(theCommandID);
2575 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2576 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2577 SMESHGUI_EdgesConnectivityDlg *Dlg = new SMESHGUI_EdgesConnectivityDlg( parent, "", Sel ) ;
2579 QApplication::restoreOverrideCursor();
2580 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2581 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2588 if ( !parent->menuBar()->isItemChecked(9010) ) {
2589 QApplication::setOverrideCursor( Qt::waitCursor );
2590 parent->menuBar()->setItemChecked(9011, false );
2592 smeshGUI->EraseSimulationActors();
2593 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2595 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2596 int nbSel = Sel->IObjectCount() ;
2598 Standard_Boolean res;
2599 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2601 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2603 // It's necessary to display SMDS IDs instead of VTK ones, so
2604 // vtkIdFilter is unacceptable here. We have to do it manually :(
2605 vtkUnstructuredGrid* ptGrid = vtkUnstructuredGrid::New();
2606 ptGrid->CopyStructure(MeshActor->DataSource);
2608 int numPts = MeshActor->DataSource->GetNumberOfPoints();
2610 // Loop over points and generate ids
2611 vtkIntArray *ptIds = vtkIntArray::New();
2612 ptIds->SetNumberOfValues(numPts);
2614 for (int id=0; id < numPts; id++) {
2615 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
2616 ptIds->SetValue(id, idSMDS);
2619 // mpv porting vtk4.2.2
2620 // vtkScalars* newScalars = vtkScalars::New();
2621 // newScalars->SetData(ptIds);
2622 // ptGrid->GetPointData()->SetScalars(newScalars);
2623 ptGrid->GetPointData()->SetScalars(ptIds);
2624 // newScalars->Delete();
2628 vtkMaskPoints* mask = vtkMaskPoints::New();
2629 mask->SetInput(ptGrid);
2630 mask->SetOnRatio( 1 );
2631 // mask->SetMaximumNumberOfPoints( 50 );
2632 // mask->RandomModeOn();
2634 vtkSelectVisiblePoints* visPts = vtkSelectVisiblePoints::New();
2635 visPts->SetInput(mask->GetOutput());
2636 visPts->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2637 //visPts->SetSelectInvisible(1);
2638 visPts->SelectInvisibleOff();
2639 visPts->SetTolerance(0.1);
2641 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2642 ldm->SetInput(visPts->GetOutput());
2643 ldm->SetLabelFormat("%g");
2644 ldm->SetLabelModeToLabelScalars();
2645 //ldm->SetLabelModeToLabelFieldData();
2647 ldm->SetFontFamilyToTimes();
2648 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2653 vtkActor2D* pointLabels = vtkActor2D::New();
2654 pointLabels->SetMapper(ldm);
2655 pointLabels->GetProperty()->SetColor(0,1,0);
2659 smeshGUI->mySimulationActors2D->AddItem( pointLabels );
2660 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( pointLabels );
2664 QApplication::setOverrideCursor( Qt::waitCursor );
2665 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2666 smeshGUI->EraseSimulationActors();
2667 smeshGUI->ScalarVisibilityOff();
2669 QApplication::restoreOverrideCursor();
2674 if ( !parent->menuBar()->isItemChecked(9011) ) {
2675 QApplication::setOverrideCursor( Qt::waitCursor );
2676 parent->menuBar()->setItemChecked(9010, false );
2678 smeshGUI->EraseSimulationActors();
2679 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2681 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2682 int nbSel = Sel->IObjectCount() ;
2684 Standard_Boolean res;
2685 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2687 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2689 // It's necessary to display SMDS IDs instead of VTK ones, so
2690 // vtkIdFilter is unacceptable here. We have to do it manually :(
2691 vtkUnstructuredGrid* elGrid = vtkUnstructuredGrid::New();
2692 elGrid->CopyStructure(MeshActor->DataSource);
2694 int numCells = MeshActor->DataSource->GetNumberOfCells();
2696 // Loop over points and generate ids
2697 vtkIntArray *cellIds = vtkIntArray::New();
2698 cellIds->SetNumberOfValues(numCells);
2700 for (int id=0; id < numCells; id++) {
2701 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
2702 cellIds->SetValue(id, idSMDS);
2705 // mpv porting vk4.2.2
2706 // vtkScalars* newScalars = vtkScalars::New();
2707 // newScalars->SetData(cellIds);
2708 elGrid->GetCellData()->SetScalars(cellIds);
2709 // elGrid->GetCellData()->SetScalars(newScalars);
2710 // newScalars->Delete();
2715 vtkCellCenters* cc = vtkCellCenters::New();
2716 cc->SetInput(elGrid);
2718 vtkSelectVisiblePoints* visCells = vtkSelectVisiblePoints::New();
2719 visCells->SetInput(cc->GetOutput());
2720 visCells->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2721 visCells->SelectInvisibleOff();
2722 visCells->SetTolerance(0.1);
2723 // visCells->SetSelectInvisible(1);
2725 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2726 ldm->SetInput(visCells->GetOutput());
2727 ldm->SetLabelFormat("%g");
2728 ldm->SetLabelModeToLabelScalars();
2730 ldm->SetFontFamilyToTimes();
2731 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2736 vtkActor2D* cellLabels = vtkActor2D::New();
2737 cellLabels->SetMapper(ldm);
2738 cellLabels->GetProperty()->SetColor(1,0,0);
2743 smeshGUI->mySimulationActors2D->AddItem( cellLabels );
2744 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( cellLabels );
2748 QApplication::setOverrideCursor( Qt::waitCursor );
2749 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2750 smeshGUI->EraseSimulationActors();
2751 smeshGUI->ScalarVisibilityOff();
2753 QApplication::restoreOverrideCursor();
2757 case 10001: // DISPLAY MODE PREFERENCE
2759 parent->menuBar()->setItemChecked(10001, !parent->menuBar()->isItemChecked(10001) );
2760 parent->menuBar()->setItemChecked(10002, false );
2761 parent->menuBar()->setItemChecked(10003, false );
2762 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2767 parent->menuBar()->setItemChecked(10002, !parent->menuBar()->isItemChecked(10002) );
2768 parent->menuBar()->setItemChecked(10001, false );
2769 parent->menuBar()->setItemChecked(10003, false );
2770 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2775 parent->menuBar()->setItemChecked(10003, !parent->menuBar()->isItemChecked(10003) );
2776 parent->menuBar()->setItemChecked(10002, false );
2777 parent->menuBar()->setItemChecked(10001, false );
2778 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
2784 smeshGUI->myActiveStudy->updateObjBrowser(true);
2789 //=============================================================================
2790 /*! function : GetMeshesUsingAlgoOrHypothesis()
2791 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
2792 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
2794 //=============================================================================
2795 SALOMEDS::Study::ListOfSObject* SMESHGUI::GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp )
2797 SALOMEDS::Study::ListOfSObject_var listSOmesh = new SALOMEDS::Study::ListOfSObject ;
2798 listSOmesh->length(0) ;
2799 unsigned int index = 0 ;
2800 if( !AlgoOrHyp->_is_nil() ) {
2801 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms( AlgoOrHyp );
2802 if( !SO_Hypothesis->_is_nil() ) {
2803 SALOMEDS::Study::ListOfSObject_var listSO = smeshGUI->myStudy->FindDependances(SO_Hypothesis) ;
2804 for( unsigned int i=0; i<listSO->length(); i++ ) {
2805 SALOMEDS::SObject_var SO = listSO[i] ;
2806 if( !SO->_is_nil() ) {
2807 SALOMEDS::SObject_var SOfatherFather = SO->GetFather()->GetFather() ;
2808 if( !SOfatherFather->_is_nil() ) {
2810 listSOmesh->length(index) ;
2811 listSOmesh[index-1] = SOfatherFather ;
2817 return listSOmesh._retn() ;
2821 //=============================================================================
2825 //=============================================================================
2826 void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
2830 Mesh_Reader* myReader;
2832 if (theCommandID==113) {
2833 filter = tr("MED files (*.med)");
2834 myExtension = string("MED");
2835 myReader = new DriverMED_R_SMESHDS_Mesh;
2837 else if (theCommandID==112) {
2838 filter = tr("IDEAS files (*.unv)");
2839 myExtension = string("UNV");
2841 else if (theCommandID==111) {
2842 filter = tr("DAT files (*.dat)");
2843 myExtension = string("MED");
2844 myReader = new DriverDAT_R_SMESHDS_Mesh;
2847 QString filename = QAD_FileDlg::getFileName(parent,
2852 if ( !filename.isEmpty() ) {
2853 QApplication::setOverrideCursor( Qt::waitCursor );
2854 string myClass = string("SMESHDS_Mesh");
2855 // Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
2857 int myMeshId = (smeshGUI->myDocument)->NewMesh();
2858 SMDS_Mesh* myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
2860 myReader->SetFile(string(filename.latin1()));
2861 myReader->SetMesh(myMesh);
2862 myReader->SetMeshId(myMeshId);
2865 QApplication::restoreOverrideCursor();
2869 //=============================================================================
2873 //=============================================================================
2874 void SMESHGUI::Export_Mesh(QAD_Desktop* parent, int theCommandID)
2876 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2877 int nbSel = Sel->IObjectCount() ;
2879 Standard_Boolean res;
2880 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2881 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh( IObject, res );
2883 if (theCommandID==122) { // EXPORT MED
2884 QString filename = QAD_FileDlg::getFileName(parent,
2886 tr("MED files (*.med)"),
2889 if ( !filename.isEmpty() ) {
2890 QApplication::setOverrideCursor( Qt::waitCursor );
2891 aMesh->ExportMED( filename.latin1() );
2892 QApplication::restoreOverrideCursor();
2895 else if (theCommandID==121) { // EXPORT DAT
2896 QString filename = QAD_FileDlg::getFileName(parent,
2898 tr("DAT files (*.dat)"),
2901 if ( !filename.isEmpty() ) {
2902 QApplication::setOverrideCursor( Qt::waitCursor );
2903 aMesh->ExportDAT( filename.latin1() );
2904 QApplication::restoreOverrideCursor();
2907 else if (theCommandID==123) { // EXPORT UNV
2908 QString filename = QAD_FileDlg::getFileName(parent,
2910 tr("IDEAS files (*.unv)"),
2913 if ( !filename.isEmpty() ) {
2914 QApplication::setOverrideCursor( Qt::waitCursor );
2915 aMesh->ExportUNV( filename.latin1() );
2916 QApplication::restoreOverrideCursor();
2919 aMesh->ExportDAT( filename.latin1() );
2921 QApplication::restoreOverrideCursor();
2923 if ( IObject->hasEntry() )
2926 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2927 SALOMEDS::GenericAttribute_var anAttr;
2928 SALOMEDS::AttributeComment_var aFileName;
2929 SALOMEDS::StudyBuilder_var aStudyBuilder = smeshGUI->myStudy->NewBuilder();
2930 anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
2931 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
2932 aFileName->SetValue(filename.latin1());
2939 //=============================================================================
2943 //=============================================================================
2944 void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
2948 Document_Reader* myReader;
2950 if (theCommandID==113) {
2951 filter = tr("MED files (*.med)");
2952 myExtension = string("MED");
2953 myReader = new DriverMED_R_SMESHDS_Document;
2955 else if (theCommandID==112) {
2956 filter = tr("IDEAS files (*.unv)");
2957 myExtension = string("UNV");
2958 myReader = new DriverUNV_R_SMESHDS_Document;
2960 else if (theCommandID==111) {
2961 filter = tr("DAT files (*.dat)");
2962 myExtension = string("DAT");
2963 myReader = new DriverDAT_R_SMESHDS_Document;
2966 QString filename = QAD_FileDlg::getFileName(parent,
2969 tr("Import document"),
2971 if ( !filename.isEmpty() ) {
2972 QApplication::setOverrideCursor( Qt::waitCursor );
2973 string myClass = string("SMESHDS_Document");
2974 // Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
2975 SMESHDS_Document* newDocument = new SMESHDS_Document(1);
2977 myReader->SetFile(string(filename.latin1()));
2978 myReader->SetDocument(smeshGUI->myDocument);
2980 QApplication::restoreOverrideCursor();
2984 void SMESHGUI::Export_Document(QAD_Desktop* parent, int theCommandID)
2987 Document_Writer* myWriter;
2990 if (theCommandID==122) {
2991 filter = tr("MED files (*.med)");
2992 myExtension = string("MED");
2993 myWriter = new DriverMED_W_SMESHDS_Document;
2995 else if (theCommandID==121) {
2996 filter = tr("DAT files (*.dat)");
2997 myExtension = string("DAT");
2998 myWriter = new DriverDAT_W_SMESHDS_Document;
2999 } else if (theCommandID==123) {
3000 filter = tr("IDEAS files (*.unv)");
3001 myExtension = string("UNV");
3002 myWriter = new DriverUNV_W_SMESHDS_Document;
3005 QString filename = QAD_FileDlg::getFileName(parent,
3008 tr("Export document"),
3010 if ( !filename.isEmpty() ) {
3011 QApplication::setOverrideCursor( Qt::waitCursor );
3012 string myClass = string("SMESHDS_Document");
3013 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
3015 myWriter->SetFile(string(filename.latin1()));
3016 myWriter->SetDocument(smeshGUI->myDocument);
3018 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
3019 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
3020 //myWriter->SetDocument(myDocument);
3023 QApplication::restoreOverrideCursor();
3027 //=============================================================================
3031 //=============================================================================
3032 bool SMESHGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3034 SMESHGUI::GetOrCreateSMESHGUI(parent);
3039 //=============================================================================
3043 //=============================================================================
3044 bool SMESHGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3046 SMESHGUI::GetOrCreateSMESHGUI(parent);
3052 //=============================================================================
3056 //=============================================================================
3057 bool SMESHGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3059 SMESHGUI::GetOrCreateSMESHGUI(parent);
3065 //=============================================================================
3069 //=============================================================================
3070 bool SMESHGUI::SetSettings( QAD_Desktop* parent )
3072 SMESHGUI::GetOrCreateSMESHGUI(parent);
3075 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3076 if ( DisplayMode.compare("") == 0 ) {
3077 DisplayMode = "Shading";
3078 QAD_CONFIG->addSetting("SMESH:DisplayMode","Shading");
3081 if ( DisplayMode.compare("Wireframe") == 0 ){
3082 parent->menuBar()->setItemChecked(10003, false );
3083 parent->menuBar()->setItemChecked(10002, false );
3084 parent->menuBar()->setItemChecked(10001, true );
3085 } else if ( DisplayMode.compare("Shading") == 0 ){
3086 parent->menuBar()->setItemChecked(10003, false );
3087 parent->menuBar()->setItemChecked(10002, true );
3088 parent->menuBar()->setItemChecked(10001, false );
3089 } else if ( DisplayMode.compare("Shrink") == 0 ) {
3090 parent->menuBar()->setItemChecked(10003, true );
3091 parent->menuBar()->setItemChecked(10002, false );
3092 parent->menuBar()->setItemChecked(10001, false );
3095 /* Automatic Update */
3096 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3097 if ( AutoUpdate.compare("true") == 0 ) {
3098 parent->menuBar()->setItemChecked(1001, true );
3099 smeshGUI->myAutomaticUpdate = true;
3101 parent->menuBar()->setItemChecked(1001, false );
3102 smeshGUI->myAutomaticUpdate = false;
3106 parent->menuBar()->setItemEnabled( 11, false); // IMPORT
3112 //=============================================================================
3116 //=============================================================================
3117 void SMESHGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
3119 /* Create or retrieve an object SMESHGUI */
3120 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3122 // NRI : Temporary added
3123 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3124 // theObject = "NothingSelected";
3125 // theContext = "NothingSelected";
3129 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3130 int nbSel = Sel->IObjectCount();
3132 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3133 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
3134 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1) ) {
3135 theObject = "ScalarBar";
3138 theObject = "NothingSelected";
3139 theContext = "NothingSelected";
3142 theObject = "NothingSelected";
3143 theContext = "NothingSelected";
3145 } else if (nbSel == 1 ) {
3146 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3149 theObject = smeshGUI->CheckHomogeneousSelection();
3154 //=============================================================================
3158 //=============================================================================
3159 bool SMESHGUI::CustomPopup( QAD_Desktop* parent,
3161 const QString& theContext,
3162 const QString& theParent,
3163 const QString& theObject )
3165 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3166 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3168 /* Create or retrieve an object SMESHGUI */
3169 SMESHGUI::GetOrCreateSMESHGUI(parent);
3171 // NRI : Temporary added
3172 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3177 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3178 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3179 int nbSel = Sel->IObjectCount();
3182 if (studyFrame->getTypeView() != VIEW_VTK)
3185 } else if (nbSel == 1 ) {
3186 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3187 // First check type of active viewer (VTK required)
3188 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3190 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3192 int id = popup->idAt(0);
3193 if (id <= QAD_TopLabel_Popup_ID)
3194 popup->removeItemAt(0);
3198 if (theObject.compare("Component") == 0) {
3199 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3204 // Remove common popup items for Submesh, Hypothesis and Algorithm
3205 if (theObject.compare("SubMesh") == 0 ||
3206 theObject.compare("Hypothesis") == 0 ||
3207 theObject.compare("Algorithm") == 0 ) {
3208 popup->removeItem(QAD_Display_Popup_ID);
3209 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3210 popup->removeItem(QAD_Erase_Popup_ID);
3211 int id = popup->idAt(popup->count()-1); // last item
3212 if (id < 0 && id != -1) popup->removeItem(id); // separator
3215 if (theObject.compare("Component") == 0) {
3216 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3220 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3221 QFont f = QApplication::font();
3224 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3226 if ( theParent.compare("Viewer")==0 ) {
3227 if (popup->idAt(0) == id) {
3228 popup->removeItem(id);
3229 popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), id, 0 );
3232 Standard_Boolean res;
3233 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3234 if ( res && studyFrame->getTypeView() == VIEW_VTK) {
3235 VTKViewer_RenderWindowInteractor* myRenderInter=
3236 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3237 if ( myRenderInter->isVisible( IObject ) ) {
3238 popup->removeItem(QAD_Display_Popup_ID);
3240 popup->removeItem(QAD_Erase_Popup_ID);
3243 popup->removeItem(QAD_Erase_Popup_ID);
3244 if (!res) {// mesh not computed -> can't display it
3245 popup->removeItem(QAD_Display_Popup_ID);
3246 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3247 popup->removeItemAt(popup->count() - 1);//separator
3250 } else if ( theParent.compare("ObjectBrowser")==0 ) {
3251 if (theObject.compare("Mesh") == 0 ||
3252 theObject.compare("SubMesh") == 0 ||
3253 theObject.compare("Hypothesis") == 0 ||
3254 theObject.compare("Algorithm") == 0 ) {
3255 popup->removeItemAt(0);
3257 if (popup->idAt(0) == id) {
3258 popup->removeItem(id);
3259 popup->removeItemAt(0);//separator
3263 Standard_Boolean res;
3264 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3265 if ( res && studyFrame->getTypeView() == VIEW_VTK ) {
3266 VTKViewer_RenderWindowInteractor* myRenderInter=
3267 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3268 if ( myRenderInter->isVisible( IObject ) ) {
3269 popup->removeItem(QAD_Display_Popup_ID);
3271 popup->removeItem(QAD_Erase_Popup_ID);
3274 if (theObject.compare("Mesh") == 0 ||
3275 theObject.compare("SubMesh") == 0 ||
3276 theObject.compare("Hypothesis") == 0 ||
3277 theObject.compare("Algorithm") == 0 ) {
3279 popup->removeItem(QAD_Erase_Popup_ID);
3280 if (!res) {// mesh not computed -> can't display it
3281 popup->removeItem(QAD_Display_Popup_ID);
3282 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3283 popup->removeItemAt(popup->count() - 1);//separator
3289 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3290 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3291 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3293 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3295 int id = popup->idAt(0);
3296 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3297 popup->removeItemAt(0);
3301 if (parentComp.isNull()) { // objects from several components are selected
3302 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3303 popup->removeItem(QAD_Display_Popup_ID);
3304 popup->removeItem(QAD_Erase_Popup_ID);
3305 int id = popup->idAt(popup->count()-1); // last item
3306 if (id < 0 && id != -1) popup->removeItem(id); // separator
3311 QString type = smeshGUI->CheckHomogeneousSelection();
3312 if ( type.compare("Heterogeneous Selection") != 0 ) {
3313 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3314 QFont f = QApplication::font();
3316 popup->removeItem(id);
3317 popup->insertItem( new CustomItem ( QString("%1 ").arg(nbSel) + type + " (s) ", f), id, 0 );
3323 //=============================================================================
3324 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3325 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3327 //=============================================================================
3328 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3330 /* Create or retrieve an object SMESHGUI */
3331 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3333 QAD_StudyFrame* activeFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3334 if (activeFrame->getTypeView() == VIEW_VTK) {
3336 SALOMEDS::SObject_var fatherSF =
3337 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
3339 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3340 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3342 // for(;It.More();It.Next()) {
3343 // Handle(SALOME_InteractiveObject) IObject = It.Value();
3344 Handle(SALOME_InteractiveObject) IObject = theIO;
3345 if ( IObject->hasEntry() ) {
3346 // Look for the actor in all views
3347 Standard_Boolean res;
3348 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3350 // Actor not found at all -> mesh is not computed -> do nothing!!!
3352 /*SMESH::SMESH_Mesh_var aM;
3353 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3354 SALOMEDS::SObject_var father = aMorSM->GetFather();
3355 SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
3357 // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
3358 if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
3361 SALOMEDS::GenericAttribute_var anAttr;
3362 SALOMEDS::AttributeIOR_var anIOR;
3363 if ( !aMorSM->_is_nil() ) {
3364 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
3365 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3366 aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
3370 if (!aM->_is_nil()) {
3371 smeshGUI->InitActor(aM);
3372 ac = smeshGUI->ReadScript(aM);
3376 smeshGUI->DisplayActor( ac, true );
3377 smeshGUI->DisplayEdges( ac );
3378 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3381 } else { // The actor exists in some view
3382 // Check whether the actor belongs to the active view
3383 VTKViewer_RenderWindowInteractor* rwInter =
3384 ((VTKViewer_ViewFrame*)activeFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3386 // The actor belongs to inactive view -> create a copy and display it in the active view
3387 if (!rwInter->isInViewer(IObject)) {
3388 SMESH_Actor* acCopy = SMESH_Actor::New();
3389 acCopy->ShallowCopy(ac);
3392 smeshGUI->DisplayActor( ac, false );
3393 smeshGUI->DisplayEdges( ac );
3394 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3399 MESSAGE("BuildPresentation() must not be called while non-VTK view is active")
3403 //=============================================================================
3407 //=============================================================================
3408 void SMESHGUI::setOrb()
3411 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
3412 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
3413 _orb = init( 0 , 0 );
3415 INFOS("internal error : orb not found");
3418 ASSERT(! CORBA::is_nil(_orb));
3422 //=============================================================================
3426 //=============================================================================
3427 SMESH_Actor* SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
3429 SMESH_Actor* MeshActor;
3430 if ( !aMesh->_is_nil() ) {
3431 Standard_Boolean result;
3432 MeshActor = FindActor(aMesh, result, true);
3434 SMESH::log_array_var aSeq = aMesh->GetLog(true);
3436 if (aSeq->length() == 0) {
3437 MESSAGE("ReadScript(): log is empty")
3441 for (unsigned int ind = 0; ind < aSeq->length();ind++) {
3442 switch ( aSeq[ind].commandType )
3444 case SMESH::ADD_NODE :
3446 AddNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3449 case SMESH::ADD_EDGE :
3451 // AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3454 case SMESH::ADD_TRIANGLE :
3456 AddTriangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3459 case SMESH::ADD_QUADRANGLE :
3461 AddQuadrangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3464 case SMESH::ADD_TETRAHEDRON :
3466 AddTetras( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3469 case SMESH::ADD_PYRAMID :
3473 case SMESH::ADD_PRISM :
3477 case SMESH::ADD_HEXAHEDRON :
3479 AddHexaedres( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3482 case SMESH::REMOVE_NODE :
3484 RemoveNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3487 case SMESH::REMOVE_ELEMENT :
3489 RemoveElements( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3501 //=============================================================================
3505 //=============================================================================
3506 void SMESHGUI::Dump(SMESH_Actor* Mactor)
3508 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3509 vtkPoints *Pts = ugrid->GetPoints();
3510 int nbPts = Pts->GetNumberOfPoints();
3511 int nbCells = ugrid->GetNumberOfCells();
3515 In = fopen("/tmp/dumpMesh","w+");
3516 fprintf(In,"%d %d\n",nbPts,nbCells);
3517 for ( int i = 0; i < nbPts; i++ ) {
3518 float *p = ugrid->GetPoint(i);
3519 fprintf(In,"%d %e %e %e\n",i, p[0], p[1], p[2] );
3522 for ( int i = 0; i < nbCells; i++ ) {
3523 fprintf(In,"%d %d",i,ugrid->GetCell(i)->GetCellType());
3524 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3525 for (j=0; j<Id->GetNumberOfIds(); j++) {
3526 fprintf(In," %d",Id->GetId(j));
3534 //=============================================================================
3538 //=============================================================================
3539 void SMESHGUI::AddNodes( SMESH_Actor* Mactor, int number,
3540 const SMESH::double_array& coords,
3541 const SMESH::long_array& indexes)
3543 QApplication::setOverrideCursor( Qt::waitCursor );
3544 if ( Mactor->GetMapper() == NULL ) {
3545 vtkPoints *Pts = vtkPoints::New();
3546 SMESH_Grid *ugrid = SMESH_Grid::New();
3551 while ( i <= number ) {
3552 int idVTK = Pts->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3553 //Mactor->AddNode( indexes[i-1], idVTK );
3554 ugrid->AddNode( indexes[i-1], idVTK );
3558 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3559 ugrid->SetPoints(Pts);
3560 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3561 PtsMapper->SetInput( ugrid );
3562 Mactor->DataSource = PtsMapper->GetInput();
3563 Mactor->SetMapper(PtsMapper);
3565 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3566 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3569 while ( i <= number ) {
3570 int idVTK = ugrid->GetPoints()->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3571 ugrid->AddNode( indexes[i-1], idVTK );
3575 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3576 PtsMapper->SetInput( ugrid );
3577 Mactor->DataSource = PtsMapper->GetInput();
3578 Mactor->SetMapper(PtsMapper);
3580 QApplication::restoreOverrideCursor();
3583 //=============================================================================
3587 //=============================================================================
3588 void SMESHGUI::AddNode(SMESH_Actor* Mactor, int idnode, float x, float y, float z)
3590 QApplication::setOverrideCursor( Qt::waitCursor );
3591 MESSAGE ( "SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z )
3592 if ( Mactor->GetMapper() == NULL ) {
3593 vtkPoints *Pts = vtkPoints::New();
3594 int idVTK = Pts->InsertNextPoint( x, y, z );
3595 //Mactor->AddNode( idnode, idVTK );
3596 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3597 SMESH_Grid *ugrid = SMESH_Grid::New();
3599 ugrid->AddNode( idnode, idVTK );
3600 ugrid->SetPoints(Pts);
3601 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3602 PtsMapper->SetInput( ugrid );
3603 Mactor->DataSource = PtsMapper->GetInput();
3604 Mactor->SetMapper(PtsMapper);
3606 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3607 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3608 int idVTK = ugrid->GetPoints()->InsertNextPoint( x, y, z );
3609 //Mactor->AddNode( idnode, idVTK );
3610 ugrid->AddNode( idnode, idVTK );
3611 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3612 PtsMapper->SetInput( ugrid );
3613 Mactor->DataSource = PtsMapper->GetInput();
3614 Mactor->SetMapper(PtsMapper);
3616 QApplication::restoreOverrideCursor();
3619 //=============================================================================
3623 //=============================================================================
3624 void SMESHGUI::RemoveNode(SMESH_Actor* Mactor, int idnode)
3626 MESSAGE ( " OLD RemoveNode method " )
3627 // int id = Mactor->GetIdVTKNode( idnode );
3628 // MESSAGE ( " RemoveNode id VTK " << id )
3629 // if ( Mactor->GetMapper() != NULL ) {
3630 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3631 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3632 // vtkPoints *Pts = ugrid->GetPoints();
3633 // vtkPoints *newPts = vtkPoints::New();
3634 // int nbPts = Pts->GetNumberOfPoints();
3635 // bool findPt = false;
3636 // for ( int i = 0; i < nbPts; i++ ) {
3639 // newPts->InsertPoint(i, Pts->GetPoint(i) );
3641 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
3644 // Mactor->RemoveNode( idnode );
3648 // newUgrid->SetPoints(newPts);
3649 // int nbCells = ugrid->GetNumberOfCells();
3650 // for ( int i = 0; i < nbCells; i++ ) {
3651 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3652 // vtkIdList *newIds = vtkIdList::New();
3653 // int nbIds = Ids->GetNumberOfIds();
3654 // newIds->SetNumberOfIds(nbIds);
3655 // for ( int j = 0; j < nbIds; j++ ) {
3656 // int theid = Ids->GetId(j);
3657 // if ( theid > id ) {
3658 // newIds->SetId( j, theid-1 );
3660 // newIds->SetId( j, theid );
3662 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3663 // Mactor->RemoveElement( idSMDSel, false );
3664 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3665 // Mactor->AddElement( idSMDSel, idVTKel );
3669 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3670 // Mapper->SetInput( newUgrid );
3671 // Mactor->DataSource = Mapper->GetInput();
3672 // Mactor->SetMapper(Mapper);
3678 //=============================================================================
3682 //=============================================================================
3683 void SMESHGUI::RemoveNodes(SMESH_Actor* Mactor, int number,
3684 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3686 QApplication::setOverrideCursor( Qt::waitCursor );
3688 while ( i <= number ) {
3689 Mactor->RemoveNode( indexes[i-1] );
3693 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
3694 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
3695 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
3697 if ( Mactor->GetMapper() != NULL ) {
3698 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3699 SMESH_Grid *newUgrid = SMESH_Grid::New();
3700 newUgrid->CopyMaps(ugrid);
3702 vtkPoints *Pts = ugrid->GetPoints();
3703 vtkPoints *newPts = vtkPoints::New();
3704 int nbPts = Pts->GetNumberOfPoints();
3706 for ( int i = 0; i < nbPts; i++ ) {
3707 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
3708 if ( idSMESHDSNode != -1 ) {
3709 newPts->InsertPoint(j, Pts->GetPoint(i) );
3711 newMapVTKNodes.Bind(j, idSMESHDSNode);
3712 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
3714 MapOldNodesToNewNodes.Bind(i,j);
3719 newUgrid->SetIdsVTKNode(newMapVTKNodes);
3720 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
3721 newUgrid->SetPoints(newPts);
3723 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3724 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3726 int nbCells = ugrid->GetNumberOfCells();
3727 for ( int i = 0; i < nbCells; i++ ) {
3728 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3729 vtkIdList *newIds = vtkIdList::New();
3730 int nbIds = Ids->GetNumberOfIds();
3731 newIds->SetNumberOfIds(nbIds);
3733 for ( int j = 0; j < nbIds; j++ ) {
3734 int theid = Ids->GetId(j);
3735 if ( MapOldNodesToNewNodes.IsBound( theid ) ) {
3736 newIds->SetId( j, MapOldNodesToNewNodes.Find( theid ) );
3743 // Filtering out cells based on non-existing nodes
3745 int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3746 int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3748 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
3749 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
3753 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3754 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3756 // Copy new data to the old DatSource: keep the single DataSource for all actors
3757 ugrid->DeepCopy(newUgrid);
3759 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3760 Mapper->SetInput( ugrid );
3761 Mactor->SetMapper(Mapper);
3763 // Commented to avoid multiple viewer updates when called by ReadScript()
3767 QApplication::restoreOverrideCursor();
3770 //=============================================================================
3774 //=============================================================================
3775 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3777 QApplication::setOverrideCursor( Qt::waitCursor );
3778 Standard_Boolean result;
3779 SMESH_Actor* ac = FindActor( aMesh, result, true );
3781 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3782 anArrayOfIdeces->length(MapIndex.Extent());
3783 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3785 for ( ; ite.More(); ite.Next() ) {
3786 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
3787 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
3790 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3791 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3794 if ( myAutomaticUpdate ) {
3795 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3796 if ( Mesh != NULL ) {
3797 smeshGUI->DisplayActor( Mesh );
3798 smeshGUI->DisplayEdges( Mesh );
3799 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3800 AddActorInSelection( Mesh );
3803 QApplication::restoreOverrideCursor();
3806 //=============================================================================
3810 //=============================================================================
3811 void SMESHGUI::RemoveElement(SMESH_Actor* Mactor, int idelement)
3813 MESSAGE ( " OLD RemoveElement method " )
3814 // int id = Mactor->GetIdVTKElement( idelement );
3815 // MESSAGE ( " RemoveElement id VTK : " << id )
3816 // if ( Mactor->GetMapper() != NULL ) {
3817 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3818 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3820 // int nbCells = ugrid->GetNumberOfCells();
3821 // for ( int i = 0; i < nbCells; i++ ) {
3823 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3824 // ugrid->GetCell(i)->GetPointIds() );
3826 // Mactor->RemoveElement( idelement );
3828 // newUgrid->SetPoints(ugrid->GetPoints());
3830 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3831 // Mapper->SetInput( newUgrid );
3832 // Mactor->DataSource = Mapper->GetInput();
3833 // Mactor->SetMapper(Mapper);
3839 //=============================================================================
3843 //=============================================================================
3844 void SMESHGUI::RemoveElements(SMESH_Actor* Mactor, int number,
3845 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3847 QApplication::setOverrideCursor( Qt::waitCursor );
3849 while ( i <= number ) {
3850 Mactor->RemoveElement( indexes[i-1] );
3853 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3854 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3856 if ( Mactor->GetMapper() != NULL ) {
3857 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3858 SMESH_Grid* newUgrid = SMESH_Grid::New();
3859 newUgrid->CopyMaps(ugrid);
3861 int nbCells = ugrid->GetNumberOfCells();
3862 for ( int i = 0; i < nbCells; i++ ) {
3863 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
3864 if ( idSMESHDSElement != -1 ) {
3865 int newId = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3866 ugrid->GetCell(i)->GetPointIds() );
3867 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
3868 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
3872 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3873 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3875 newUgrid->SetPoints(ugrid->GetPoints());
3877 // Copy new data to the old DatSource: keep the single DataSource for all actors
3878 ugrid->DeepCopy(newUgrid);
3880 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3881 Mapper->SetInput( ugrid );
3882 Mactor->SetMapper(Mapper);
3884 // Commented to avoid multiple viewer updates when called by ReadScript()
3887 QApplication::restoreOverrideCursor();
3890 //=============================================================================
3894 //=============================================================================
3895 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3897 QApplication::setOverrideCursor( Qt::waitCursor );
3898 Standard_Boolean result;
3899 SMESH_Actor* ac = FindActor( aMesh, result, true );
3901 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3902 anArrayOfIdeces->length(MapIndex.Extent());
3903 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3905 for ( ; ite.More(); ite.Next() ) {
3906 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
3907 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
3911 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3912 aMeshEditor->RemoveElements(anArrayOfIdeces);
3915 if ( myAutomaticUpdate ) {
3916 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3917 if ( Mesh != NULL ) {
3918 smeshGUI->DisplayActor( Mesh );
3919 smeshGUI->DisplayEdges( Mesh );
3920 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3921 AddActorInSelection( Mesh );
3927 QApplication::restoreOverrideCursor();
3931 //=============================================================================
3935 //=============================================================================
3936 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3938 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3941 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3942 Standard_Boolean result;
3943 SMESH_Actor* ac = FindActor( aMesh, result, true );
3945 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3946 SMESH_Grid* UGrid = SMESH_Grid::New();
3947 SMESH_Grid* oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
3948 UGrid->CopyMaps(oldGrid);
3950 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3951 gf->SetInput( ac->DataSource );
3953 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3954 Mapper->SetInput( gf->GetOutput() );
3957 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3958 for ( ; ite.More(); ite.Next() ) {
3959 Mapper->GetInput()->ReverseCell( ite.Key() );
3962 UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
3963 int nbCells = Mapper->GetInput()->GetNumberOfCells();
3964 for ( int i = 0; i < nbCells; i++ ) {
3965 UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
3968 // Copy new data to the old DatSource: keep the single DataSource for all actors
3969 oldGrid->DeepCopy(UGrid);
3971 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
3972 //NewMapper->SetInput( UGrid );
3973 NewMapper->SetInput( oldGrid );
3974 NewMapper->Update();
3976 //ac->DataSource = NewMapper->GetInput();
3977 ac->SetMapper( NewMapper );
3979 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3981 QApplication::restoreOverrideCursor();
3985 //=============================================================================
3989 //=============================================================================
3990 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3992 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3995 QApplication::setOverrideCursor( Qt::waitCursor );
3996 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3997 Standard_Boolean result;
3999 SMESH_Actor* ac = FindActor( aMesh, result, true );
4001 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4002 SMESH_Grid* UGrid = SMESH_Grid::New();
4003 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4004 gf->SetInput( ac->DataSource );
4006 vtkExtractEdges *edges = vtkExtractEdges::New();
4007 edges->SetInput( ac->DataSource );
4009 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4010 Mapper->SetInput( edges->GetOutput() );
4013 int nb = Mapper->GetInput()->GetNumberOfCells();
4014 //MESSAGE ( "nb : " << nb )
4016 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
4017 for ( ; ite.More(); ite.Next() ) {
4018 vtkCell* StartEdge = Mapper->GetInput()->GetCell(ite.Key());
4019 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
4020 int CellType = StartEdge->GetCellType();
4021 //MESSAGE( "DCQ : Cell Type = " << CellType)
4022 int nbPoints = StartEdge->GetNumberOfPoints();
4024 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4025 if ( nbPoints == 2 ) {
4026 vtkUnstructuredGrid* StartUGrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
4028 vtkIdList *IdCells = vtkIdList::New();
4029 vtkIdList *IdPoints = StartEdge->GetPointIds();
4033 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),p1);
4034 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),p2);
4036 int idp1 = StartUGrid->FindPoint(p1);
4037 int idp2 = StartUGrid->FindPoint(p2);
4039 StartUGrid->GetPointCells( idp1, IdCells );
4041 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4042 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4044 //MESSAGE ( " pt 0 : " << idp1 )
4045 //MESSAGE ( " pt 1 : " << idp2 )
4047 vtkIdList *IdPts = vtkIdList::New();
4048 if (IdCells->GetNumberOfIds() >= 2) {
4049 int nbCells = IdCells->GetNumberOfIds();
4050 //MESSAGE ( " nbCells : " << nbCells )
4051 for (int j=0; j<nbCells; j++) {
4052 StartUGrid->GetCellPoints( IdCells->GetId(j), IdPts );
4053 if ( IdPts->IsId( idp2 ) == -1 ) {
4054 IdCells->DeleteId( IdCells->GetId(j) );
4059 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4061 vtkIdList *IdPts0 = vtkIdList::New();
4062 vtkIdList *IdPts1 = vtkIdList::New();
4064 if (IdCells->GetNumberOfIds() == 2) {
4065 StartUGrid->GetCellPoints( IdCells->GetId(0), IdPts0 );
4066 StartUGrid->GetCellPoints( IdCells->GetId(1), IdPts1 );
4069 TColStd_MapOfInteger EndMapIndex;
4070 for (int j = 0; j < 3; j++ ) {
4071 if ( IdPts0->GetId(j) != idp1 && IdPts0->GetId(j) != idp2 ) {
4072 EndMapIndex.Add( IdPts0->GetId(j) );
4074 if ( IdPts1->GetId(j) != idp1 && IdPts1->GetId(j) != idp2 ) {
4075 EndMapIndex.Add( IdPts1->GetId(j) );
4079 bool MyAU = myAutomaticUpdate ;
4080 myAutomaticUpdate = false ;
4082 EndMapIndex.Add( idp1 );
4083 TColStd_MapIteratorOfMapOfInteger ite1( EndMapIndex );
4085 while ( ite1.More() ) {
4086 if ( ite1.Key() == idp1 )
4091 bool reverse1 = ( i == 2 );
4092 this->AddFace( aMesh, EndMapIndex, reverse1 );
4094 EndMapIndex.Remove( idp1 );
4095 EndMapIndex.Add( idp2 );
4096 TColStd_MapIteratorOfMapOfInteger ite2( EndMapIndex );
4098 while ( ite2.More() ) {
4099 if ( ite2.Key() == idp2 )
4104 bool reverse2 = ( i == 2 );
4105 this->AddFace( aMesh, EndMapIndex, !(reverse1 == reverse2) );
4107 myAutomaticUpdate = MyAU ;
4108 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4111 TColStd_MapOfInteger StartMapIndex;
4112 StartMapIndex.Add( IdCells->GetId(0) );
4113 StartMapIndex.Add( IdCells->GetId(1) );
4114 this->RemoveElements( aMesh, StartMapIndex );
4122 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4123 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4124 // for ( int i = 0; i < nbCells; i++ ) {
4125 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4128 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4129 // NewMapper->SetInput( UGrid );
4130 // NewMapper->Update();
4132 // ac->DataSource = NewMapper->GetInput();
4133 // ac->SetMapper( NewMapper );
4135 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4137 QApplication::restoreOverrideCursor();
4141 //=============================================================================
4145 //=============================================================================
4146 void SMESHGUI::AddEdges( SMESH_Actor* Mactor, int number,
4147 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4149 QApplication::setOverrideCursor( Qt::waitCursor );
4150 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4151 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4154 while ( i <= number ) {
4155 vtkIdList *Ids = vtkIdList::New();
4156 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4157 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4158 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4159 Mactor->AddElement( indexes[j-1], id );
4163 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4164 EdgeMapper->SetInput( ugrid );
4165 Mactor->DataSource = EdgeMapper->GetInput();
4166 Mactor->SetMapper(EdgeMapper);
4167 QApplication::restoreOverrideCursor();
4170 //=============================================================================
4174 //=============================================================================
4175 void SMESHGUI::AddEdge(SMESH_Actor* Mactor, int idedge, int idnode1, int idnode2)
4177 QApplication::setOverrideCursor( Qt::waitCursor );
4178 MESSAGE ( "SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" << idnode2 )
4179 vtkIdList *Ids = vtkIdList::New();
4180 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4181 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4183 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4184 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4185 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4186 Mactor->AddElement( idedge, id );
4188 MESSAGE ( " Edge VTK id " << id )
4190 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4191 EdgeMapper->SetInput( ugrid );
4192 Mactor->DataSource = EdgeMapper->GetInput();
4193 Mactor->SetMapper(EdgeMapper);
4194 QApplication::restoreOverrideCursor();
4197 //=============================================================================
4201 //=============================================================================
4202 void SMESHGUI::AddTriangles( SMESH_Actor* Mactor, int number,
4203 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4205 QApplication::setOverrideCursor( Qt::waitCursor );
4206 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4207 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4210 while ( i <= number ) {
4211 vtkIdList *Ids = vtkIdList::New();
4212 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4213 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4214 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4215 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4216 Mactor->AddElement( indexes[j-1], id );
4220 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4221 TriMapper->SetInput( ugrid );
4222 Mactor->DataSource = TriMapper->GetInput();
4223 Mactor->SetMapper(TriMapper);
4224 QApplication::restoreOverrideCursor();
4226 void SMESHGUI::AddTriangle(SMESH_Actor* Mactor, int idtri, int idnode1, int idnode2, int idnode3)
4228 QApplication::setOverrideCursor( Qt::waitCursor );
4229 vtkIdList *Ids = vtkIdList::New();
4230 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4231 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4232 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4234 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4235 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4236 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4237 Mactor->AddElement( idtri, id );
4239 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4240 TriMapper->SetInput( ugrid );
4241 Mactor->DataSource = TriMapper->GetInput();
4242 Mactor->SetMapper(TriMapper);
4243 QApplication::restoreOverrideCursor();
4246 //=============================================================================
4250 //=============================================================================
4251 void SMESHGUI::AddQuadrangles( SMESH_Actor* Mactor, int number,
4252 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4254 QApplication::setOverrideCursor( Qt::waitCursor );
4255 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4256 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4259 while ( i <= number ) {
4260 vtkIdList *Ids = vtkIdList::New();
4261 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4262 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4263 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4264 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4265 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4266 Mactor->AddElement( indexes[j-1], id );
4270 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4271 QuadMapper->SetInput( ugrid );
4272 Mactor->DataSource = QuadMapper->GetInput();
4273 Mactor->SetMapper(QuadMapper);
4274 QApplication::restoreOverrideCursor();
4278 //=============================================================================
4282 //=============================================================================
4283 void SMESHGUI::AddQuadrangle(SMESH_Actor* Mactor, int idquad, int idnode1, int idnode2,
4284 int idnode3, int idnode4)
4286 QApplication::setOverrideCursor( Qt::waitCursor );
4287 vtkIdList *Ids = vtkIdList::New();
4288 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4289 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4290 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4291 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4293 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4294 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4295 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4296 Mactor->AddElement( idquad, id );
4298 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4299 QuadMapper->SetInput( ugrid );
4300 Mactor->DataSource = QuadMapper->GetInput();
4301 Mactor->SetMapper(QuadMapper);
4302 QApplication::restoreOverrideCursor();
4306 //=============================================================================
4310 //=============================================================================
4311 void SMESHGUI::AddTetras( SMESH_Actor* Mactor, int number,
4312 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4314 QApplication::setOverrideCursor( Qt::waitCursor );
4315 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4316 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4319 while ( i <= number ) {
4320 vtkIdList *Ids = vtkIdList::New();
4321 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4322 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4323 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4324 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4325 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4326 Mactor->AddElement( indexes[j-1], id );
4330 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4331 TetraMapper->SetInput( ugrid );
4332 Mactor->DataSource = TetraMapper->GetInput();
4333 Mactor->SetMapper(TetraMapper);
4334 QApplication::restoreOverrideCursor();
4338 //=============================================================================
4342 //=============================================================================
4343 void SMESHGUI::AddTetra(SMESH_Actor* Mactor, int idtetra, int idnode1, int idnode2,
4344 int idnode3, int idnode4)
4346 QApplication::setOverrideCursor( Qt::waitCursor );
4347 MESSAGE ( "SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" << idnode2
4348 << ";" << idnode3 << ";" << idnode4 )
4349 vtkIdList *Ids = vtkIdList::New();
4350 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4351 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4352 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4353 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4355 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4356 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4357 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4358 Mactor->AddElement( idtetra, id );
4360 MESSAGE ( " Tetra VTK id " << id )
4362 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4363 TetraMapper->SetInput( ugrid );
4364 Mactor->DataSource = TetraMapper->GetInput();
4365 Mactor->SetMapper(TetraMapper);
4366 QApplication::restoreOverrideCursor();
4370 //=============================================================================
4374 //=============================================================================
4375 void SMESHGUI::AddHexaedres( SMESH_Actor* Mactor, int number,
4376 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4378 QApplication::setOverrideCursor( Qt::waitCursor );
4379 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4380 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4383 while ( i <= number ) {
4384 vtkIdList *Ids = vtkIdList::New();
4385 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4386 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4387 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4388 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4389 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+4] ) );
4390 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+5] ) );
4391 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+6] ) );
4392 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+7] ) );
4393 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4394 Mactor->AddElement( indexes[j-1], id );
4398 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4399 HexaMapper->SetInput( ugrid );
4400 Mactor->DataSource = HexaMapper->GetInput();
4401 Mactor->SetMapper(HexaMapper);
4402 QApplication::restoreOverrideCursor();
4406 //=============================================================================
4410 //=============================================================================
4411 void SMESHGUI::AddHexaedre(SMESH_Actor* Mactor, int idhexa, int idnode1, int idnode2,
4412 int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
4414 QApplication::setOverrideCursor( Qt::waitCursor );
4415 MESSAGE ( "SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" << idnode2
4416 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" << idnode6
4417 << ";" << idnode7 << ";" << idnode8)
4419 vtkIdList *Ids = vtkIdList::New();
4420 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4421 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4422 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4423 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4424 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode5 ) );
4425 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode6 ) );
4426 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode7 ) );
4427 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode8 ) );
4429 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4430 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4431 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4432 Mactor->AddElement( idhexa, id );
4434 MESSAGE ( " Hexa VTK id " << id )
4436 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4437 HexaMapper->SetInput( ugrid );
4438 Mactor->DataSource = HexaMapper->GetInput();
4439 Mactor->SetMapper(HexaMapper);
4440 QApplication::restoreOverrideCursor();
4443 //=====================================================================================
4445 //=====================================================================================
4448 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
4450 return SMESHGUI::OnGUIEvent(theCommandID, parent);
4453 bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4455 return SMESHGUI::OnKeyPress (pe, parent, studyFrame);
4458 bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4460 return SMESHGUI::OnMousePress (pe, parent, studyFrame);
4463 bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4465 return SMESHGUI::OnMouseMove (pe, parent, studyFrame);
4468 bool SetSettings ( QAD_Desktop* parent )
4470 return SMESHGUI::SetSettings( parent );
4473 bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
4474 const QString & theParent, const QString & theObject )
4476 return SMESHGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
4479 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
4481 SMESHGUI::DefinePopup( theContext, theParent, theObject );
4484 bool activeStudyChanged ( QAD_Desktop* parent )
4486 SMESHGUI::activeStudyChanged( parent );
4489 void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
4491 SMESHGUI::BuildPresentation(theIO);
4494 void supportedViewType(int* buffer, int bufferSize)
4496 if (!buffer || !bufferSize) return;
4497 buffer[0] = (int)VIEW_VTK;
4503 //=============================================================================
4507 //=============================================================================
4508 void SMESHGUI::ViewNodes()
4510 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4513 EraseSimulationActors();
4514 mySimulationActors = vtkActorCollection::New();
4515 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4516 vtkActorCollection* theActors = theRenderer->GetActors();
4517 theActors->InitTraversal();
4518 vtkActor *ac = theActors->GetNextActor();
4519 while(!(ac==NULL)) {
4520 if ( ac->IsA("SMESH_Actor") ) {
4521 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
4522 if ( anActor->GetVisibility() == 1 ) {
4523 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4524 gf->SetInput( anActor->DataSource );
4525 vtkMaskPoints *verts = vtkMaskPoints::New();
4526 verts->SetInput(gf->GetOutput());
4527 verts->GenerateVerticesOn();
4528 verts->SetOnRatio(1);
4530 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4531 vertMapper->SetInput(verts->GetOutput());
4532 vertMapper->ScalarVisibilityOff();
4534 vtkActor *vertActor = vtkActor::New();
4535 vertActor->SetMapper(vertMapper);
4538 anActor->GetNodeColor(r, g, b ) ;
4539 vertActor->GetProperty()->SetColor( r, g, b ) ;
4541 vertActor->GetProperty()->SetPointSize( anActor->GetNodeSize() );
4543 vertActor->PickableOff();
4545 mySimulationActors->AddItem( vertActor );
4546 theRenderer->AddActor( vertActor );
4549 ac = theActors->GetNextActor();
4552 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4557 //=============================================================================
4561 //=============================================================================
4562 void SMESHGUI::Control(int theCommandID)
4564 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4567 QApplication::setOverrideCursor( Qt::waitCursor );
4568 DisplayScalarBar( false );
4570 vtkDoubleArray *scalars = vtkDoubleArray::New();
4571 scalars->SetNumberOfComponents(1);
4573 vtkDataSetMapper* meshMapper = 0;
4574 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4575 int nbSel = Sel->IObjectCount();
4576 Standard_Boolean result;
4577 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
4578 SMESH_Actor* MeshActor = FindActorByEntry(IObject->getEntry(), result, true);
4580 // Mesh may be not updated after Compute
4581 if (!MeshActor->DataSource || !MeshActor->GetMapper()) {
4582 QApplication::restoreOverrideCursor();
4586 vtkDataSet* aDataSet = MeshActor->DataSource;
4587 typedef double (*TScalarFun)(vtkCell* theCell);
4588 TScalarFun aScalarFun;
4591 switch (theCommandID){
4593 type = tr( "SMESH_CONTROL_LENGTH_EDGES");
4594 aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
4595 aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
4596 MESSAGE ( " init minimum length " << aDataSet->GetNumberOfCells() );
4597 if(MeshActor->getDisplayMode() != 0)
4598 ChangeRepresentation( MeshActor, 1);// limitation; in Wireframe, colored edges are not visible
4602 type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
4603 aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
4604 if(MeshActor->getDisplayMode() != 1)
4605 ChangeRepresentation( MeshActor, 1 );
4609 type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
4610 aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
4614 type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
4615 aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
4616 if(MeshActor->getDisplayMode() != 1)
4617 ChangeRepresentation( MeshActor, 1 );
4621 type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
4622 aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
4623 if(MeshActor->getDisplayMode() != 1)
4624 ChangeRepresentation( MeshActor, 1 );
4628 type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
4629 aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
4633 type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
4634 aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
4638 for(int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
4639 scalars->InsertTuple1(i,aScalarFun(aDataSet->GetCell(i)));
4642 scalars->GetRange(range);
4644 vtkLookupTable* wat = vtkLookupTable::New();
4645 wat->SetRange( range );
4648 scalars->SetLookupTable(wat);
4650 if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
4651 meshMapper->SetScalarModeToUseCellData();
4652 MeshActor->DataSource->GetCellData()->SetScalars(scalars);
4653 meshMapper->SetScalarRange( range );
4654 meshMapper->ScalarVisibilityOn();
4656 vtkScalarBarActor* aScalarBar = GetScalarBar();
4657 if ( aScalarBar == NULL ) {
4658 aScalarBar = vtkScalarBarActor::New();
4659 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
4660 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
4661 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
4662 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
4663 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
4664 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
4665 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
4666 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
4667 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
4669 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily, Orientation,
4670 Width, Height, NumberOfColors, NumberOfLabels);
4671 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4672 theRenderer->AddActor2D(aScalarBar);
4674 aScalarBar->SetLookupTable( wat );
4675 aScalarBar->SetTitle( type.latin1() );
4679 DisplayScalarBar( true );
4681 QApplication::restoreOverrideCursor();
4685 //=============================================================================
4689 //=============================================================================
4690 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
4691 QString Bold, QString Italic,
4692 QString Shadow, QString FontFamily,
4693 QString Orientation, float Width, float Height,
4694 int NbColors, int NbLabels )
4696 if ( Bold.isNull() || Bold.isEmpty() || (Bold.compare( "true" ) == 0) )
4697 theScalarBar->BoldOn();
4699 theScalarBar->BoldOff();
4701 if ( Italic.isNull() || Italic.isEmpty() || (Italic.compare( "true" ) == 0) )
4702 theScalarBar->ItalicOn();
4704 theScalarBar->ItalicOff();
4706 if ( Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare( "true" ) == 0) )
4707 theScalarBar->ShadowOn();
4709 theScalarBar->ShadowOff();
4711 if ( FontFamily.compare( "Arial" ) == 0 )
4712 theScalarBar->SetFontFamilyToArial();
4713 else if ( FontFamily.compare( "Courier" ) == 0 )
4714 theScalarBar->SetFontFamilyToCourier();
4715 else if ( FontFamily.compare( "Times" ) == 0 )
4716 theScalarBar->SetFontFamilyToTimes();
4718 theScalarBar->SetFontFamilyToArial();
4720 if ( Orientation.isNull() || Orientation.isEmpty() || (Orientation.compare( "Vertical" ) == 0) )
4721 theScalarBar->SetOrientationToVertical();
4723 theScalarBar->SetOrientationToHorizontal();
4726 theScalarBar->SetWidth((Width == 0)? 0.17 : Width);
4727 theScalarBar->SetHeight((Height == 0)? 0.8 : Height);
4729 theScalarBar->SetNumberOfLabels((NbLabels == 0)? 5 : NbLabels);
4730 theScalarBar->SetMaximumNumberOfColors((NbColors == 0)? 64 : NbColors);
4734 //=============================================================================
4738 //=============================================================================
4739 void SMESHGUI::DisplayScalarBar(bool visibility)
4741 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4744 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4745 vtkScalarBarActor* aScalarBar = GetScalarBar();
4747 if ( aScalarBar == NULL ) {
4748 MESSAGE("myScalarBar is NULL");
4753 aScalarBar->VisibilityOn();
4755 aScalarBar->VisibilityOff();
4756 //Turn off mesh coloring (influences on all views)
4757 vtkActorCollection* actorList=theRenderer->GetActors();
4758 actorList->InitTraversal();
4759 vtkActor *ac = actorList->GetNextActor();
4761 if (ac->GetMapper() != NULL) {
4762 ac->GetMapper()->ScalarVisibilityOff();
4764 ac = actorList->GetNextActor();
4766 // Turn off ScalarBar in all views
4767 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
4768 for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
4769 if (aFrame->getTypeView() == VIEW_VTK) {
4770 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
4771 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
4772 actor2DList->InitTraversal();
4773 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
4774 while (aActor2d != NULL) {
4775 if (aActor2d->IsA("vtkScalarBarActor")) {
4776 aActor2d->VisibilityOff();
4779 actor2DList->GetNextActor2D();
4784 myActiveStudy->update3dViewers();
4788 //=============================================================================
4792 //=============================================================================
4793 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
4795 vtkScalarBarActor* aScalarBar = GetScalarBar();
4796 if ( aScalarBar == NULL ) {
4797 MESSAGE("myScalarBar is NULL");
4800 DisplayScalarBar(false);
4802 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
4803 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4804 vtkActorCollection* aActorList = aRenderer->GetActors();
4805 aActorList->InitTraversal();
4806 vtkActor *aActor = aActorList->GetNextActor();
4807 while(aActor != NULL) {
4808 if (aActor->IsA("SMESH_Actor")) {
4809 SMESH_Actor* aMeshActor = SMESH_Actor::SafeDownCast(aActor);
4810 vtkDataSetMapper* aMeshMapper = (vtkDataSetMapper*) (aMeshActor->getMapper());
4811 if ((aMeshMapper != NULL)) {
4812 aMeshMapper->SetScalarRange( MinRange, MaxRange );
4813 aMeshMapper->ScalarVisibilityOn();
4816 aActor = aActorList->GetNextActor();
4818 DisplayScalarBar(true);
4822 //=============================================================================
4826 //=============================================================================
4827 void SMESHGUI::SetDisplaySettings()
4829 EmitSignalDeactivateDialog() ;
4830 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "") ;
4832 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
4833 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
4834 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
4835 QColor color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4836 aDlg->SetColor(1,color);
4838 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
4839 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
4840 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4841 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4842 aDlg->SetColor(2,color);
4844 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4845 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4846 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4847 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4848 aDlg->SetColor(3,color);
4850 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4851 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4852 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4853 color = QColor (SBr.toInt(), SBg.toInt(), SBb.toInt());
4854 aDlg->SetColor(4,color);
4856 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4857 aDlg->SetIntValue(1,intValue.toInt());
4858 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4859 aDlg->SetIntValue(2,intValue.toInt());
4860 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4861 aDlg->SetIntValue(3,intValue.toInt());
4863 if ( aDlg->exec() ) {
4864 QColor colorFill = aDlg->GetColor( 1 );
4865 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4866 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4867 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4869 QColor colorOutline = aDlg->GetColor( 2 );
4870 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4871 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4872 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4874 QColor colorNode = aDlg->GetColor( 3 );
4875 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4876 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4877 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4879 QColor colorBackFace = aDlg->GetColor( 4 );
4880 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4881 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4882 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4884 int width = aDlg->GetIntValue( 1 );
4885 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4887 int nodes_size = aDlg->GetIntValue( 2 );
4888 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4890 int shrink_coeff = aDlg->GetIntValue( 3 );
4891 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4897 //=======================================================================
4898 // function : Parameter()
4899 // purpose : return a parameter (double) from a dialog box
4901 // aValue : is a double used as a default value displayed
4902 // aLabel : is the title for aValue1
4903 // aTitle : is the main title
4904 // bottom : maximum value to be entered
4905 // top : minimum value to be entered
4906 // decimals : number of decimals
4907 //=======================================================================
4908 double SMESHGUI::Parameter( Standard_Boolean& res,
4909 const double aValue,
4912 const double bottom,
4914 const int decimals )
4916 SMESHGUI_aParameterDlg* Dialog =
4917 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4920 bottom, top, decimals,
4922 Dialog->setValue( aValue );
4924 res = ( Dialog->exec() == QDialog::Accepted );
4926 X = Dialog->getDblValue();
4930 //=======================================================================
4931 // function : Parameter()
4932 // purpose : return a parameter (int) from a dialog box
4934 // aValue : is a int used as a default value displayed
4935 // aLabel : is the title for aValue1
4936 // aTitle : is the main title
4937 // bottom : maximum value to be entered
4938 // top : minimum value to be entered
4939 //=======================================================================
4940 int SMESHGUI::Parameter( Standard_Boolean& res,
4947 SMESHGUI_aParameterDlg* Dialog =
4948 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4953 Dialog->setValue( aValue );
4955 res = ( Dialog->exec() == QDialog::Accepted );
4957 X = Dialog->getIntValue();
4961 //=============================================================================
4965 //=============================================================================
4966 void SMESHGUI::DisplayEdges(SMESH_Actor* ac, bool visibility)
4968 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4970 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
4973 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4974 gf->SetInput(ac->DataSource);
4975 vtkFeatureEdges *edges = vtkFeatureEdges::New();
4976 edges->SetInput(gf->GetOutput());
4977 edges->BoundaryEdgesOn();
4978 edges->ManifoldEdgesOn();
4980 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
4981 edgeMapper->SetInput(edges->GetOutput());
4982 edgeMapper->ScalarVisibilityOff();
4984 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4985 vtkActorCollection* actorList=theRenderer->GetActors();
4987 int test=actorList->IsItemPresent(ac->EdgeDevice);
4989 vtkProperty* prop = vtkProperty::New();
4990 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
4991 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
4992 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
4993 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
4994 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
4995 ac->EdgeDevice->SetProperty(prop);
4996 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
4997 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
4998 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
4999 ac->EdgeDevice->SetMapper(edgeMapper);
5001 theRenderer->AddActor(ac->EdgeDevice);
5003 ac->EdgeDevice->SetMapper(edgeMapper);
5004 edgeMapper->Update();
5007 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5008 shrink->SetInput(ac->DataSource);
5009 shrink->SetShrinkFactor(ac->GetShrinkFactor());
5010 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5011 Shrinkgf->SetInput( shrink->GetOutput() );
5012 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5013 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5014 ShrinkEdges->BoundaryEdgesOn();
5015 ShrinkEdges->ManifoldEdgesOn();
5017 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5018 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5019 ShrinkEdgeMapper->ScalarVisibilityOff();
5021 test=actorList->IsItemPresent(ac->EdgeShrinkDevice);
5023 vtkProperty* prop = vtkProperty::New();
5024 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5025 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5026 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5027 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5028 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5029 ac->EdgeShrinkDevice->SetProperty(prop);
5030 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5031 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5032 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5033 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5035 theRenderer->AddActor(ac->EdgeShrinkDevice);
5037 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5038 ShrinkEdgeMapper->Update();
5041 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5046 //=============================================================================
5050 //=============================================================================
5051 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5053 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh( aMesh );
5054 SALOMEDS::GenericAttribute_var anAttr;
5055 SALOMEDS::AttributeName_var aName;
5056 if ( !aSO_M->_is_nil() ) {
5057 if (aSO_M->FindAttribute(anAttr, "AttributeName") ) {
5058 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5059 Standard_Boolean result;
5060 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5062 SMESH_Actor* amesh = SMESH_Actor::New();
5063 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(aSO_M->GetID(),
5067 amesh->setName( aName->Value() );
5068 DisplayActor(amesh, false);
5075 //=============================================================================
5079 //=============================================================================
5080 void SMESHGUI::Update()
5082 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
5083 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5085 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5086 int nbSel = Sel->IObjectCount();
5088 vtkActorCollection* actorList=theRenderer->GetActors();
5089 actorList->InitTraversal();
5090 vtkActor *ac = actorList->GetNextActor();
5091 while(!(ac==NULL)) {
5092 if ( ac->IsA("SMESH_Actor") ) {
5093 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5094 if ( anActor->hasIO() ) {
5095 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5099 ac = actorList->GetNextActor();
5102 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5103 for ( ; It.More(); It.Next() ) {
5104 Handle(SALOME_InteractiveObject) IO = It.Value();
5108 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5111 QApplication::restoreOverrideCursor();
5115 //=============================================================================
5119 //=============================================================================
5120 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject)& IO)
5122 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5125 if ( IO->hasEntry() ) {
5126 Standard_Boolean res;
5127 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh( IO, res );
5129 SMESH_Actor* ac = FindActorByEntry( IO->getEntry(), res, false );
5131 // Check whether the actor belongs to the active view
5132 VTKViewer_RenderWindowInteractor* rwInter =
5133 ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5135 // The actor belongs to inactive view -> create a copy and display it in the active view
5136 if (!rwInter->isInViewer(IO)) {
5137 SMESH_Actor* acCopy = SMESH_Actor::New();
5138 acCopy->ShallowCopy(ac);
5140 smeshGUI->DisplayActor( acCopy, false );
5142 ac = ReadScript( aMesh );
5149 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
5157 //=============================================================================
5161 //=============================================================================
5162 vtkActor* SMESHGUI::SimulationMoveNode(SMESH_Actor* Mactor, int idnode)
5164 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5167 mySimulationActors = vtkActorCollection::New();
5168 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5170 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5171 vtkIdList *IdCells = vtkIdList::New();
5172 ugrid->GetPointCells( idnode, IdCells );
5174 vtkPoints *Pts = vtkPoints::New();
5175 Pts = ugrid->GetPoints();
5177 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
5178 ugridSimulation->SetPoints( Pts );
5179 vtkIdList *IdPts = vtkIdList::New();
5180 for (int j=0; j<IdCells->GetNumberOfIds(); j++) {
5181 ugrid->GetCellPoints( IdCells->GetId(j), IdPts );
5182 ugridSimulation->InsertNextCell( ugrid->GetCellType( IdCells->GetId(j) ), IdPts );
5185 vtkProperty* prop = vtkProperty::New();
5186 prop->SetColor( 1., 0., 0. );
5187 prop->SetRepresentationToWireframe();
5189 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
5190 if ( Edgewidth == 0 )
5192 prop->SetLineWidth( Edgewidth+1 );
5194 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5195 Mapper->SetInput( ugridSimulation );
5196 vtkActor* ac = vtkActor::New();
5197 ac->SetMapper( Mapper );
5198 ac->SetProperty( prop );
5200 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
5201 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
5203 mySimulationActors->AddItem( ac );
5204 theRenderer->AddActor( ac );
5206 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5213 //=============================================================================
5217 //=============================================================================
5218 void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5220 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5223 EraseSimulationActors();
5224 mySimulationActors = vtkActorCollection::New();
5225 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5226 Standard_Boolean result;
5227 SMESH_Actor* ac = FindActor( aMesh, result, true );
5230 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5231 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5233 vtkPoints *Pts = ugrid->GetPoints();
5234 vtkPoints *newPts = vtkPoints::New();
5235 int nbPts = Pts->GetNumberOfPoints();
5236 for ( int i = 0; i < nbPts; i++ ) {
5237 newPts->InsertPoint(i, Pts->GetPoint(i) );
5240 newugrid->SetPoints(newPts);
5241 newugrid->GetPoints()->InsertNextPoint( x, y, z );
5243 vtkMaskPoints* verts = vtkMaskPoints::New();
5244 verts->SetInput(newugrid);
5245 verts->SetGenerateVertices(1);
5246 verts->SetOnRatio(1);
5248 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
5249 vertMapper->SetInput( verts->GetOutput() );
5250 vertMapper->ScalarVisibilityOff();
5252 vtkActor* node = vtkActor::New();
5253 node->SetMapper( vertMapper );
5255 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5256 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5257 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5258 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5259 if ( !nodecolor.isValid() )
5260 // nodecolor = QColor(0.,1.,0.);
5261 nodecolor = QColor(0,1,0);
5263 node->GetProperty()->SetColor( float(nodecolor.red())/255.,
5264 float(nodecolor.green())/255.,
5265 float(nodecolor.blue())/255.);
5267 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
5271 node->GetProperty()->SetPointSize( intValue );
5273 node->VisibilityOn();
5275 mySimulationActors->AddItem( node );
5276 theRenderer->AddActor(node);
5279 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5283 //=============================================================================
5287 //=============================================================================
5288 void SMESHGUI::DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z)
5290 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5293 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5294 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
5295 pt[0] = x; pt[1] = y; pt[2] = z;
5297 ac->GetMapper()->ImmediateModeRenderingOn();
5298 ac->GetProperty()->SetRepresentationToWireframe();
5300 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5306 //=============================================================================
5310 //=============================================================================
5311 void SMESHGUI::MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z)
5313 Standard_Boolean result;
5315 SMESH_Actor* MeshActor = FindActor(aMesh, result, true);
5321 //=============================================================================
5325 //=============================================================================
5326 void SMESHGUI::ScalarVisibilityOff()
5328 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5331 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5332 vtkActorCollection* actorList=theRenderer->GetActors();
5334 actorList->InitTraversal();
5335 vtkActor *ac = actorList->GetNextActor();
5336 while(!(ac==NULL)) {
5337 if ( ac->IsA("SMESH_Actor") ) {
5338 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5339 if ( anActor->GetVisibility() == 1 ) {
5340 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (anActor->getMapper());
5341 meshMapper->ScalarVisibilityOff();
5342 meshMapper->SetInput( anActor->DataSource );
5343 ChangeRepresentation( anActor, anActor->getDisplayMode() );
5346 ac = actorList->GetNextActor();
5349 theRenderer->Render();
5353 //=============================================================================
5357 //=============================================================================
5358 void SMESHGUI::DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5360 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5363 EraseSimulationActors();
5364 mySimulationActors = vtkActorCollection::New();
5365 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5366 Standard_Boolean result;
5367 SMESH_Actor* ac = FindActor( aMesh, result, true );
5369 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5373 vtkIdList *Ids = vtkIdList::New();
5374 for ( ; ite.More(); ite.Next() ) {
5375 idNodes[i] = ite.Key();
5379 Ids->InsertId( 0, idNodes[0] );
5380 pts[0] = idNodes[0];
5381 Ids->InsertId( 1, idNodes[1] );
5382 pts[1] = idNodes[1];
5384 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5385 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5386 newugrid->SetPoints( ugrid->GetPoints() ) ;
5387 newugrid->InsertNextCell(VTK_LINE, 2, pts);
5389 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5390 Mapper->SetInput( newugrid );
5393 vtkActor* edge = vtkActor::New();
5394 edge->SetMapper( Mapper );
5395 edge->SetProperty( ac->GetProperty() );
5396 edge->SetBackfaceProperty( ac->GetBackfaceProperty() );
5397 edge->VisibilityOn();
5398 mySimulationActors->AddItem( edge );
5399 theRenderer->AddActor(edge);
5402 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5407 //=============================================================================
5411 //=============================================================================
5412 void SMESHGUI::DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5414 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5417 EraseSimulationActors();
5418 mySimulationActors = vtkActorCollection::New();
5419 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5420 Standard_Boolean result;
5421 SMESH_Actor* ac = FindActor( aMesh, result, true );
5423 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5427 vtkIdList *Ids = vtkIdList::New();
5428 for ( ; ite.More(); ite.Next() ) {
5429 idNodes[i] = ite.Key();
5434 Ids->InsertId( 0, idNodes[2] );
5435 pts[0] = idNodes[2];
5436 Ids->InsertId( 1, idNodes[1] );
5437 pts[1] = idNodes[1];
5438 Ids->InsertId( 2, idNodes[0] );
5439 pts[2] = idNodes[0];
5441 Ids->InsertId( 0, idNodes[0] );
5442 pts[0] = idNodes[0];
5443 Ids->InsertId( 1, idNodes[1] );
5444 pts[1] = idNodes[1];
5445 Ids->InsertId( 2, idNodes[2] );
5446 pts[2] = idNodes[2];
5448 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5449 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5450 newugrid->SetPoints( ugrid->GetPoints() ) ;
5451 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
5453 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5454 Mapper->SetInput( newugrid );
5457 vtkActor* tri = vtkActor::New();
5458 tri->SetMapper( Mapper );
5459 tri->SetProperty( ac->GetProperty() );
5460 tri->SetBackfaceProperty( ac->GetBackfaceProperty() );
5461 tri->VisibilityOn();
5462 mySimulationActors->AddItem( tri );
5463 theRenderer->AddActor(tri);
5466 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5471 //=============================================================================
5475 //=============================================================================
5476 void SMESHGUI::DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5478 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5481 EraseSimulationActors();
5482 mySimulationActors = vtkActorCollection::New();
5483 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5484 Standard_Boolean result;
5485 SMESH_Actor* ac = FindActor( aMesh, result, true );
5487 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5490 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5493 vtkIdList *Ids = vtkIdList::New();
5494 for ( ; ite.More(); ite.Next() ) {
5495 idNodes[i] = ite.Key();
5499 float *p0 = ugrid->GetPoint(idNodes[0]);
5500 float *p1 = ugrid->GetPoint(idNodes[1]);
5501 float *p2 = ugrid->GetPoint(idNodes[2]);
5502 float *p3 = ugrid->GetPoint(idNodes[3]);
5504 gp_Pnt P0(p0[0],p0[1],p0[2]);
5506 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5507 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5508 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5510 gp_Vec Cross1 = V1 ^ V2;
5511 gp_Vec Cross2 = V2 ^ V3;
5514 if ( Cross1.Dot(Cross2) < 0 ) {
5515 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5516 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5520 if ( Cross1.Dot(Cross2) < 0 ) {
5522 idNodes[2] = idNodes[3];
5526 idNodes[1] = idNodes[2];
5532 Ids->InsertId( 0, idNodes[3] );
5533 Ids->InsertId( 1, idNodes[2] );
5534 Ids->InsertId( 2, idNodes[1] );
5535 Ids->InsertId( 3, idNodes[0] );
5537 Ids->InsertId( 0, idNodes[0] );
5538 Ids->InsertId( 1, idNodes[1] );
5539 Ids->InsertId( 2, idNodes[2] );
5540 Ids->InsertId( 3, idNodes[3] );
5543 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5544 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5545 newugrid->SetPoints( ugrid->GetPoints() ) ;
5546 newugrid->InsertNextCell(VTK_QUAD, Ids);
5548 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5549 Mapper->SetInput( newugrid );
5552 vtkActor* quad = vtkActor::New();
5553 quad->SetMapper( Mapper );
5554 quad->SetProperty( ac->GetProperty() );
5555 quad->SetBackfaceProperty( ac->GetBackfaceProperty() );
5556 quad->VisibilityOn();
5557 mySimulationActors->AddItem( quad );
5558 theRenderer->AddActor(quad);
5560 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5565 //=============================================================================
5569 //=============================================================================
5570 void SMESHGUI::DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5572 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5575 EraseSimulationActors();
5576 mySimulationActors = vtkActorCollection::New();
5577 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5578 Standard_Boolean result;
5579 SMESH_Actor* ac = FindActor( aMesh, result, true );
5581 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5584 vtkIdList *Ids = vtkIdList::New();
5585 for ( ; ite.More(); ite.Next() ) {
5586 idNodes[i] = ite.Key();
5590 Ids->InsertId( 0, idNodes[0] );
5591 Ids->InsertId( 1, idNodes[1] );
5592 Ids->InsertId( 2, idNodes[2] );
5593 Ids->InsertId( 3, idNodes[3] );
5595 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5596 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5597 newugrid->SetPoints( ugrid->GetPoints() ) ;
5598 newugrid->InsertNextCell(VTK_TETRA, Ids);
5600 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5601 Mapper->SetInput( newugrid );
5604 vtkActor* tetra = vtkActor::New();
5605 tetra->SetMapper( Mapper );
5606 tetra->SetProperty( ac->GetProperty() );
5607 tetra->SetBackfaceProperty( ac->GetBackfaceProperty() );
5608 tetra->VisibilityOn();
5609 mySimulationActors->AddItem( tetra );
5610 theRenderer->AddActor(tetra);
5612 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5617 //=============================================================================
5621 //=============================================================================
5622 void SMESHGUI::DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5624 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5627 EraseSimulationActors();
5628 mySimulationActors = vtkActorCollection::New();
5629 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5630 Standard_Boolean result;
5631 SMESH_Actor* ac = FindActor( aMesh, result, true );
5633 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5636 vtkIdList *Ids = vtkIdList::New();
5637 for ( ; ite.More(); ite.Next() ) {
5638 idNodes[i] = ite.Key();
5642 Ids->InsertId( 0, idNodes[0] );
5643 Ids->InsertId( 1, idNodes[1] );
5644 Ids->InsertId( 2, idNodes[2] );
5645 Ids->InsertId( 3, idNodes[3] );
5646 Ids->InsertId( 4, idNodes[4] );
5647 Ids->InsertId( 5, idNodes[5] );
5648 Ids->InsertId( 6, idNodes[6] );
5649 Ids->InsertId( 7, idNodes[7] );
5651 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5652 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5653 newugrid->SetPoints( ugrid->GetPoints() ) ;
5654 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5656 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5657 Mapper->SetInput( newugrid );
5660 vtkActor* hexa = vtkActor::New();
5661 hexa->SetMapper( Mapper );
5662 hexa->SetProperty( ac->GetProperty() );
5663 hexa->SetBackfaceProperty( ac->GetBackfaceProperty() );
5664 hexa->VisibilityOn();
5665 mySimulationActors->AddItem( hexa );
5666 theRenderer->AddActor(hexa);
5668 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5673 //=============================================================================
5677 //=============================================================================
5678 void SMESHGUI::AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5680 QApplication::setOverrideCursor( Qt::waitCursor );
5681 Standard_Boolean result;
5682 SMESH_Actor* ac = FindActor( aMesh, result, true );
5684 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5685 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5686 anArrayOfIdeces->length(MapIndex.Extent());
5689 for ( ; ite.More(); ite.Next() ) {
5690 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5695 if ( MapIndex.Extent() == 4 ) {
5698 TColStd_MapIteratorOfMapOfInteger ite1( MapIndex );
5699 for ( ; ite1.More(); ite1.Next() ) {
5700 idNodes[i] = ite1.Key();
5704 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5705 float *p0 = ugrid->GetPoint(idNodes[0]);
5706 float *p1 = ugrid->GetPoint(idNodes[1]);
5707 float *p2 = ugrid->GetPoint(idNodes[2]);
5708 float *p3 = ugrid->GetPoint(idNodes[3]);
5710 gp_Pnt P0(p0[0],p0[1],p0[2]);
5712 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5713 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5714 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5716 gp_Vec Cross1 = V1 ^ V2;
5717 gp_Vec Cross2 = V2 ^ V3;
5719 if ( Cross1.Dot(Cross2) < 0 ) {
5721 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5722 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5726 if ( Cross1.Dot(Cross2) < 0 ) {
5727 tmp = anArrayOfIdeces[2];
5728 anArrayOfIdeces[2] = anArrayOfIdeces[3];
5729 anArrayOfIdeces[3] = tmp;
5731 tmp = anArrayOfIdeces[1];
5732 anArrayOfIdeces[1] = anArrayOfIdeces[2];
5733 anArrayOfIdeces[2] = tmp;
5740 for (i=0; i < (MapIndex.Extent()/2); i++) {
5741 tmp = anArrayOfIdeces[i];
5742 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent()-i-1];
5743 anArrayOfIdeces[MapIndex.Extent()-i-1] = tmp;
5746 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5747 aMeshEditor->AddFace(anArrayOfIdeces);
5749 if ( myAutomaticUpdate ) {
5750 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5751 if ( Mesh != NULL ) {
5752 smeshGUI->DisplayActor( Mesh );
5753 smeshGUI->DisplayEdges( Mesh );
5754 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5755 AddActorInSelection( Mesh );
5758 QApplication::restoreOverrideCursor();
5762 //=============================================================================
5766 //=============================================================================
5767 void SMESHGUI::AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5769 QApplication::setOverrideCursor( Qt::waitCursor );
5770 Standard_Boolean result;
5771 SMESH_Actor* ac = FindActor( aMesh, result, true );
5773 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5774 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5775 anArrayOfIdeces->length(MapIndex.Extent());
5778 for ( ; ite.More(); ite.Next() ) {
5779 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5783 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5784 aMeshEditor->AddVolume(anArrayOfIdeces);
5786 if ( myAutomaticUpdate ) {
5787 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5788 if ( Mesh != NULL ) {
5789 smeshGUI->DisplayActor( Mesh );
5790 smeshGUI->DisplayEdges( Mesh );
5791 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5792 AddActorInSelection( Mesh );
5795 QApplication::restoreOverrideCursor();
5799 //=============================================================================
5803 //=============================================================================
5804 void SMESHGUI::AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5806 QApplication::setOverrideCursor( Qt::waitCursor );
5807 Standard_Boolean result;
5808 SMESH_Actor* ac = FindActor( aMesh, result, true );
5810 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5811 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5812 anArrayOfIdeces->length(MapIndex.Extent());
5815 for ( ; ite.More(); ite.Next() ) {
5816 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5820 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5821 aMeshEditor->AddEdge(anArrayOfIdeces);
5823 if ( myAutomaticUpdate ) {
5824 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5825 if ( Mesh != NULL ) {
5826 smeshGUI->DisplayActor( Mesh );
5827 smeshGUI->DisplayEdges( Mesh );
5828 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5829 AddActorInSelection( Mesh );
5832 QApplication::restoreOverrideCursor();
5835 //=============================================================================
5839 //=============================================================================
5840 void SMESHGUI::AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5842 QApplication::setOverrideCursor( Qt::waitCursor );
5843 Standard_Boolean result;
5844 SMESH_Actor* ac = FindActor( aMesh, result, true );
5846 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5847 aMeshEditor->AddNode(x,y,z);
5849 if ( myAutomaticUpdate ) {
5850 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5851 if ( Mesh != NULL ) {
5852 smeshGUI->DisplayActor( Mesh );
5853 smeshGUI->DisplayEdges( Mesh );
5854 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5855 AddActorInSelection( Mesh );
5859 QApplication::restoreOverrideCursor();
5862 //=============================================================================
5866 //=============================================================================
5867 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor *ac)
5869 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5872 EraseSimulationActors();
5873 mySimulationActors2D = vtkActor2DCollection::New();
5875 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5877 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
5878 gs2->SetGlyphTypeToTriangle();
5881 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
5882 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
5883 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
5885 legend->SetNumberOfEntries(4);
5886 legend->SetEntryString( 0, tr( "SMESH_BOUNDARYEDGES" ) );
5887 legend->SetEntrySymbol( 0, gs2->GetOutput() );
5888 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.) );
5889 legend->SetEntryString( 1, tr( "SMESH_MANIFOLDEDGES" ) );
5890 legend->SetEntrySymbol( 1, gs2->GetOutput() );
5891 legend->SetEntryColor(1, ac->GetMapper()->GetLookupTable()->GetColor(0.666667) );
5892 legend->SetEntryString( 2, tr( "SMESH_NONMANIFOLDEDGES" ) );
5893 legend->SetEntrySymbol( 2, gs2->GetOutput() );
5894 legend->SetEntryColor(2, ac->GetMapper()->GetLookupTable()->GetColor(0.222222) );
5895 legend->SetEntryString( 3, tr( "SMESH_FEATUREEDGES" ) );
5896 legend->SetEntrySymbol( 3, gs2->GetOutput() );
5897 legend->SetEntryColor(3, ac->GetMapper()->GetLookupTable()->GetColor(0.444444) );
5898 legend->SetPadding( 5 );
5899 // legend->GetProperty()->SetColor();
5901 mySimulationActors2D->AddItem( legend );
5902 theRenderer->AddActor2D( legend );
5905 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5908 //===============================================================================
5909 // function : OnEditDelete()
5911 //===============================================================================
5912 void SMESHGUI::OnEditDelete()
5914 if ( QAD_MessageBox::warn2
5915 ( QAD_Application::getDesktop(),
5916 tr ("SMESH_WRN_WARNING"),
5917 tr ("SMESH_REALLY_DELETE"),
5918 tr ("SMESH_BUT_YES"), tr ("SMESH_BUT_NO"), 1, 0, 0 ) != 1 )
5921 int nbSf = myActiveStudy->getStudyFramesCount();
5923 Standard_Boolean found;
5924 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5925 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
5926 SALOMEDS::GenericAttribute_var anAttr;
5927 SALOMEDS::AttributeIOR_var anIOR;
5929 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5930 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5931 for(;It.More();It.Next()) {
5932 Handle(SALOME_InteractiveObject) IObject = It.Value();
5933 if ( IObject->hasEntry() ) {
5934 SALOMEDS::SObject_var SO = myStudy->FindObjectID( IObject->getEntry() );
5936 /* Erase child graphical objects */
5937 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5938 for (; it->More();it->Next()) {
5939 SALOMEDS::SObject_var CSO= it->Value();
5940 if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
5941 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5943 for ( int i = 0; i < nbSf; i++ ) {
5944 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5945 if ( sf->getTypeView() == VIEW_VTK ) {
5946 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5947 SMESH_Actor* ac = smeshGUI->FindActorByEntry( CSO->GetID(), found, false );
5949 Renderer->RemoveActor(ac->EdgeDevice);
5950 Renderer->RemoveActor(ac->EdgeShrinkDevice);
5951 Renderer->RemoveActor(ac);
5958 /* Erase main graphical object */
5959 for ( int i = 0; i < nbSf; i++ ) {
5960 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5961 if ( sf->getTypeView() == VIEW_VTK ) {
5962 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5963 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
5964 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), found, false );
5966 Renderer->RemoveActor(ac->EdgeDevice);
5967 Renderer->RemoveActor(ac->EdgeShrinkDevice);
5969 myRenderInter->Remove( IObject );
5973 /* Erase objects in Study */
5974 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
5975 if ( !obj->_is_nil() ) {
5976 QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5978 aStudyBuilder->RemoveObject(obj);
5982 } /* IObject->hasEntry() */
5985 /* Clear any previous selection */
5986 Sel->ClearIObjects() ;
5987 myActiveStudy->updateObjBrowser();