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 );
852 if ( !Hyp->_is_nil() ) {
853 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
854 myStudyAPI.SetName( SHyp, NameAlgo);
857 catch (const SALOME::SALOME_Exception& S_ex) {
858 QtCatchCorbaException(S_ex);
860 myActiveStudy->updateObjBrowser(true);
864 //=============================================================================
868 //=============================================================================
869 void SMESHGUI::CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length )
871 QApplication::setOverrideCursor( Qt::waitCursor );
873 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
874 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
875 if ( !LL->_is_nil() )
876 LL->SetLength( Length );
878 catch (const SALOME::SALOME_Exception& S_ex) {
879 QtCatchCorbaException(S_ex);
881 myActiveStudy->updateObjBrowser(true);
882 QApplication::restoreOverrideCursor();
885 //=============================================================================
889 //=============================================================================
890 void SMESHGUI::CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea )
892 QApplication::setOverrideCursor( Qt::waitCursor );
894 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
895 SMESH::SMESH_MaxElementArea_var MaxElArea = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
896 if ( !MaxElArea->_is_nil() )
897 MaxElArea->SetMaxElementArea( MaxArea );
899 catch (SALOME::SALOME_Exception& S_ex) {
900 QtCatchCorbaException(S_ex);
903 myActiveStudy->updateObjBrowser(true);
904 QApplication::restoreOverrideCursor();
907 //=============================================================================
911 //=============================================================================
912 void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume )
914 QApplication::setOverrideCursor( Qt::waitCursor );
916 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
917 SMESH::SMESH_MaxElementVolume_var MaxElVolume = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
918 if ( !MaxElVolume->_is_nil() )
919 MaxElVolume->SetMaxElementVolume( MaxVolume );
921 catch (const SALOME::SALOME_Exception& S_ex) {
922 QtCatchCorbaException(S_ex);
924 myActiveStudy->updateObjBrowser(true);
925 QApplication::restoreOverrideCursor();
928 //=============================================================================
932 //=============================================================================
933 void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments )
935 QApplication::setOverrideCursor( Qt::waitCursor );
937 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
938 SMESH::SMESH_NumberOfSegments_var NbS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
939 if ( !NbS->_is_nil() )
940 NbS->SetNumberOfSegments( nbSegments );
942 catch (const SALOME::SALOME_Exception& S_ex) {
943 QtCatchCorbaException(S_ex);
945 myActiveStudy->updateObjBrowser(true);
946 QApplication::restoreOverrideCursor();
949 //=============================================================================
953 //=============================================================================
954 int SMESHGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName )
956 int nbSel = Sel->IObjectCount() ;
958 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
959 aName = IObject->getName();
961 aName = tr( "SMESH_OBJECTS_SELECTED" ).arg( nbSel );
966 //=============================================================================
970 //=============================================================================
971 int SMESHGUI::GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName )
974 int nbSel = Sel->IObjectCount() ;
976 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
977 if ( !IObject->hasEntry() )
980 Standard_Boolean res;
981 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
985 TColStd_MapOfInteger MapIndex;
986 Sel->GetIndex( IObject, MapIndex );
987 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
989 nbNodes = MapIndex.Extent();
990 for ( ; ite.More(); ite.Next() ) {
991 aName = aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) + " ";
999 //=============================================================================
1003 //=============================================================================
1004 int SMESHGUI::GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName )
1007 int nbSel = Sel->IObjectCount() ;
1009 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1010 if ( !IObject->hasEntry() )
1013 Standard_Boolean res;
1014 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1018 TColStd_MapOfInteger MapIndex;
1019 Sel->GetIndex( IObject, MapIndex );
1020 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1022 nbElements = MapIndex.Extent();
1023 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1024 for ( ; ite.More(); ite.Next() ) {
1025 int idVTK = ite.Key();
1026 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1027 aName = aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1036 //=============================================================================
1040 //=============================================================================
1041 int SMESHGUI::GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName )
1044 int nbSel = Sel->IObjectCount() ;
1046 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1047 if ( !IObject->hasEntry() )
1050 Standard_Boolean res;
1051 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1055 TColStd_MapOfInteger MapIndex;
1056 Sel->GetIndex( IObject, MapIndex );
1057 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1059 nbElements = MapIndex.Extent();
1060 for ( ; ite.More(); ite.Next() ) {
1061 aName = aName + QString("%1").arg(ite.Key()) + " ";
1070 //=============================================================================
1074 //=============================================================================
1075 SMESH_Actor* SMESHGUI::FindActorByEntry(QString entry,
1076 Standard_Boolean& testResult,
1077 bool onlyInActiveView)
1079 int nbSf = myActiveStudy->getStudyFramesCount();
1080 for ( int i = 0; i < nbSf; i++ ) {
1081 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
1082 if ( sf->getTypeView() == VIEW_VTK ) {
1083 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1084 vtkActorCollection* theActors = Renderer->GetActors();
1085 theActors->InitTraversal();
1086 vtkActor *ac = theActors->GetNextActor();
1087 while(!(ac==NULL)) {
1088 if ( ac->IsA("SMESH_Actor") ) {
1089 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1090 if ( anActor->hasIO() ) {
1091 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1092 if ( strcmp( IO->getEntry(), entry ) == 0 ) {
1093 if ( onlyInActiveView ) {
1094 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
1105 ac = theActors->GetNextActor();
1110 MESSAGE ( " Actor Not Found " )
1112 return SMESH_Actor::New();
1115 //=============================================================================
1119 //=============================================================================
1120 SMESH_Actor* SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1121 Standard_Boolean& testResult,
1122 bool onlyInActiveView)
1124 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
1125 if ( SM->_is_nil() ) {
1126 MESSAGE ( " Actor Not Found " )
1129 return SMESH_Actor::New();
1132 return FindActorByEntry( SM->GetID(), testResult, onlyInActiveView);
1135 //=============================================================================
1139 //=============================================================================
1140 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO,
1141 Standard_Boolean& testResult)
1143 SMESH::SMESH_Mesh_var aMesh;
1144 testResult = false ;
1147 if ( IO->hasEntry() ) {
1148 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1149 SALOMEDS::GenericAttribute_var anAttr;
1150 SALOMEDS::AttributeIOR_var anIOR;
1151 if ( !obj->_is_nil() ) {
1152 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1153 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1154 aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1155 if ( !aMesh->_is_nil() ) {
1157 return SMESH::SMESH_Mesh::_duplicate( aMesh );
1162 return SMESH::SMESH_Mesh::_nil();
1165 //=============================================================================
1169 //=============================================================================
1170 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO,
1171 Standard_Boolean& testResult)
1173 SMESH::SMESH_subMesh_var aSubMesh;
1174 testResult = false ;
1177 if ( IO->hasEntry() ) {
1178 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1179 SALOMEDS::GenericAttribute_var anAttr;
1180 SALOMEDS::AttributeIOR_var anIOR;
1181 if ( !obj->_is_nil() ) {
1182 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1183 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1184 aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1185 if ( !aSubMesh->_is_nil() ) {
1187 return SMESH::SMESH_subMesh::_duplicate( aSubMesh );
1192 return SMESH::SMESH_subMesh::_nil();
1195 //=============================================================================
1199 //=============================================================================
1200 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO,
1201 Standard_Boolean& testResult )
1203 SMESH::SMESH_Hypothesis_var aHyp ;
1204 testResult = false ;
1207 if ( IO->hasEntry() ) {
1208 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1209 SALOMEDS::GenericAttribute_var anAttr;
1210 SALOMEDS::AttributeIOR_var anIOR;
1211 if ( !obj->_is_nil() ) {
1212 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1213 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1214 aHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()));
1215 if ( !aHyp->_is_nil() ) {
1217 return SMESH::SMESH_Hypothesis::_duplicate( aHyp );
1222 return SMESH::SMESH_Hypothesis::_nil();
1227 //=============================================================================
1231 //=============================================================================
1232 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO,
1233 Standard_Boolean& testResult )
1235 GEOM::GEOM_Shape_var aShape ;
1236 testResult = false ;
1239 if ( IO->hasEntry() ) {
1240 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1241 SALOMEDS::GenericAttribute_var anAttr;
1242 SALOMEDS::AttributeIOR_var anIOR;
1243 if ( !obj->_is_nil() ) {
1244 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1245 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1246 aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
1247 if ( !aShape->_is_nil() ) {
1249 return GEOM::GEOM_Shape::_duplicate( aShape );
1254 return GEOM::GEOM_Shape::_nil();
1258 //=============================================================================
1262 //=============================================================================
1263 void SMESHGUI::SetViewMode(int commandId)
1265 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1266 int nbSel = Sel->IObjectCount();
1268 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1269 for ( ; It.More(); It.Next() ) {
1270 Handle(SALOME_InteractiveObject) IObject = It.Value();
1271 if ( IObject->hasEntry() ) {
1272 Standard_Boolean res;
1273 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1275 switch (commandId) {
1277 ChangeRepresentation( ac, 0 );
1281 ChangeRepresentation( ac, 1 );
1285 ChangeRepresentation( ac, 2 );
1289 ChangeRepresentation( ac, 3 );
1296 if ( commandId == 1133 ) {
1297 ChangeRepresentation( SMESH_Actor::New(), 4 );
1302 //=============================================================================
1306 //=============================================================================
1307 void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
1309 if (ac->DataSource == NULL && type != 4 )
1313 if ( ac->getMapper() == NULL ) {
1319 QApplication::setOverrideCursor( Qt::waitCursor );
1320 if (ac->getDisplayMode()==2) {
1321 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1322 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1323 meshMapper->SetInput(ac->DataSource);
1324 meshMapper->SetScalarVisibility(isColored); //SAL3899
1326 ac->setDisplayMode(0);
1327 ac->GetProperty()->SetRepresentationToWireframe();
1328 // ac->SetActorProperty( ac->GetProperty() );
1329 QApplication::restoreOverrideCursor();
1333 QApplication::setOverrideCursor( Qt::waitCursor );
1334 if (ac->getDisplayMode()==2) {
1335 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1336 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1337 meshMapper->SetInput(ac->DataSource);
1338 meshMapper->SetScalarVisibility(isColored); //SAL3899
1340 ac->setDisplayMode(1);
1341 ac->GetProperty()->SetRepresentationToSurface();
1342 QApplication::restoreOverrideCursor();
1343 // ac->SetActorProperty( ac->GetProperty() );
1347 // if (!(ac->getDisplayMode()==2)) {
1348 // ChangeRepresentation(ac, 1);
1349 QApplication::setOverrideCursor( Qt::waitCursor );
1350 ac->setDisplayMode(2);
1351 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1352 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1353 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1354 shrink->SetInput(ac->DataSource);
1355 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1357 meshMapper->SetInput( shrink->GetOutput() );
1358 meshMapper->SetScalarVisibility(isColored); //SAL3899
1359 ac->SetMapper( meshMapper );
1360 QApplication::restoreOverrideCursor();
1368 float backfacecolor[3];
1370 ac->GetColor(color[0],color[1],color[2]);
1371 QColor c(color[0]*255,color[1]*255,color[2]*255);
1372 ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
1373 QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1374 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1375 QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1376 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
1377 QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1379 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1380 if ( Edgewidth == 0 )
1382 int intValue = ac->GetNodeSize() ;
1383 float Shrink = ac->GetShrinkFactor();
1385 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "" ) ;
1386 aDlg->SetColor(1,c);
1387 aDlg->SetColor(2,e);
1388 aDlg->SetColor(3,n);
1389 aDlg->SetColor(4,b);
1390 aDlg->SetIntValue(1,Edgewidth);
1391 aDlg->SetIntValue(2,intValue);
1392 aDlg->SetIntValue(3,int(Shrink*100.));
1394 if ( aDlg->exec() ) {
1395 QApplication::setOverrideCursor( Qt::waitCursor );
1396 QColor color = aDlg->GetColor(1);
1397 QColor edgecolor = aDlg->GetColor(2);
1398 QColor nodecolor = aDlg->GetColor(3);
1399 QColor backfacecolor = aDlg->GetColor(4);
1400 /* actor color and backface color */
1401 ac->GetProperty()->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1402 ac->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1403 ac->GetBackfaceProperty()->SetColor(float(backfacecolor.red())/255.,float(backfacecolor.green())/255.,float(backfacecolor.blue())/255.);
1406 ac->EdgeDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1407 float(edgecolor.green())/255.,
1408 float(edgecolor.blue())/255.);
1409 ac->EdgeShrinkDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1410 float(edgecolor.green())/255.,
1411 float(edgecolor.blue())/255.);
1412 ac->SetEdgeColor(float(edgecolor.red())/255.,
1413 float(edgecolor.green())/255.,
1414 float(edgecolor.blue())/255.);
1416 /* Shrink factor and size edges */
1417 ac->SetShrinkFactor( aDlg->GetIntValue(3)/100. );
1418 ac->EdgeDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1419 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1421 /* Nodes color and size */
1422 ac->SetNodeColor(float(nodecolor.red())/255.,
1423 float(nodecolor.green())/255.,
1424 float(nodecolor.blue())/255.);
1425 ac->SetNodeSize(aDlg->GetIntValue(2)) ;
1427 if (ac->getDisplayMode()==2) {
1428 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1429 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1430 meshMapper->SetInput(ac->DataSource);
1431 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1432 shrink->SetInput(meshMapper->GetInput());
1433 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1435 meshMapper->SetInput( shrink->GetOutput() );
1436 meshMapper->SetScalarVisibility(isColored); //SAL3899
1437 ac->SetMapper( meshMapper );
1441 QApplication::restoreOverrideCursor();
1446 EmitSignalDeactivateDialog() ;
1447 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1448 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg( QAD_Application::getDesktop(), "", Sel) ;
1452 QApplication::setOverrideCursor( Qt::waitCursor );
1453 ac->GetProperty()->SetRepresentationToPoints();
1454 QApplication::restoreOverrideCursor();
1459 QApplication::setOverrideCursor( Qt::waitCursor );
1460 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1461 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1462 theRenderer->Render();
1464 QApplication::restoreOverrideCursor();
1467 //=============================================================================
1471 //=============================================================================
1472 void SMESHGUI::UpdateView()
1474 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1477 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1478 theRenderer->Render();
1481 //=============================================================================
1485 //=============================================================================
1486 void SMESHGUI::DisplayActor(SMESH_Actor* ac, bool visibility)
1488 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1491 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1493 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1494 vtkActorCollection* theActors = theRenderer->GetActors();
1495 theActors->InitTraversal();
1496 if ( theActors->IsItemPresent(ac) == 0 ) {
1497 vtkProperty* prop = vtkProperty::New();
1498 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1499 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1500 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. ) ;
1502 prop->SetPointSize( QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
1503 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
1504 ac->SetProperty( prop );
1505 ac->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1506 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1507 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. );
1509 // prop->BackfaceCullingOn();
1510 vtkProperty* backprop = vtkProperty::New();
1511 backprop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed").toFloat()/255.,
1512 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").toFloat()/255.,
1513 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").toFloat()/255. ) ;
1514 ac->SetBackfaceProperty(backprop);
1516 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1519 ac->SetShrinkFactor( intValue/100. );
1521 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1522 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1524 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1525 if ( DisplayMode.compare("Wireframe") == 0 ){
1526 ac->setDisplayMode(0);
1527 ChangeRepresentation( ac, 0 );
1528 } else if ( DisplayMode.compare("Shading") == 0 ){
1529 ac->setDisplayMode(1);
1530 ChangeRepresentation( ac, 1 );
1531 } else if ( DisplayMode.compare("Shrink") == 0 ) {
1532 ac->setDisplayMode(2);
1533 ChangeRepresentation( ac, 2 );
1535 theRenderer->AddActor(ac);
1537 if (ac->GetMapper())
1538 ac->GetMapper()->Update();
1541 // if ( visibility )
1542 ac->SetVisibility(visibility);
1543 // ac->VisibilityOn();
1545 // ac->VisibilityOff();
1547 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1551 //=============================================================================
1555 //=============================================================================
1556 void SMESHGUI::EraseActor(SMESH_Actor* ac)
1558 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1561 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1563 //NRI- : 02/12/2002 : Fixed bugId 882
1564 // ac->EdgeDevice->VisibilityOff();
1565 // ac->EdgeShrinkDevice->VisibilityOff();
1566 // ac->VisibilityOff();
1567 ac->SetVisibility( false );
1569 theRenderer->Render();
1572 //=============================================================================
1576 //=============================================================================
1577 bool SMESHGUI::AddActorInSelection(SMESH_Actor* ac)
1579 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1580 Sel->ClearIObjects();
1582 return Sel->AddIObject( ac->getIO() );
1587 //=============================================================================
1591 //=============================================================================
1592 QString SMESHGUI::CheckHomogeneousSelection()
1594 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1597 SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
1598 for (; Itinit.More(); Itinit.Next()) {
1599 List.Append(Itinit.Value());
1602 QString RefType = CheckTypeObject( Sel->firstIObject() );
1603 SALOME_ListIteratorOfListIO It( List );
1604 for (; It.More(); It.Next()) {
1605 Handle(SALOME_InteractiveObject) IObject = It.Value();
1606 QString Type = CheckTypeObject( IObject );
1607 if ( Type.compare( RefType ) != 0 )
1608 return "Heterogeneous Selection";
1611 Sel->ClearIObjects();
1612 SALOME_ListIteratorOfListIO It1( List );
1613 for(;It1.More();It1.Next()) {
1614 int res = Sel->AddIObject( It1.Value() );
1616 myActiveStudy->highlight( It1.Value(), false );
1618 myActiveStudy->highlight( It1.Value(), true );
1623 //=============================================================================
1627 //=============================================================================
1628 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO)
1630 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
1631 if (!sobj->_is_nil()) {
1632 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1633 if (strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected
1638 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1639 Sel->ClearIObjects();
1641 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter( HYPOTHESIS );
1642 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter( ALGORITHM );
1643 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
1644 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
1645 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
1646 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter( SUBMESH_VERTEX );
1647 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter( SUBMESH_EDGE );
1648 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter( SUBMESH_FACE );
1649 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter( SUBMESH_SOLID );
1650 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter( SUBMESH_COMPOUND );
1652 Sel->AddFilter(aHypFilter);
1653 if ( Sel->AddIObject( IO ) != -1 ) {
1654 Sel->ClearFilters();
1655 return "Hypothesis";
1658 Sel->ClearFilters();
1659 Sel->AddFilter(anAlgoFilter);
1660 if ( Sel->AddIObject( IO ) != -1 ) {
1661 Sel->ClearFilters();
1665 Sel->ClearFilters();
1666 Sel->AddFilter(aMeshFilter);
1667 if ( Sel->AddIObject( IO ) != -1 ) {
1668 Sel->ClearFilters();
1672 Sel->ClearFilters();
1673 Sel->AddFilter(aSubMeshFilter);
1674 if ( Sel->AddIObject( IO ) != -1 ) {
1675 Sel->ClearFilters();
1679 Sel->ClearFilters();
1680 Sel->AddFilter(aSubMeshVextexFilter);
1681 if ( Sel->AddIObject( IO ) != -1 ) {
1682 Sel->ClearFilters();
1683 return "SubMeshVertex";
1686 Sel->ClearFilters();
1687 Sel->AddFilter(aSubMeshEdgeFilter);
1688 if ( Sel->AddIObject( IO ) != -1 ){
1689 Sel->ClearFilters();
1690 return "SubMeshEdge";
1693 Sel->ClearFilters();
1694 Sel->AddFilter(aSubMeshFaceFilter);
1695 if ( Sel->AddIObject( IO ) != -1 ) {
1696 Sel->ClearFilters();
1697 return "SubMeshFace";
1700 Sel->ClearFilters();
1701 Sel->AddFilter(aSubMeshSolidFilter);
1702 if ( Sel->AddIObject( IO ) != -1 ) {
1703 Sel->ClearFilters();
1704 return "SubMeshSolid";
1707 Sel->ClearFilters();
1708 Sel->AddFilter(aSubMeshCompoundFilter);
1709 if ( Sel->AddIObject( IO ) != -1 ) {
1710 Sel->ClearFilters();
1711 return "SubMeshCompound";
1714 Sel->ClearFilters();
1715 Sel->AddIObject( IO );
1719 //=============================================================================
1723 //=============================================================================
1724 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1726 /* Create or retrieve an object SMESHGUI */
1727 SMESHGUI::GetOrCreateSMESHGUI(parent);
1729 // NRI : Temporary added
1730 if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
1735 // QAD_Viewer3d* v3d;
1736 OCCViewer_Viewer3d* v3d;
1738 Handle(AIS_InteractiveContext) ic;
1739 vtkRenderer* Renderer;
1740 vtkRenderWindow* RenWin;
1742 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1743 v3d =((OCCViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1744 ic = v3d->getAISContext();
1745 } else if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1746 Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1747 RenWin = Renderer->GetRenderWindow();
1750 switch (theCommandID)
1753 smeshGUI->OnEditDelete();
1760 Import_Document(parent,theCommandID);//NBU
1761 //Import_Mesh(parent,theCommandID);
1765 case 122: // EXPORT MED
1769 Export_Mesh(parent, theCommandID);
1773 case 200: // SCALAR BAR
1775 smeshGUI->DisplayScalarBar(false);
1780 SMESHGUI_EditScalarBarDlg *aDlg = new SMESHGUI_EditScalarBarDlg( parent, "", false ) ;
1786 smeshGUI->DisplayScalarBar( true );
1790 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
1796 smeshGUI->SetViewMode(theCommandID);
1800 case 214 : // UPDATE
1808 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1809 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1811 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1812 for(;It.More();It.Next()) {
1813 Handle(SALOME_InteractiveObject) IOS = It.Value();
1814 if ( IOS->hasEntry() ) {
1815 Standard_Boolean res;
1816 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IOS->getEntry(), res, true );
1817 if ( res ) smeshGUI->EraseActor( ac );
1821 Sel->ClearIObjects();
1822 smeshGUI->myActiveStudy->updateObjBrowser( true );
1825 case 301 : // DISPLAY
1827 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1829 QApplication::setOverrideCursor( Qt::waitCursor );
1830 SALOMEDS::SObject_var fatherSF =
1831 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1833 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1834 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1836 for(;It.More();It.Next()) {
1837 Handle(SALOME_InteractiveObject) IObject = It.Value();
1838 if ( IObject->hasEntry() ) {
1839 Standard_Boolean res;
1840 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1842 smeshGUI->DisplayActor( ac, true );
1843 smeshGUI->DisplayEdges( ac );
1844 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1848 QApplication::restoreOverrideCursor();
1853 case 302 : // DISPLAY ONLY
1855 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1856 QApplication::setOverrideCursor( Qt::waitCursor );
1857 vtkActorCollection* theActors = Renderer->GetActors();
1858 theActors->InitTraversal();
1859 vtkActor *ac = theActors->GetNextActor();
1860 while(!(ac==NULL)) {
1861 if ( ac->IsA("SMESH_Actor") ) {
1862 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1863 if(!anActor->isHighlighted()) {
1864 //anActor->VisibilityOff();
1865 //NRI- : 02/12/2002 : Fixed bugId 882
1866 // anActor->EdgeDevice->VisibilityOff();
1867 // anActor->EdgeShrinkDevice->VisibilityOff();
1868 anActor->SetVisibility( false );
1871 ac = theActors->GetNextActor();
1874 // Display selection
1875 SALOMEDS::SObject_var fatherSF = smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1877 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1878 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1880 for(;It.More();It.Next()) {
1881 Handle(SALOME_InteractiveObject) IObject = It.Value();
1882 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1884 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
1885 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
1887 if(myRenderInter->isInViewer(IObject)) {
1888 if ( IObject->hasEntry() ) {
1889 Standard_Boolean res;
1890 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1892 smeshGUI->DisplayActor( ac, true );
1893 smeshGUI->DisplayEdges( ac );
1894 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1899 smeshGUI->myActiveStudy->updateObjBrowser( true );
1900 QApplication::restoreOverrideCursor();
1907 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1908 smeshGUI->EmitSignalDeactivateDialog() ;
1909 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1910 Sel->ClearIObjects();
1911 smeshGUI->myDesktop->SetSelectionMode(1, true);
1912 parent->menuBar()->setItemChecked(9010, false );
1913 parent->menuBar()->setItemChecked(9011, false );
1914 smeshGUI->ViewNodes();
1915 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg( parent, "", Sel ) ;
1917 QApplication::restoreOverrideCursor();
1918 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1919 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
1924 case 405: // MOVE NODE
1926 smeshGUI->myDesktop->SetSelectionMode(1, true);
1927 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1928 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, "", Sel ) ;
1932 case 701: // COMPUTE MESH
1934 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1935 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1936 int nbSel = Sel->IObjectCount();
1938 QApplication::restoreOverrideCursor();
1942 SMESH::SMESH_Mesh_var aM;
1943 SMESH::SMESH_subMesh_var aSubM;
1944 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1945 if ( IObject->hasEntry() ) {
1946 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1947 SALOMEDS::GenericAttribute_var anAttr;
1948 SALOMEDS::AttributeIOR_var anIOR;
1949 if ( !aMorSM->_is_nil() ) {
1950 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
1951 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1952 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : IOR = " << anIOR->Value() )
1953 CORBA::Object_var cobj;
1955 cobj = _orb->string_to_object(anIOR->Value());
1956 if ( CORBA::is_nil(cobj) ) {
1957 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : nil object" )
1960 catch(CORBA::COMM_FAILURE& ex) {
1961 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : exception (1)" )
1963 aM = SMESH::SMESH_Mesh::_narrow(cobj);
1964 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1965 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1966 if ( !aM->_is_nil() ) {
1967 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1968 if ( !refShape->_is_nil() ) {
1969 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1971 QApplication::restoreOverrideCursor();
1972 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1973 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1977 smeshGUI->myComponentMesh->Compute( aM, refShape);
1978 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1979 // TO Do : change icon of all submeshes
1981 catch (const SALOME::SALOME_Exception& S_ex) {
1982 QtCatchCorbaException(S_ex);
1985 } else if ( !aSubM->_is_nil() ) {
1986 aM = aSubM->GetFather();
1987 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1988 if ( !refShape->_is_nil() ) {
1989 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1991 QApplication::restoreOverrideCursor();
1992 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1993 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1997 smeshGUI->myComponentMesh->Compute( aM, refShape);
1998 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1999 // TO Do : change icon of all submeshes
2001 catch (const SALOME::SALOME_Exception& S_ex) {
2002 QtCatchCorbaException(S_ex);
2010 // Check whether the actor for the mesh exists at least in one view
2011 Standard_Boolean res;
2012 SMESH_Actor* ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2014 smeshGUI->InitActor( aM );
2016 // Check whether the actor belongs to the active view
2017 VTKViewer_RenderWindowInteractor* rwInter =
2018 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2020 // The actor belongs to inactive view -> create a copy and add it in the active view
2021 if (!rwInter->isInViewer(IObject)) {
2022 SMESH_Actor* acCopy = SMESH_Actor::New();
2023 acCopy->ShallowCopy(ac);
2025 smeshGUI->DisplayActor( acCopy, false );
2029 if ( smeshGUI->myAutomaticUpdate ) {
2030 SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
2031 if ( Mesh != NULL ) {
2035 smeshGUI->DisplayActor( Mesh, true );
2036 smeshGUI->DisplayEdges( Mesh, true );
2037 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
2041 QApplication::restoreOverrideCursor();
2042 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2043 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2045 QApplication::restoreOverrideCursor();
2049 case 702: // ADD SUB MESH
2051 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2052 smeshGUI->EmitSignalDeactivateDialog() ;
2053 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2054 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg( parent, "", Sel ) ;
2056 QApplication::restoreOverrideCursor();
2057 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2058 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2063 case 703: // INIT MESH
2065 smeshGUI->EmitSignalDeactivateDialog() ;
2066 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2067 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg( parent, "", Sel ) ;
2071 case 704: // EDIT Hypothesis
2073 smeshGUI->EmitSignalDeactivateDialog() ;
2074 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2075 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2079 case 705: // EDIT Global Hypothesis
2081 smeshGUI->EmitSignalDeactivateDialog() ;
2082 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2083 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2087 case 706: // EDIT Local Hypothesis
2089 smeshGUI->EmitSignalDeactivateDialog() ;
2090 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2091 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2095 case 806: // ORIENTATION ELEMENTS
2097 smeshGUI->EmitSignalDeactivateDialog() ;
2098 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2099 smeshGUI->myDesktop->SetSelectionMode(3, true);
2100 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg( parent, "", Sel ) ;
2104 case 807: // DIAGONAL INVERSION
2106 smeshGUI->EmitSignalDeactivateDialog() ;
2107 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2108 Sel->ClearIObjects();
2109 smeshGUI->myDesktop->SetSelectionMode(2, true);
2110 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg( parent, "", Sel ) ;
2114 case 900: // MESH INFOS
2116 smeshGUI->EmitSignalDeactivateDialog() ;
2117 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2118 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg( parent, "", Sel ) ;
2122 case 1001: // AUTOMATIC UPDATE PREFERENCES
2124 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001) );
2125 if ( parent->menuBar()->isItemChecked(1001) ) {
2126 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","true");
2127 smeshGUI->myAutomaticUpdate = true;
2129 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","false");
2130 smeshGUI->myAutomaticUpdate = false;
2135 case 1003: // MESH PREFERENCES
2137 smeshGUI->SetDisplaySettings();
2143 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2144 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2145 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2146 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2147 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2148 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2149 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2150 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2151 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2153 if ( Width == 0 ) Width = 0.17;
2154 if ( Height == 0 ) Height = 0.8;
2155 if ( NumberOfLabels == 0 ) NumberOfLabels = 5;
2156 if ( NumberOfColors == 0) NumberOfColors = 64;
2158 SMESHGUI_Preferences_ScalarBarDlg *aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, "", true) ;
2160 if ( Bold.compare("true") == 0 )
2161 aDlg->Bold->setChecked(true); else aDlg->Bold->setChecked(false);
2162 if ( Italic.compare("true") == 0 )
2163 aDlg->Italic->setChecked(true); else aDlg->Italic->setChecked(false);
2164 if ( Shadow.compare("true") == 0 )
2165 aDlg->Shadow->setChecked(true); else aDlg->Shadow->setChecked(false);
2167 if ( Orientation.compare("Horizontal") == 0 )
2168 aDlg->RadioHoriz->setChecked(true); else aDlg->RadioVert->setChecked(true);
2170 int NbItems = aDlg->ComboBox1->count();
2172 aDlg->ComboBox1->setCurrentItem( i );
2173 while ( i < NbItems ) {
2174 if ( FontFamily.compare( aDlg->ComboBox1->text( i ) ) == 0 )
2175 aDlg->ComboBox1->setCurrentItem( i );
2179 aDlg->LineEditWidth->setText( QString("%1").arg(Width) );
2180 aDlg->LineEditHeight->setText( QString("%1").arg(Height) );
2182 aDlg->SpinBoxLabels->setValue( NumberOfLabels );
2183 aDlg->SpinBoxColors->setValue( NumberOfColors );
2186 if ( aDlg->result() ) {
2187 if ( aDlg->RadioHoriz->isChecked() )
2188 Orientation = "Horizontal"; else Orientation = "Vertical";
2189 if ( aDlg->Bold->isChecked() )
2190 Bold = "true"; else Bold = "false";
2191 if ( aDlg->Italic->isChecked() )
2192 Italic = "true"; else Italic = "false";
2193 if ( aDlg->Shadow->isChecked() )
2194 Shadow = "true"; else Shadow = "false";
2196 FontFamily = aDlg->ComboBox1->currentText();
2197 Width = aDlg->LineEditWidth->text().toFloat();
2198 Height = aDlg->LineEditHeight->text().toFloat();
2199 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2200 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2203 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
2204 if ( aScalarBar != NULL ) {
2205 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2206 FontFamily, Orientation,
2207 Width, Height, NumberOfColors, NumberOfLabels);
2210 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2211 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2212 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2213 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2214 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2215 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2216 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2217 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2218 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2223 case 1100: // EDIT HYPOTHESIS
2225 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2226 int nbSel = Sel->IObjectCount() ;
2229 Standard_Boolean res;
2230 SMESH::SMESH_Hypothesis_var Hyp = smeshGUI->ConvertIOinSMESHHypothesis( Sel->firstIObject(), res );
2232 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2233 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2234 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2235 SALOMEDS::Study::ListOfSObject_var listSOmesh = smeshGUI->GetMeshesUsingAlgoOrHypothesis( Hyp) ;
2238 QString Name = Hyp->GetName();
2240 if ( Name.compare("LocalLength") == 0 ) {
2241 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
2242 double beforeLength = LL->GetLength() ;
2243 double Length = smeshGUI->Parameter( res,
2245 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2248 if ( res && Length != beforeLength ) {
2249 LL->SetLength( Length );
2250 for( int i=0; i<listSOmesh->length(); i++ ) {
2251 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2256 } else if ( Name.compare("NumberOfSegments") == 0 ) {
2257 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
2258 int beforeNbSeg = NOS->GetNumberOfSegments() ;
2259 int NbSeg = smeshGUI->Parameter( res,
2261 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2265 if ( res && NbSeg != beforeNbSeg ) {
2266 NOS->SetNumberOfSegments( NbSeg );
2267 for( int i=0; i<listSOmesh->length(); i++ ) {
2268 SALOMEDS::SObject_var SO = listSOmesh[i] ;
2269 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2274 } else if ( Name.compare("MaxElementArea") == 0 ) {
2275 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
2276 double beforeMaxArea = MEA->GetMaxElementArea() ;
2277 double MaxArea = smeshGUI->Parameter( res,
2279 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2282 if ( res && MaxArea != beforeMaxArea ) {
2283 MEA->SetMaxElementArea( MaxArea );
2284 for( int i=0; i<listSOmesh->length(); i++ ) {
2285 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2290 } else if ( Name.compare("MaxElementVolume") == 0 ) {
2291 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
2292 double beforeMaxVolume = MEV->GetMaxElementVolume() ;
2293 double MaxVolume = smeshGUI->Parameter( res,
2295 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2298 if ( res && MaxVolume != beforeMaxVolume ) {
2299 MEV->SetMaxElementVolume( MaxVolume );
2300 for( int i=0; i<listSOmesh->length(); i++ ) {
2301 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2306 } else if ( Name.compare("Regular_1D") == 0 ) {
2307 } else if ( Name.compare("MEFISTO_2D") == 0 ) {
2316 case 1101: // RENAME
2318 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2319 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2320 for ( ; It.More(); It.Next() ) {
2321 Handle(SALOME_InteractiveObject) IObject = It.Value();
2323 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2324 SALOMEDS::GenericAttribute_var anAttr;
2325 SALOMEDS::AttributeName_var aName;
2326 if ( !obj->_is_nil() ) {
2327 if (obj->FindAttribute(anAttr, "AttributeName")) {
2328 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2329 QString newName = QString( aName->Value() );
2330 newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName);
2331 if ( !newName.isEmpty() ) {
2332 QApplication::setOverrideCursor( Qt::waitCursor );
2333 smeshGUI->myActiveStudy->renameIObject( IObject, newName );
2335 QApplication::restoreOverrideCursor();
2342 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2344 QApplication::setOverrideCursor( Qt::waitCursor );
2345 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2346 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2347 for ( int i=0; It.More(); It.Next(), i++ ) {
2348 Handle(SALOME_InteractiveObject) IObject = It.Value();
2349 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh( IObject );
2351 Sel->ClearIObjects();
2352 smeshGUI->myActiveStudy->updateObjBrowser( true );
2353 QApplication::restoreOverrideCursor();
2357 case 401: // GEOM::EDGE
2359 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2360 smeshGUI->EmitSignalDeactivateDialog() ;
2361 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2362 Sel->ClearIObjects();
2363 smeshGUI->myDesktop->SetSelectionMode(1, true);
2364 parent->menuBar()->setItemChecked(9010, false );
2365 parent->menuBar()->setItemChecked(9011, false );
2366 smeshGUI->ViewNodes();
2367 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg( parent, "", Sel ) ;
2369 QApplication::restoreOverrideCursor();
2370 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2371 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2375 case 4021: // TRIANGLE
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_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 3 ) ;
2387 QApplication::restoreOverrideCursor();
2388 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2389 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
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, 4 ) ;
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_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( 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, 8 ) ;
2441 QApplication::restoreOverrideCursor();
2442 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2443 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2448 case 4041: // REMOVES NODES
2450 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2451 smeshGUI->EmitSignalDeactivateDialog() ;
2452 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2453 Sel->ClearIObjects();
2454 smeshGUI->myDesktop->SetSelectionMode(1, true);
2455 parent->menuBar()->setItemChecked(9010, false );
2456 parent->menuBar()->setItemChecked(9011, false );
2457 smeshGUI->ViewNodes();
2458 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg( parent, "", Sel ) ;
2460 QApplication::restoreOverrideCursor();
2461 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2462 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2466 case 4042: // REMOVES ELEMENTS
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(3, true);
2473 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg( parent, "", Sel ) ;
2475 QApplication::restoreOverrideCursor();
2476 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2477 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2482 case 5000: // HYPOTHESIS - ALGO
2484 smeshGUI->CreateAlgorithm("Regular_1D","Wire Discretisation");
2489 smeshGUI->CreateAlgorithm("MEFISTO_2D","Triangle (Mefisto)");
2494 smeshGUI->CreateAlgorithm("Quadrangle_2D","Quadrangle (Mapping)");
2499 smeshGUI->CreateAlgorithm("Hexa_3D","Hexahedron (i,j,k)");
2503 case 5030: // HYPOTHESIS - LOCAL LENGTH
2505 smeshGUI->EmitSignalDeactivateDialog() ;
2506 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2507 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg( parent, "" ) ;
2510 case 5031: // HYPOTHESIS - NB SEGMENTS
2512 smeshGUI->EmitSignalDeactivateDialog() ;
2513 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2514 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg( parent, "" ) ;
2518 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
2520 smeshGUI->EmitSignalDeactivateDialog() ;
2521 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2522 SMESHGUI_MaxElementAreaDlg *aDlg = new SMESHGUI_MaxElementAreaDlg( parent, "" ) ;
2526 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
2528 smeshGUI->EmitSignalDeactivateDialog() ;
2529 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2530 SMESHGUI_MaxElementVolumeDlg *aDlg = new SMESHGUI_MaxElementVolumeDlg( parent, "" ) ;
2534 case 6016: // CONTROLS
2542 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2543 int nbSel = Sel->IObjectCount();
2546 smeshGUI->Control(theCommandID);
2552 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2553 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2554 SMESHGUI_EdgesConnectivityDlg *Dlg = new SMESHGUI_EdgesConnectivityDlg( parent, "", Sel ) ;
2556 QApplication::restoreOverrideCursor();
2557 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2558 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2565 if ( !parent->menuBar()->isItemChecked(9010) ) {
2566 QApplication::setOverrideCursor( Qt::waitCursor );
2567 parent->menuBar()->setItemChecked(9011, false );
2569 smeshGUI->EraseSimulationActors();
2570 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2572 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2573 int nbSel = Sel->IObjectCount() ;
2575 Standard_Boolean res;
2576 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2578 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2580 // It's necessary to display SMDS IDs instead of VTK ones, so
2581 // vtkIdFilter is unacceptable here. We have to do it manually :(
2582 vtkUnstructuredGrid* ptGrid = vtkUnstructuredGrid::New();
2583 ptGrid->CopyStructure(MeshActor->DataSource);
2585 int numPts = MeshActor->DataSource->GetNumberOfPoints();
2587 // Loop over points and generate ids
2588 vtkIntArray *ptIds = vtkIntArray::New();
2589 ptIds->SetNumberOfValues(numPts);
2591 for (int id=0; id < numPts; id++) {
2592 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
2593 ptIds->SetValue(id, idSMDS);
2596 // mpv porting vtk4.2.2
2597 // vtkScalars* newScalars = vtkScalars::New();
2598 // newScalars->SetData(ptIds);
2599 // ptGrid->GetPointData()->SetScalars(newScalars);
2600 ptGrid->GetPointData()->SetScalars(ptIds);
2601 // newScalars->Delete();
2605 vtkMaskPoints* mask = vtkMaskPoints::New();
2606 mask->SetInput(ptGrid);
2607 mask->SetOnRatio( 1 );
2608 // mask->SetMaximumNumberOfPoints( 50 );
2609 // mask->RandomModeOn();
2611 vtkSelectVisiblePoints* visPts = vtkSelectVisiblePoints::New();
2612 visPts->SetInput(mask->GetOutput());
2613 visPts->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2614 //visPts->SetSelectInvisible(1);
2615 visPts->SelectInvisibleOff();
2616 visPts->SetTolerance(0.1);
2618 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2619 ldm->SetInput(visPts->GetOutput());
2620 ldm->SetLabelFormat("%g");
2621 ldm->SetLabelModeToLabelScalars();
2622 //ldm->SetLabelModeToLabelFieldData();
2624 ldm->SetFontFamilyToTimes();
2625 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2630 vtkActor2D* pointLabels = vtkActor2D::New();
2631 pointLabels->SetMapper(ldm);
2632 pointLabels->GetProperty()->SetColor(0,1,0);
2636 smeshGUI->mySimulationActors2D->AddItem( pointLabels );
2637 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( pointLabels );
2641 QApplication::setOverrideCursor( Qt::waitCursor );
2642 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2643 smeshGUI->EraseSimulationActors();
2644 smeshGUI->ScalarVisibilityOff();
2646 QApplication::restoreOverrideCursor();
2651 if ( !parent->menuBar()->isItemChecked(9011) ) {
2652 QApplication::setOverrideCursor( Qt::waitCursor );
2653 parent->menuBar()->setItemChecked(9010, false );
2655 smeshGUI->EraseSimulationActors();
2656 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2658 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2659 int nbSel = Sel->IObjectCount() ;
2661 Standard_Boolean res;
2662 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2664 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2666 // It's necessary to display SMDS IDs instead of VTK ones, so
2667 // vtkIdFilter is unacceptable here. We have to do it manually :(
2668 vtkUnstructuredGrid* elGrid = vtkUnstructuredGrid::New();
2669 elGrid->CopyStructure(MeshActor->DataSource);
2671 int numCells = MeshActor->DataSource->GetNumberOfCells();
2673 // Loop over points and generate ids
2674 vtkIntArray *cellIds = vtkIntArray::New();
2675 cellIds->SetNumberOfValues(numCells);
2677 for (int id=0; id < numCells; id++) {
2678 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
2679 cellIds->SetValue(id, idSMDS);
2682 // mpv porting vk4.2.2
2683 // vtkScalars* newScalars = vtkScalars::New();
2684 // newScalars->SetData(cellIds);
2685 elGrid->GetCellData()->SetScalars(cellIds);
2686 // elGrid->GetCellData()->SetScalars(newScalars);
2687 // newScalars->Delete();
2692 vtkCellCenters* cc = vtkCellCenters::New();
2693 cc->SetInput(elGrid);
2695 vtkSelectVisiblePoints* visCells = vtkSelectVisiblePoints::New();
2696 visCells->SetInput(cc->GetOutput());
2697 visCells->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2698 visCells->SelectInvisibleOff();
2699 visCells->SetTolerance(0.1);
2700 // visCells->SetSelectInvisible(1);
2702 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2703 ldm->SetInput(visCells->GetOutput());
2704 ldm->SetLabelFormat("%g");
2705 ldm->SetLabelModeToLabelScalars();
2707 ldm->SetFontFamilyToTimes();
2708 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2713 vtkActor2D* cellLabels = vtkActor2D::New();
2714 cellLabels->SetMapper(ldm);
2715 cellLabels->GetProperty()->SetColor(1,0,0);
2720 smeshGUI->mySimulationActors2D->AddItem( cellLabels );
2721 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( cellLabels );
2725 QApplication::setOverrideCursor( Qt::waitCursor );
2726 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2727 smeshGUI->EraseSimulationActors();
2728 smeshGUI->ScalarVisibilityOff();
2730 QApplication::restoreOverrideCursor();
2734 case 10001: // DISPLAY MODE PREFERENCE
2736 parent->menuBar()->setItemChecked(10001, !parent->menuBar()->isItemChecked(10001) );
2737 parent->menuBar()->setItemChecked(10002, false );
2738 parent->menuBar()->setItemChecked(10003, false );
2739 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2744 parent->menuBar()->setItemChecked(10002, !parent->menuBar()->isItemChecked(10002) );
2745 parent->menuBar()->setItemChecked(10001, false );
2746 parent->menuBar()->setItemChecked(10003, false );
2747 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2752 parent->menuBar()->setItemChecked(10003, !parent->menuBar()->isItemChecked(10003) );
2753 parent->menuBar()->setItemChecked(10002, false );
2754 parent->menuBar()->setItemChecked(10001, false );
2755 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
2761 smeshGUI->myActiveStudy->updateObjBrowser(true);
2766 //=============================================================================
2767 /*! function : GetMeshesUsingAlgoOrHypothesis()
2768 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
2769 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
2771 //=============================================================================
2772 SALOMEDS::Study::ListOfSObject* SMESHGUI::GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp )
2774 SALOMEDS::Study::ListOfSObject_var listSOmesh = new SALOMEDS::Study::ListOfSObject ;
2775 listSOmesh->length(0) ;
2776 unsigned int index = 0 ;
2777 if( !AlgoOrHyp->_is_nil() ) {
2778 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms( AlgoOrHyp );
2779 if( !SO_Hypothesis->_is_nil() ) {
2780 SALOMEDS::Study::ListOfSObject_var listSO = smeshGUI->myStudy->FindDependances(SO_Hypothesis) ;
2781 for( unsigned int i=0; i<listSO->length(); i++ ) {
2782 SALOMEDS::SObject_var SO = listSO[i] ;
2783 if( !SO->_is_nil() ) {
2784 SALOMEDS::SObject_var SOfatherFather = SO->GetFather()->GetFather() ;
2785 if( !SOfatherFather->_is_nil() ) {
2787 listSOmesh->length(index) ;
2788 listSOmesh[index-1] = SOfatherFather ;
2794 return listSOmesh._retn() ;
2798 //=============================================================================
2802 //=============================================================================
2803 void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
2807 Mesh_Reader* myReader;
2809 if (theCommandID==113) {
2810 filter = tr("MED files (*.med)");
2811 myExtension = string("MED");
2812 myReader = new DriverMED_R_SMESHDS_Mesh;
2814 else if (theCommandID==112) {
2815 filter = tr("IDEAS files (*.unv)");
2816 myExtension = string("UNV");
2818 else if (theCommandID==111) {
2819 filter = tr("DAT files (*.dat)");
2820 myExtension = string("MED");
2821 myReader = new DriverDAT_R_SMESHDS_Mesh;
2824 QString filename = QAD_FileDlg::getFileName(parent,
2829 if ( !filename.isEmpty() ) {
2830 QApplication::setOverrideCursor( Qt::waitCursor );
2831 string myClass = string("SMESHDS_Mesh");
2832 // Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
2834 int myMeshId = (smeshGUI->myDocument)->NewMesh();
2835 SMDS_Mesh* myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
2837 myReader->SetFile(string(filename.latin1()));
2838 myReader->SetMesh(myMesh);
2839 myReader->SetMeshId(myMeshId);
2842 QApplication::restoreOverrideCursor();
2846 //=============================================================================
2850 //=============================================================================
2851 void SMESHGUI::Export_Mesh(QAD_Desktop* parent, int theCommandID)
2853 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2854 int nbSel = Sel->IObjectCount() ;
2856 Standard_Boolean res;
2857 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2858 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh( IObject, res );
2860 if (theCommandID==122) { // EXPORT MED
2861 QString filename = QAD_FileDlg::getFileName(parent,
2863 tr("MED files (*.med)"),
2866 if ( !filename.isEmpty() ) {
2867 QApplication::setOverrideCursor( Qt::waitCursor );
2868 aMesh->ExportMED( filename.latin1() );
2869 QApplication::restoreOverrideCursor();
2872 else if (theCommandID==121) { // EXPORT DAT
2873 QString filename = QAD_FileDlg::getFileName(parent,
2875 tr("DAT files (*.dat)"),
2878 if ( !filename.isEmpty() ) {
2879 QApplication::setOverrideCursor( Qt::waitCursor );
2880 aMesh->ExportDAT( filename.latin1() );
2881 QApplication::restoreOverrideCursor();
2884 else if (theCommandID==123) { // EXPORT UNV
2885 QString filename = QAD_FileDlg::getFileName(parent,
2887 tr("IDEAS files (*.unv)"),
2890 if ( !filename.isEmpty() ) {
2891 QApplication::setOverrideCursor( Qt::waitCursor );
2892 aMesh->ExportUNV( filename.latin1() );
2893 QApplication::restoreOverrideCursor();
2896 aMesh->ExportDAT( filename.latin1() );
2898 QApplication::restoreOverrideCursor();
2900 if ( IObject->hasEntry() )
2903 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2904 SALOMEDS::GenericAttribute_var anAttr;
2905 SALOMEDS::AttributeComment_var aFileName;
2906 SALOMEDS::StudyBuilder_var aStudyBuilder = smeshGUI->myStudy->NewBuilder();
2907 anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
2908 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
2909 aFileName->SetValue(filename.latin1());
2916 //=============================================================================
2920 //=============================================================================
2921 void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
2925 Document_Reader* myReader;
2927 if (theCommandID==113) {
2928 filter = tr("MED files (*.med)");
2929 myExtension = string("MED");
2930 myReader = new DriverMED_R_SMESHDS_Document;
2932 else if (theCommandID==112) {
2933 filter = tr("IDEAS files (*.unv)");
2934 myExtension = string("UNV");
2935 myReader = new DriverUNV_R_SMESHDS_Document;
2937 else if (theCommandID==111) {
2938 filter = tr("DAT files (*.dat)");
2939 myExtension = string("DAT");
2940 myReader = new DriverDAT_R_SMESHDS_Document;
2943 QString filename = QAD_FileDlg::getFileName(parent,
2946 tr("Import document"),
2948 if ( !filename.isEmpty() ) {
2949 QApplication::setOverrideCursor( Qt::waitCursor );
2950 string myClass = string("SMESHDS_Document");
2951 // Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
2952 SMESHDS_Document* newDocument = new SMESHDS_Document(1);
2954 myReader->SetFile(string(filename.latin1()));
2955 myReader->SetDocument(smeshGUI->myDocument);
2957 QApplication::restoreOverrideCursor();
2961 void SMESHGUI::Export_Document(QAD_Desktop* parent, int theCommandID)
2964 Document_Writer* myWriter;
2967 if (theCommandID==122) {
2968 filter = tr("MED files (*.med)");
2969 myExtension = string("MED");
2970 myWriter = new DriverMED_W_SMESHDS_Document;
2972 else if (theCommandID==121) {
2973 filter = tr("DAT files (*.dat)");
2974 myExtension = string("DAT");
2975 myWriter = new DriverDAT_W_SMESHDS_Document;
2976 } else if (theCommandID==123) {
2977 filter = tr("IDEAS files (*.unv)");
2978 myExtension = string("UNV");
2979 myWriter = new DriverUNV_W_SMESHDS_Document;
2982 QString filename = QAD_FileDlg::getFileName(parent,
2985 tr("Export document"),
2987 if ( !filename.isEmpty() ) {
2988 QApplication::setOverrideCursor( Qt::waitCursor );
2989 string myClass = string("SMESHDS_Document");
2990 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
2992 myWriter->SetFile(string(filename.latin1()));
2993 myWriter->SetDocument(smeshGUI->myDocument);
2995 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
2996 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
2997 //myWriter->SetDocument(myDocument);
3000 QApplication::restoreOverrideCursor();
3004 //=============================================================================
3008 //=============================================================================
3009 bool SMESHGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3011 SMESHGUI::GetOrCreateSMESHGUI(parent);
3016 //=============================================================================
3020 //=============================================================================
3021 bool SMESHGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3023 SMESHGUI::GetOrCreateSMESHGUI(parent);
3029 //=============================================================================
3033 //=============================================================================
3034 bool SMESHGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3036 SMESHGUI::GetOrCreateSMESHGUI(parent);
3042 //=============================================================================
3046 //=============================================================================
3047 bool SMESHGUI::SetSettings( QAD_Desktop* parent )
3049 SMESHGUI::GetOrCreateSMESHGUI(parent);
3052 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3053 if ( DisplayMode.compare("") == 0 ) {
3054 DisplayMode = "Shading";
3055 QAD_CONFIG->addSetting("SMESH:DisplayMode","Shading");
3058 if ( DisplayMode.compare("Wireframe") == 0 ){
3059 parent->menuBar()->setItemChecked(10003, false );
3060 parent->menuBar()->setItemChecked(10002, false );
3061 parent->menuBar()->setItemChecked(10001, true );
3062 } else if ( DisplayMode.compare("Shading") == 0 ){
3063 parent->menuBar()->setItemChecked(10003, false );
3064 parent->menuBar()->setItemChecked(10002, true );
3065 parent->menuBar()->setItemChecked(10001, false );
3066 } else if ( DisplayMode.compare("Shrink") == 0 ) {
3067 parent->menuBar()->setItemChecked(10003, true );
3068 parent->menuBar()->setItemChecked(10002, false );
3069 parent->menuBar()->setItemChecked(10001, false );
3072 /* Automatic Update */
3073 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3074 if ( AutoUpdate.compare("true") == 0 ) {
3075 parent->menuBar()->setItemChecked(1001, true );
3076 smeshGUI->myAutomaticUpdate = true;
3078 parent->menuBar()->setItemChecked(1001, false );
3079 smeshGUI->myAutomaticUpdate = false;
3083 parent->menuBar()->setItemEnabled( 11, false); // IMPORT
3089 //=============================================================================
3093 //=============================================================================
3094 void SMESHGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
3096 /* Create or retrieve an object SMESHGUI */
3097 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3099 // NRI : Temporary added
3100 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3101 // theObject = "NothingSelected";
3102 // theContext = "NothingSelected";
3106 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3107 int nbSel = Sel->IObjectCount();
3109 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3110 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
3111 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1) ) {
3112 theObject = "ScalarBar";
3115 theObject = "NothingSelected";
3116 theContext = "NothingSelected";
3119 theObject = "NothingSelected";
3120 theContext = "NothingSelected";
3122 } else if (nbSel == 1 ) {
3123 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3126 theObject = smeshGUI->CheckHomogeneousSelection();
3131 //=============================================================================
3135 //=============================================================================
3136 bool SMESHGUI::CustomPopup( QAD_Desktop* parent,
3138 const QString& theContext,
3139 const QString& theParent,
3140 const QString& theObject )
3142 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3143 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3145 /* Create or retrieve an object SMESHGUI */
3146 SMESHGUI::GetOrCreateSMESHGUI(parent);
3148 // NRI : Temporary added
3149 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3154 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3155 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3156 int nbSel = Sel->IObjectCount();
3159 if (studyFrame->getTypeView() != VIEW_VTK)
3162 } else if (nbSel == 1 ) {
3163 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3164 // First check type of active viewer (VTK required)
3165 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3167 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3169 int id = popup->idAt(0);
3170 if (id <= QAD_TopLabel_Popup_ID)
3171 popup->removeItemAt(0);
3175 if (theObject.compare("Component") == 0) {
3176 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3181 // Remove common popup items for Submesh, Hypothesis and Algorithm
3182 if (theObject.compare("SubMesh") == 0 ||
3183 theObject.compare("Hypothesis") == 0 ||
3184 theObject.compare("Algorithm") == 0 ) {
3185 popup->removeItem(QAD_Display_Popup_ID);
3186 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3187 popup->removeItem(QAD_Erase_Popup_ID);
3188 int id = popup->idAt(popup->count()-1); // last item
3189 if (id < 0 && id != -1) popup->removeItem(id); // separator
3192 if (theObject.compare("Component") == 0) {
3193 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3197 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3198 QFont f = QApplication::font();
3201 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3203 if ( theParent.compare("Viewer")==0 ) {
3204 if (popup->idAt(0) == id) {
3205 popup->removeItem(id);
3206 popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), id, 0 );
3209 Standard_Boolean res;
3210 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3211 if ( res && studyFrame->getTypeView() == VIEW_VTK) {
3212 VTKViewer_RenderWindowInteractor* myRenderInter=
3213 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3214 if ( myRenderInter->isVisible( IObject ) ) {
3215 popup->removeItem(QAD_Display_Popup_ID);
3217 popup->removeItem(QAD_Erase_Popup_ID);
3220 popup->removeItem(QAD_Erase_Popup_ID);
3221 if (!res) {// mesh not computed -> can't display it
3222 popup->removeItem(QAD_Display_Popup_ID);
3223 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3224 popup->removeItemAt(popup->count() - 1);//separator
3227 } else if ( theParent.compare("ObjectBrowser")==0 ) {
3228 if (theObject.compare("Mesh") == 0 ||
3229 theObject.compare("SubMesh") == 0 ||
3230 theObject.compare("Hypothesis") == 0 ||
3231 theObject.compare("Algorithm") == 0 ) {
3232 popup->removeItemAt(0);
3234 if (popup->idAt(0) == id) {
3235 popup->removeItem(id);
3236 popup->removeItemAt(0);//separator
3240 Standard_Boolean res;
3241 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3242 if ( res && studyFrame->getTypeView() == VIEW_VTK ) {
3243 VTKViewer_RenderWindowInteractor* myRenderInter=
3244 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3245 if ( myRenderInter->isVisible( IObject ) ) {
3246 popup->removeItem(QAD_Display_Popup_ID);
3248 popup->removeItem(QAD_Erase_Popup_ID);
3251 if (theObject.compare("Mesh") == 0 ||
3252 theObject.compare("SubMesh") == 0 ||
3253 theObject.compare("Hypothesis") == 0 ||
3254 theObject.compare("Algorithm") == 0 ) {
3256 popup->removeItem(QAD_Erase_Popup_ID);
3257 if (!res) {// mesh not computed -> can't display it
3258 popup->removeItem(QAD_Display_Popup_ID);
3259 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3260 popup->removeItemAt(popup->count() - 1);//separator
3266 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3267 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3268 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3270 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3272 int id = popup->idAt(0);
3273 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3274 popup->removeItemAt(0);
3278 if (parentComp.isNull()) { // objects from several components are selected
3279 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3280 popup->removeItem(QAD_Display_Popup_ID);
3281 popup->removeItem(QAD_Erase_Popup_ID);
3282 int id = popup->idAt(popup->count()-1); // last item
3283 if (id < 0 && id != -1) popup->removeItem(id); // separator
3288 QString type = smeshGUI->CheckHomogeneousSelection();
3289 if ( type.compare("Heterogeneous Selection") != 0 ) {
3290 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3291 QFont f = QApplication::font();
3293 popup->removeItem(id);
3294 popup->insertItem( new CustomItem ( QString("%1 ").arg(nbSel) + type + " (s) ", f), id, 0 );
3300 //=============================================================================
3301 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3302 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3304 //=============================================================================
3305 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3307 /* Create or retrieve an object SMESHGUI */
3308 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3310 QAD_StudyFrame* activeFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3311 if (activeFrame->getTypeView() == VIEW_VTK) {
3313 SALOMEDS::SObject_var fatherSF =
3314 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
3316 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3317 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3319 // for(;It.More();It.Next()) {
3320 // Handle(SALOME_InteractiveObject) IObject = It.Value();
3321 Handle(SALOME_InteractiveObject) IObject = theIO;
3322 if ( IObject->hasEntry() ) {
3323 // Look for the actor in all views
3324 Standard_Boolean res;
3325 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3327 // Actor not found at all -> mesh is not computed -> do nothing!!!
3329 /*SMESH::SMESH_Mesh_var aM;
3330 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3331 SALOMEDS::SObject_var father = aMorSM->GetFather();
3332 SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
3334 // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
3335 if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
3338 SALOMEDS::GenericAttribute_var anAttr;
3339 SALOMEDS::AttributeIOR_var anIOR;
3340 if ( !aMorSM->_is_nil() ) {
3341 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
3342 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3343 aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
3347 if (!aM->_is_nil()) {
3348 smeshGUI->InitActor(aM);
3349 ac = smeshGUI->ReadScript(aM);
3353 smeshGUI->DisplayActor( ac, true );
3354 smeshGUI->DisplayEdges( ac );
3355 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3358 } else { // The actor exists in some view
3359 // Check whether the actor belongs to the active view
3360 VTKViewer_RenderWindowInteractor* rwInter =
3361 ((VTKViewer_ViewFrame*)activeFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3363 // The actor belongs to inactive view -> create a copy and display it in the active view
3364 if (!rwInter->isInViewer(IObject)) {
3365 SMESH_Actor* acCopy = SMESH_Actor::New();
3366 acCopy->ShallowCopy(ac);
3369 smeshGUI->DisplayActor( ac, false );
3370 smeshGUI->DisplayEdges( ac );
3371 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3376 MESSAGE("BuildPresentation() must not be called while non-VTK view is active")
3380 //=============================================================================
3384 //=============================================================================
3385 void SMESHGUI::setOrb()
3388 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
3389 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
3390 _orb = init( 0 , 0 );
3392 INFOS("internal error : orb not found");
3395 ASSERT(! CORBA::is_nil(_orb));
3399 //=============================================================================
3403 //=============================================================================
3404 SMESH_Actor* SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
3406 SMESH_Actor* MeshActor;
3407 if ( !aMesh->_is_nil() ) {
3408 Standard_Boolean result;
3409 MeshActor = FindActor(aMesh, result, true);
3411 SMESH::log_array_var aSeq = aMesh->GetLog(true);
3413 if (aSeq->length() == 0) {
3414 MESSAGE("ReadScript(): log is empty")
3418 for (unsigned int ind = 0; ind < aSeq->length();ind++) {
3419 switch ( aSeq[ind].commandType )
3421 case SMESH::ADD_NODE :
3423 AddNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3426 case SMESH::ADD_EDGE :
3428 // AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3431 case SMESH::ADD_TRIANGLE :
3433 AddTriangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3436 case SMESH::ADD_QUADRANGLE :
3438 AddQuadrangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3441 case SMESH::ADD_TETRAHEDRON :
3443 AddTetras( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3446 case SMESH::ADD_PYRAMID :
3450 case SMESH::ADD_PRISM :
3454 case SMESH::ADD_HEXAHEDRON :
3456 AddHexaedres( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3459 case SMESH::REMOVE_NODE :
3461 RemoveNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3464 case SMESH::REMOVE_ELEMENT :
3466 RemoveElements( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3478 //=============================================================================
3482 //=============================================================================
3483 void SMESHGUI::Dump(SMESH_Actor* Mactor)
3485 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3486 vtkPoints *Pts = ugrid->GetPoints();
3487 int nbPts = Pts->GetNumberOfPoints();
3488 int nbCells = ugrid->GetNumberOfCells();
3492 In = fopen("/tmp/dumpMesh","w+");
3493 fprintf(In,"%d %d\n",nbPts,nbCells);
3494 for ( int i = 0; i < nbPts; i++ ) {
3495 float *p = ugrid->GetPoint(i);
3496 fprintf(In,"%d %e %e %e\n",i, p[0], p[1], p[2] );
3499 for ( int i = 0; i < nbCells; i++ ) {
3500 fprintf(In,"%d %d",i,ugrid->GetCell(i)->GetCellType());
3501 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3502 for (j=0; j<Id->GetNumberOfIds(); j++) {
3503 fprintf(In," %d",Id->GetId(j));
3511 //=============================================================================
3515 //=============================================================================
3516 void SMESHGUI::AddNodes( SMESH_Actor* Mactor, int number,
3517 const SMESH::double_array& coords,
3518 const SMESH::long_array& indexes)
3520 QApplication::setOverrideCursor( Qt::waitCursor );
3521 if ( Mactor->GetMapper() == NULL ) {
3522 vtkPoints *Pts = vtkPoints::New();
3523 SMESH_Grid *ugrid = SMESH_Grid::New();
3528 while ( i <= number ) {
3529 int idVTK = Pts->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3530 //Mactor->AddNode( indexes[i-1], idVTK );
3531 ugrid->AddNode( indexes[i-1], idVTK );
3535 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3536 ugrid->SetPoints(Pts);
3537 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3538 PtsMapper->SetInput( ugrid );
3539 Mactor->DataSource = PtsMapper->GetInput();
3540 Mactor->SetMapper(PtsMapper);
3542 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3543 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3546 while ( i <= number ) {
3547 int idVTK = ugrid->GetPoints()->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3548 ugrid->AddNode( indexes[i-1], idVTK );
3552 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3553 PtsMapper->SetInput( ugrid );
3554 Mactor->DataSource = PtsMapper->GetInput();
3555 Mactor->SetMapper(PtsMapper);
3557 QApplication::restoreOverrideCursor();
3560 //=============================================================================
3564 //=============================================================================
3565 void SMESHGUI::AddNode(SMESH_Actor* Mactor, int idnode, float x, float y, float z)
3567 QApplication::setOverrideCursor( Qt::waitCursor );
3568 MESSAGE ( "SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z )
3569 if ( Mactor->GetMapper() == NULL ) {
3570 vtkPoints *Pts = vtkPoints::New();
3571 int idVTK = Pts->InsertNextPoint( x, y, z );
3572 //Mactor->AddNode( idnode, idVTK );
3573 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3574 SMESH_Grid *ugrid = SMESH_Grid::New();
3576 ugrid->AddNode( idnode, idVTK );
3577 ugrid->SetPoints(Pts);
3578 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3579 PtsMapper->SetInput( ugrid );
3580 Mactor->DataSource = PtsMapper->GetInput();
3581 Mactor->SetMapper(PtsMapper);
3583 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3584 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3585 int idVTK = ugrid->GetPoints()->InsertNextPoint( x, y, z );
3586 //Mactor->AddNode( idnode, idVTK );
3587 ugrid->AddNode( idnode, idVTK );
3588 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3589 PtsMapper->SetInput( ugrid );
3590 Mactor->DataSource = PtsMapper->GetInput();
3591 Mactor->SetMapper(PtsMapper);
3593 QApplication::restoreOverrideCursor();
3596 //=============================================================================
3600 //=============================================================================
3601 void SMESHGUI::RemoveNode(SMESH_Actor* Mactor, int idnode)
3603 MESSAGE ( " OLD RemoveNode method " )
3604 // int id = Mactor->GetIdVTKNode( idnode );
3605 // MESSAGE ( " RemoveNode id VTK " << id )
3606 // if ( Mactor->GetMapper() != NULL ) {
3607 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3608 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3609 // vtkPoints *Pts = ugrid->GetPoints();
3610 // vtkPoints *newPts = vtkPoints::New();
3611 // int nbPts = Pts->GetNumberOfPoints();
3612 // bool findPt = false;
3613 // for ( int i = 0; i < nbPts; i++ ) {
3616 // newPts->InsertPoint(i, Pts->GetPoint(i) );
3618 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
3621 // Mactor->RemoveNode( idnode );
3625 // newUgrid->SetPoints(newPts);
3626 // int nbCells = ugrid->GetNumberOfCells();
3627 // for ( int i = 0; i < nbCells; i++ ) {
3628 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3629 // vtkIdList *newIds = vtkIdList::New();
3630 // int nbIds = Ids->GetNumberOfIds();
3631 // newIds->SetNumberOfIds(nbIds);
3632 // for ( int j = 0; j < nbIds; j++ ) {
3633 // int theid = Ids->GetId(j);
3634 // if ( theid > id ) {
3635 // newIds->SetId( j, theid-1 );
3637 // newIds->SetId( j, theid );
3639 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3640 // Mactor->RemoveElement( idSMDSel, false );
3641 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3642 // Mactor->AddElement( idSMDSel, idVTKel );
3646 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3647 // Mapper->SetInput( newUgrid );
3648 // Mactor->DataSource = Mapper->GetInput();
3649 // Mactor->SetMapper(Mapper);
3655 //=============================================================================
3659 //=============================================================================
3660 void SMESHGUI::RemoveNodes(SMESH_Actor* Mactor, int number,
3661 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3663 QApplication::setOverrideCursor( Qt::waitCursor );
3665 while ( i <= number ) {
3666 Mactor->RemoveNode( indexes[i-1] );
3670 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
3671 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
3672 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
3674 if ( Mactor->GetMapper() != NULL ) {
3675 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3676 SMESH_Grid *newUgrid = SMESH_Grid::New();
3677 newUgrid->CopyMaps(ugrid);
3679 vtkPoints *Pts = ugrid->GetPoints();
3680 vtkPoints *newPts = vtkPoints::New();
3681 int nbPts = Pts->GetNumberOfPoints();
3683 for ( int i = 0; i < nbPts; i++ ) {
3684 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
3685 if ( idSMESHDSNode != -1 ) {
3686 newPts->InsertPoint(j, Pts->GetPoint(i) );
3688 newMapVTKNodes.Bind(j, idSMESHDSNode);
3689 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
3691 MapOldNodesToNewNodes.Bind(i,j);
3696 newUgrid->SetIdsVTKNode(newMapVTKNodes);
3697 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
3698 newUgrid->SetPoints(newPts);
3700 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3701 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3703 int nbCells = ugrid->GetNumberOfCells();
3704 for ( int i = 0; i < nbCells; i++ ) {
3705 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3706 vtkIdList *newIds = vtkIdList::New();
3707 int nbIds = Ids->GetNumberOfIds();
3708 newIds->SetNumberOfIds(nbIds);
3710 for ( int j = 0; j < nbIds; j++ ) {
3711 int theid = Ids->GetId(j);
3712 if ( MapOldNodesToNewNodes.IsBound( theid ) ) {
3713 newIds->SetId( j, MapOldNodesToNewNodes.Find( theid ) );
3720 // Filtering out cells based on non-existing nodes
3722 int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3723 int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3725 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
3726 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
3730 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3731 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3733 // Copy new data to the old DatSource: keep the single DataSource for all actors
3734 ugrid->DeepCopy(newUgrid);
3736 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3737 Mapper->SetInput( ugrid );
3738 Mactor->SetMapper(Mapper);
3740 // Commented to avoid multiple viewer updates when called by ReadScript()
3744 QApplication::restoreOverrideCursor();
3747 //=============================================================================
3751 //=============================================================================
3752 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3754 QApplication::setOverrideCursor( Qt::waitCursor );
3755 Standard_Boolean result;
3756 SMESH_Actor* ac = FindActor( aMesh, result, true );
3758 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3759 anArrayOfIdeces->length(MapIndex.Extent());
3760 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3762 for ( ; ite.More(); ite.Next() ) {
3763 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
3764 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
3767 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3768 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3771 if ( myAutomaticUpdate ) {
3772 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3773 if ( Mesh != NULL ) {
3774 smeshGUI->DisplayActor( Mesh );
3775 smeshGUI->DisplayEdges( Mesh );
3776 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3777 AddActorInSelection( Mesh );
3780 QApplication::restoreOverrideCursor();
3783 //=============================================================================
3787 //=============================================================================
3788 void SMESHGUI::RemoveElement(SMESH_Actor* Mactor, int idelement)
3790 MESSAGE ( " OLD RemoveElement method " )
3791 // int id = Mactor->GetIdVTKElement( idelement );
3792 // MESSAGE ( " RemoveElement id VTK : " << id )
3793 // if ( Mactor->GetMapper() != NULL ) {
3794 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3795 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3797 // int nbCells = ugrid->GetNumberOfCells();
3798 // for ( int i = 0; i < nbCells; i++ ) {
3800 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3801 // ugrid->GetCell(i)->GetPointIds() );
3803 // Mactor->RemoveElement( idelement );
3805 // newUgrid->SetPoints(ugrid->GetPoints());
3807 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3808 // Mapper->SetInput( newUgrid );
3809 // Mactor->DataSource = Mapper->GetInput();
3810 // Mactor->SetMapper(Mapper);
3816 //=============================================================================
3820 //=============================================================================
3821 void SMESHGUI::RemoveElements(SMESH_Actor* Mactor, int number,
3822 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3824 QApplication::setOverrideCursor( Qt::waitCursor );
3826 while ( i <= number ) {
3827 Mactor->RemoveElement( indexes[i-1] );
3830 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3831 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3833 if ( Mactor->GetMapper() != NULL ) {
3834 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3835 SMESH_Grid* newUgrid = SMESH_Grid::New();
3836 newUgrid->CopyMaps(ugrid);
3838 int nbCells = ugrid->GetNumberOfCells();
3839 for ( int i = 0; i < nbCells; i++ ) {
3840 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
3841 if ( idSMESHDSElement != -1 ) {
3842 int newId = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3843 ugrid->GetCell(i)->GetPointIds() );
3844 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
3845 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
3849 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3850 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3852 newUgrid->SetPoints(ugrid->GetPoints());
3854 // Copy new data to the old DatSource: keep the single DataSource for all actors
3855 ugrid->DeepCopy(newUgrid);
3857 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3858 Mapper->SetInput( ugrid );
3859 Mactor->SetMapper(Mapper);
3861 // Commented to avoid multiple viewer updates when called by ReadScript()
3864 QApplication::restoreOverrideCursor();
3867 //=============================================================================
3871 //=============================================================================
3872 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3874 QApplication::setOverrideCursor( Qt::waitCursor );
3875 Standard_Boolean result;
3876 SMESH_Actor* ac = FindActor( aMesh, result, true );
3878 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3879 anArrayOfIdeces->length(MapIndex.Extent());
3880 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3882 for ( ; ite.More(); ite.Next() ) {
3883 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
3884 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
3888 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3889 aMeshEditor->RemoveElements(anArrayOfIdeces);
3892 if ( myAutomaticUpdate ) {
3893 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3894 if ( Mesh != NULL ) {
3895 smeshGUI->DisplayActor( Mesh );
3896 smeshGUI->DisplayEdges( Mesh );
3897 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3898 AddActorInSelection( Mesh );
3904 QApplication::restoreOverrideCursor();
3908 //=============================================================================
3912 //=============================================================================
3913 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3915 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3918 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3919 Standard_Boolean result;
3920 SMESH_Actor* ac = FindActor( aMesh, result, true );
3922 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3923 SMESH_Grid* UGrid = SMESH_Grid::New();
3924 SMESH_Grid* oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
3925 UGrid->CopyMaps(oldGrid);
3927 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3928 gf->SetInput( ac->DataSource );
3930 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3931 Mapper->SetInput( gf->GetOutput() );
3934 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3935 for ( ; ite.More(); ite.Next() ) {
3936 Mapper->GetInput()->ReverseCell( ite.Key() );
3939 UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
3940 int nbCells = Mapper->GetInput()->GetNumberOfCells();
3941 for ( int i = 0; i < nbCells; i++ ) {
3942 UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
3945 // Copy new data to the old DatSource: keep the single DataSource for all actors
3946 oldGrid->DeepCopy(UGrid);
3948 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
3949 //NewMapper->SetInput( UGrid );
3950 NewMapper->SetInput( oldGrid );
3951 NewMapper->Update();
3953 //ac->DataSource = NewMapper->GetInput();
3954 ac->SetMapper( NewMapper );
3956 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3958 QApplication::restoreOverrideCursor();
3962 //=============================================================================
3966 //=============================================================================
3967 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3969 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3972 QApplication::setOverrideCursor( Qt::waitCursor );
3973 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3974 Standard_Boolean result;
3976 SMESH_Actor* ac = FindActor( aMesh, result, true );
3978 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3979 SMESH_Grid* UGrid = SMESH_Grid::New();
3980 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3981 gf->SetInput( ac->DataSource );
3983 vtkExtractEdges *edges = vtkExtractEdges::New();
3984 edges->SetInput( ac->DataSource );
3986 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3987 Mapper->SetInput( edges->GetOutput() );
3990 int nb = Mapper->GetInput()->GetNumberOfCells();
3991 //MESSAGE ( "nb : " << nb )
3993 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3994 for ( ; ite.More(); ite.Next() ) {
3995 vtkCell* StartEdge = Mapper->GetInput()->GetCell(ite.Key());
3996 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
3997 int CellType = StartEdge->GetCellType();
3998 //MESSAGE( "DCQ : Cell Type = " << CellType)
3999 int nbPoints = StartEdge->GetNumberOfPoints();
4001 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4002 if ( nbPoints == 2 ) {
4003 vtkUnstructuredGrid* StartUGrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
4005 vtkIdList *IdCells = vtkIdList::New();
4006 vtkIdList *IdPoints = StartEdge->GetPointIds();
4010 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),p1);
4011 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),p2);
4013 int idp1 = StartUGrid->FindPoint(p1);
4014 int idp2 = StartUGrid->FindPoint(p2);
4016 StartUGrid->GetPointCells( idp1, IdCells );
4018 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4019 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4021 //MESSAGE ( " pt 0 : " << idp1 )
4022 //MESSAGE ( " pt 1 : " << idp2 )
4024 vtkIdList *IdPts = vtkIdList::New();
4025 if (IdCells->GetNumberOfIds() >= 2) {
4026 int nbCells = IdCells->GetNumberOfIds();
4027 //MESSAGE ( " nbCells : " << nbCells )
4028 for (int j=0; j<nbCells; j++) {
4029 StartUGrid->GetCellPoints( IdCells->GetId(j), IdPts );
4030 if ( IdPts->IsId( idp2 ) == -1 ) {
4031 IdCells->DeleteId( IdCells->GetId(j) );
4036 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4038 vtkIdList *IdPts0 = vtkIdList::New();
4039 vtkIdList *IdPts1 = vtkIdList::New();
4041 if (IdCells->GetNumberOfIds() == 2) {
4042 StartUGrid->GetCellPoints( IdCells->GetId(0), IdPts0 );
4043 StartUGrid->GetCellPoints( IdCells->GetId(1), IdPts1 );
4046 TColStd_MapOfInteger EndMapIndex;
4047 for (int j = 0; j < 3; j++ ) {
4048 if ( IdPts0->GetId(j) != idp1 && IdPts0->GetId(j) != idp2 ) {
4049 EndMapIndex.Add( IdPts0->GetId(j) );
4051 if ( IdPts1->GetId(j) != idp1 && IdPts1->GetId(j) != idp2 ) {
4052 EndMapIndex.Add( IdPts1->GetId(j) );
4056 bool MyAU = myAutomaticUpdate ;
4057 myAutomaticUpdate = false ;
4059 EndMapIndex.Add( idp1 );
4060 TColStd_MapIteratorOfMapOfInteger ite1( EndMapIndex );
4062 while ( ite1.More() ) {
4063 if ( ite1.Key() == idp1 )
4068 bool reverse1 = ( i == 2 );
4069 this->AddFace( aMesh, EndMapIndex, reverse1 );
4071 EndMapIndex.Remove( idp1 );
4072 EndMapIndex.Add( idp2 );
4073 TColStd_MapIteratorOfMapOfInteger ite2( EndMapIndex );
4075 while ( ite2.More() ) {
4076 if ( ite2.Key() == idp2 )
4081 bool reverse2 = ( i == 2 );
4082 this->AddFace( aMesh, EndMapIndex, !(reverse1 == reverse2) );
4084 myAutomaticUpdate = MyAU ;
4085 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4088 TColStd_MapOfInteger StartMapIndex;
4089 StartMapIndex.Add( IdCells->GetId(0) );
4090 StartMapIndex.Add( IdCells->GetId(1) );
4091 this->RemoveElements( aMesh, StartMapIndex );
4099 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4100 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4101 // for ( int i = 0; i < nbCells; i++ ) {
4102 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4105 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4106 // NewMapper->SetInput( UGrid );
4107 // NewMapper->Update();
4109 // ac->DataSource = NewMapper->GetInput();
4110 // ac->SetMapper( NewMapper );
4112 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4114 QApplication::restoreOverrideCursor();
4118 //=============================================================================
4122 //=============================================================================
4123 void SMESHGUI::AddEdges( SMESH_Actor* Mactor, int number,
4124 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4126 QApplication::setOverrideCursor( Qt::waitCursor );
4127 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4128 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4131 while ( i <= number ) {
4132 vtkIdList *Ids = vtkIdList::New();
4133 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4134 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4135 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4136 Mactor->AddElement( indexes[j-1], id );
4140 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4141 EdgeMapper->SetInput( ugrid );
4142 Mactor->DataSource = EdgeMapper->GetInput();
4143 Mactor->SetMapper(EdgeMapper);
4144 QApplication::restoreOverrideCursor();
4147 //=============================================================================
4151 //=============================================================================
4152 void SMESHGUI::AddEdge(SMESH_Actor* Mactor, int idedge, int idnode1, int idnode2)
4154 QApplication::setOverrideCursor( Qt::waitCursor );
4155 MESSAGE ( "SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" << idnode2 )
4156 vtkIdList *Ids = vtkIdList::New();
4157 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4158 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4160 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4161 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4162 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4163 Mactor->AddElement( idedge, id );
4165 MESSAGE ( " Edge VTK id " << id )
4167 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4168 EdgeMapper->SetInput( ugrid );
4169 Mactor->DataSource = EdgeMapper->GetInput();
4170 Mactor->SetMapper(EdgeMapper);
4171 QApplication::restoreOverrideCursor();
4174 //=============================================================================
4178 //=============================================================================
4179 void SMESHGUI::AddTriangles( SMESH_Actor* Mactor, int number,
4180 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4182 QApplication::setOverrideCursor( Qt::waitCursor );
4183 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4184 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4187 while ( i <= number ) {
4188 vtkIdList *Ids = vtkIdList::New();
4189 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4190 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4191 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4192 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4193 Mactor->AddElement( indexes[j-1], id );
4197 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4198 TriMapper->SetInput( ugrid );
4199 Mactor->DataSource = TriMapper->GetInput();
4200 Mactor->SetMapper(TriMapper);
4201 QApplication::restoreOverrideCursor();
4203 void SMESHGUI::AddTriangle(SMESH_Actor* Mactor, int idtri, int idnode1, int idnode2, int idnode3)
4205 QApplication::setOverrideCursor( Qt::waitCursor );
4206 vtkIdList *Ids = vtkIdList::New();
4207 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4208 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4209 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4211 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4212 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4213 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4214 Mactor->AddElement( idtri, id );
4216 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4217 TriMapper->SetInput( ugrid );
4218 Mactor->DataSource = TriMapper->GetInput();
4219 Mactor->SetMapper(TriMapper);
4220 QApplication::restoreOverrideCursor();
4223 //=============================================================================
4227 //=============================================================================
4228 void SMESHGUI::AddQuadrangles( SMESH_Actor* Mactor, int number,
4229 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4231 QApplication::setOverrideCursor( Qt::waitCursor );
4232 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4233 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4236 while ( i <= number ) {
4237 vtkIdList *Ids = vtkIdList::New();
4238 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4239 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4240 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4241 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4242 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4243 Mactor->AddElement( indexes[j-1], id );
4247 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4248 QuadMapper->SetInput( ugrid );
4249 Mactor->DataSource = QuadMapper->GetInput();
4250 Mactor->SetMapper(QuadMapper);
4251 QApplication::restoreOverrideCursor();
4255 //=============================================================================
4259 //=============================================================================
4260 void SMESHGUI::AddQuadrangle(SMESH_Actor* Mactor, int idquad, int idnode1, int idnode2,
4261 int idnode3, int idnode4)
4263 QApplication::setOverrideCursor( Qt::waitCursor );
4264 vtkIdList *Ids = vtkIdList::New();
4265 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4266 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4267 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4268 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4270 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4271 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4272 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4273 Mactor->AddElement( idquad, id );
4275 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4276 QuadMapper->SetInput( ugrid );
4277 Mactor->DataSource = QuadMapper->GetInput();
4278 Mactor->SetMapper(QuadMapper);
4279 QApplication::restoreOverrideCursor();
4283 //=============================================================================
4287 //=============================================================================
4288 void SMESHGUI::AddTetras( SMESH_Actor* Mactor, int number,
4289 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4291 QApplication::setOverrideCursor( Qt::waitCursor );
4292 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4293 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4296 while ( i <= number ) {
4297 vtkIdList *Ids = vtkIdList::New();
4298 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4299 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4300 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4301 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4302 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4303 Mactor->AddElement( indexes[j-1], id );
4307 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4308 TetraMapper->SetInput( ugrid );
4309 Mactor->DataSource = TetraMapper->GetInput();
4310 Mactor->SetMapper(TetraMapper);
4311 QApplication::restoreOverrideCursor();
4315 //=============================================================================
4319 //=============================================================================
4320 void SMESHGUI::AddTetra(SMESH_Actor* Mactor, int idtetra, int idnode1, int idnode2,
4321 int idnode3, int idnode4)
4323 QApplication::setOverrideCursor( Qt::waitCursor );
4324 MESSAGE ( "SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" << idnode2
4325 << ";" << idnode3 << ";" << idnode4 )
4326 vtkIdList *Ids = vtkIdList::New();
4327 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4328 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4329 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4330 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4332 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4333 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4334 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4335 Mactor->AddElement( idtetra, id );
4337 MESSAGE ( " Tetra VTK id " << id )
4339 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4340 TetraMapper->SetInput( ugrid );
4341 Mactor->DataSource = TetraMapper->GetInput();
4342 Mactor->SetMapper(TetraMapper);
4343 QApplication::restoreOverrideCursor();
4347 //=============================================================================
4351 //=============================================================================
4352 void SMESHGUI::AddHexaedres( SMESH_Actor* Mactor, int number,
4353 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4355 QApplication::setOverrideCursor( Qt::waitCursor );
4356 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4357 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4360 while ( i <= number ) {
4361 vtkIdList *Ids = vtkIdList::New();
4362 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4363 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4364 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4365 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4366 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+4] ) );
4367 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+5] ) );
4368 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+6] ) );
4369 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+7] ) );
4370 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4371 Mactor->AddElement( indexes[j-1], id );
4375 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4376 HexaMapper->SetInput( ugrid );
4377 Mactor->DataSource = HexaMapper->GetInput();
4378 Mactor->SetMapper(HexaMapper);
4379 QApplication::restoreOverrideCursor();
4383 //=============================================================================
4387 //=============================================================================
4388 void SMESHGUI::AddHexaedre(SMESH_Actor* Mactor, int idhexa, int idnode1, int idnode2,
4389 int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
4391 QApplication::setOverrideCursor( Qt::waitCursor );
4392 MESSAGE ( "SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" << idnode2
4393 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" << idnode6
4394 << ";" << idnode7 << ";" << idnode8)
4396 vtkIdList *Ids = vtkIdList::New();
4397 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4398 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4399 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4400 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4401 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode5 ) );
4402 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode6 ) );
4403 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode7 ) );
4404 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode8 ) );
4406 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4407 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4408 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4409 Mactor->AddElement( idhexa, id );
4411 MESSAGE ( " Hexa VTK id " << id )
4413 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4414 HexaMapper->SetInput( ugrid );
4415 Mactor->DataSource = HexaMapper->GetInput();
4416 Mactor->SetMapper(HexaMapper);
4417 QApplication::restoreOverrideCursor();
4420 //=====================================================================================
4422 //=====================================================================================
4425 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
4427 return SMESHGUI::OnGUIEvent(theCommandID, parent);
4430 bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4432 return SMESHGUI::OnKeyPress (pe, parent, studyFrame);
4435 bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4437 return SMESHGUI::OnMousePress (pe, parent, studyFrame);
4440 bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4442 return SMESHGUI::OnMouseMove (pe, parent, studyFrame);
4445 bool SetSettings ( QAD_Desktop* parent )
4447 return SMESHGUI::SetSettings( parent );
4450 bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
4451 const QString & theParent, const QString & theObject )
4453 return SMESHGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
4456 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
4458 SMESHGUI::DefinePopup( theContext, theParent, theObject );
4461 bool activeStudyChanged ( QAD_Desktop* parent )
4463 SMESHGUI::activeStudyChanged( parent );
4466 void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
4468 SMESHGUI::BuildPresentation(theIO);
4471 void supportedViewType(int* buffer, int bufferSize)
4473 if (!buffer || !bufferSize) return;
4474 buffer[0] = (int)VIEW_VTK;
4480 //=============================================================================
4484 //=============================================================================
4485 void SMESHGUI::ViewNodes()
4487 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4490 EraseSimulationActors();
4491 mySimulationActors = vtkActorCollection::New();
4492 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4493 vtkActorCollection* theActors = theRenderer->GetActors();
4494 theActors->InitTraversal();
4495 vtkActor *ac = theActors->GetNextActor();
4496 while(!(ac==NULL)) {
4497 if ( ac->IsA("SMESH_Actor") ) {
4498 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
4499 if ( anActor->GetVisibility() == 1 ) {
4500 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4501 gf->SetInput( anActor->DataSource );
4502 vtkMaskPoints *verts = vtkMaskPoints::New();
4503 verts->SetInput(gf->GetOutput());
4504 verts->GenerateVerticesOn();
4505 verts->SetOnRatio(1);
4507 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4508 vertMapper->SetInput(verts->GetOutput());
4509 vertMapper->ScalarVisibilityOff();
4511 vtkActor *vertActor = vtkActor::New();
4512 vertActor->SetMapper(vertMapper);
4515 anActor->GetNodeColor(r, g, b ) ;
4516 vertActor->GetProperty()->SetColor( r, g, b ) ;
4518 vertActor->GetProperty()->SetPointSize( anActor->GetNodeSize() );
4520 vertActor->PickableOff();
4522 mySimulationActors->AddItem( vertActor );
4523 theRenderer->AddActor( vertActor );
4526 ac = theActors->GetNextActor();
4529 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4534 //=============================================================================
4538 //=============================================================================
4539 void SMESHGUI::Control(int theCommandID)
4541 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4544 QApplication::setOverrideCursor( Qt::waitCursor );
4545 DisplayScalarBar( false );
4547 vtkDoubleArray *scalars = vtkDoubleArray::New();
4548 scalars->SetNumberOfComponents(1);
4550 vtkDataSetMapper* meshMapper = 0;
4551 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4552 int nbSel = Sel->IObjectCount();
4553 Standard_Boolean result;
4554 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
4555 SMESH_Actor* MeshActor = FindActorByEntry(IObject->getEntry(), result, true);
4557 // Mesh may be not updated after Compute
4558 if (!MeshActor->DataSource || !MeshActor->GetMapper()) {
4559 QApplication::restoreOverrideCursor();
4563 vtkDataSet* aDataSet = MeshActor->DataSource;
4564 typedef double (*TScalarFun)(vtkCell* theCell);
4565 TScalarFun aScalarFun;
4568 switch (theCommandID){
4570 type = tr( "SMESH_CONTROL_LENGTH_EDGES");
4571 aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
4572 aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
4573 MESSAGE ( " init minimum length " << aDataSet->GetNumberOfCells() );
4574 if(MeshActor->getDisplayMode() != 0)
4575 ChangeRepresentation( MeshActor, 1);// limitation; in Wireframe, colored edges are not visible
4579 type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
4580 aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
4581 if(MeshActor->getDisplayMode() != 1)
4582 ChangeRepresentation( MeshActor, 1 );
4586 type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
4587 aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
4591 type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
4592 aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
4593 if(MeshActor->getDisplayMode() != 1)
4594 ChangeRepresentation( MeshActor, 1 );
4598 type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
4599 aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
4600 if(MeshActor->getDisplayMode() != 1)
4601 ChangeRepresentation( MeshActor, 1 );
4605 type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
4606 aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
4610 type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
4611 aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
4615 for(int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
4616 scalars->InsertTuple1(i,aScalarFun(aDataSet->GetCell(i)));
4619 scalars->GetRange(range);
4621 vtkLookupTable* wat = vtkLookupTable::New();
4622 wat->SetRange( range );
4625 scalars->SetLookupTable(wat);
4627 if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
4628 meshMapper->SetScalarModeToUseCellData();
4629 MeshActor->DataSource->GetCellData()->SetScalars(scalars);
4630 meshMapper->SetScalarRange( range );
4631 meshMapper->ScalarVisibilityOn();
4633 vtkScalarBarActor* aScalarBar = GetScalarBar();
4634 if ( aScalarBar == NULL ) {
4635 aScalarBar = vtkScalarBarActor::New();
4636 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
4637 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
4638 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
4639 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
4640 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
4641 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
4642 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
4643 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
4644 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
4646 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily, Orientation,
4647 Width, Height, NumberOfColors, NumberOfLabels);
4648 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4649 theRenderer->AddActor2D(aScalarBar);
4651 aScalarBar->SetLookupTable( wat );
4652 aScalarBar->SetTitle( type.latin1() );
4656 DisplayScalarBar( true );
4658 QApplication::restoreOverrideCursor();
4662 //=============================================================================
4666 //=============================================================================
4667 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
4668 QString Bold, QString Italic,
4669 QString Shadow, QString FontFamily,
4670 QString Orientation, float Width, float Height,
4671 int NbColors, int NbLabels )
4673 if ( Bold.isNull() || Bold.isEmpty() || (Bold.compare( "true" ) == 0) )
4674 theScalarBar->BoldOn();
4676 theScalarBar->BoldOff();
4678 if ( Italic.isNull() || Italic.isEmpty() || (Italic.compare( "true" ) == 0) )
4679 theScalarBar->ItalicOn();
4681 theScalarBar->ItalicOff();
4683 if ( Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare( "true" ) == 0) )
4684 theScalarBar->ShadowOn();
4686 theScalarBar->ShadowOff();
4688 if ( FontFamily.compare( "Arial" ) == 0 )
4689 theScalarBar->SetFontFamilyToArial();
4690 else if ( FontFamily.compare( "Courier" ) == 0 )
4691 theScalarBar->SetFontFamilyToCourier();
4692 else if ( FontFamily.compare( "Times" ) == 0 )
4693 theScalarBar->SetFontFamilyToTimes();
4695 theScalarBar->SetFontFamilyToArial();
4697 if ( Orientation.isNull() || Orientation.isEmpty() || (Orientation.compare( "Vertical" ) == 0) )
4698 theScalarBar->SetOrientationToVertical();
4700 theScalarBar->SetOrientationToHorizontal();
4703 theScalarBar->SetWidth((Width == 0)? 0.17 : Width);
4704 theScalarBar->SetHeight((Height == 0)? 0.8 : Height);
4706 theScalarBar->SetNumberOfLabels((NbLabels == 0)? 5 : NbLabels);
4707 theScalarBar->SetMaximumNumberOfColors((NbColors == 0)? 64 : NbColors);
4711 //=============================================================================
4715 //=============================================================================
4716 void SMESHGUI::DisplayScalarBar(bool visibility)
4718 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4721 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4722 vtkScalarBarActor* aScalarBar = GetScalarBar();
4724 if ( aScalarBar == NULL ) {
4725 MESSAGE("myScalarBar is NULL");
4730 aScalarBar->VisibilityOn();
4732 aScalarBar->VisibilityOff();
4733 //Turn off mesh coloring (influences on all views)
4734 vtkActorCollection* actorList=theRenderer->GetActors();
4735 actorList->InitTraversal();
4736 vtkActor *ac = actorList->GetNextActor();
4738 if (ac->GetMapper() != NULL) {
4739 ac->GetMapper()->ScalarVisibilityOff();
4741 ac = actorList->GetNextActor();
4743 // Turn off ScalarBar in all views
4744 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
4745 for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
4746 if (aFrame->getTypeView() == VIEW_VTK) {
4747 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
4748 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
4749 actor2DList->InitTraversal();
4750 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
4751 while (aActor2d != NULL) {
4752 if (aActor2d->IsA("vtkScalarBarActor")) {
4753 aActor2d->VisibilityOff();
4756 actor2DList->GetNextActor2D();
4761 myActiveStudy->update3dViewers();
4765 //=============================================================================
4769 //=============================================================================
4770 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
4772 vtkScalarBarActor* aScalarBar = GetScalarBar();
4773 if ( aScalarBar == NULL ) {
4774 MESSAGE("myScalarBar is NULL");
4777 DisplayScalarBar(false);
4779 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
4780 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4781 vtkActorCollection* aActorList = aRenderer->GetActors();
4782 aActorList->InitTraversal();
4783 vtkActor *aActor = aActorList->GetNextActor();
4784 while(aActor != NULL) {
4785 if (aActor->IsA("SMESH_Actor")) {
4786 SMESH_Actor* aMeshActor = SMESH_Actor::SafeDownCast(aActor);
4787 vtkDataSetMapper* aMeshMapper = (vtkDataSetMapper*) (aMeshActor->getMapper());
4788 if ((aMeshMapper != NULL)) {
4789 aMeshMapper->SetScalarRange( MinRange, MaxRange );
4790 aMeshMapper->ScalarVisibilityOn();
4793 aActor = aActorList->GetNextActor();
4795 DisplayScalarBar(true);
4799 //=============================================================================
4803 //=============================================================================
4804 void SMESHGUI::SetDisplaySettings()
4806 EmitSignalDeactivateDialog() ;
4807 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "") ;
4809 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
4810 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
4811 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
4812 QColor color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4813 aDlg->SetColor(1,color);
4815 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
4816 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
4817 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4818 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4819 aDlg->SetColor(2,color);
4821 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4822 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4823 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4824 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4825 aDlg->SetColor(3,color);
4827 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4828 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4829 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4830 color = QColor (SBr.toInt(), SBg.toInt(), SBb.toInt());
4831 aDlg->SetColor(4,color);
4833 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4834 aDlg->SetIntValue(1,intValue.toInt());
4835 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4836 aDlg->SetIntValue(2,intValue.toInt());
4837 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4838 aDlg->SetIntValue(3,intValue.toInt());
4840 if ( aDlg->exec() ) {
4841 QColor colorFill = aDlg->GetColor( 1 );
4842 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4843 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4844 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4846 QColor colorOutline = aDlg->GetColor( 2 );
4847 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4848 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4849 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4851 QColor colorNode = aDlg->GetColor( 3 );
4852 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4853 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4854 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4856 QColor colorBackFace = aDlg->GetColor( 4 );
4857 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4858 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4859 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4861 int width = aDlg->GetIntValue( 1 );
4862 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4864 int nodes_size = aDlg->GetIntValue( 2 );
4865 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4867 int shrink_coeff = aDlg->GetIntValue( 3 );
4868 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4874 //=======================================================================
4875 // function : Parameter()
4876 // purpose : return a parameter (double) from a dialog box
4878 // aValue : is a double used as a default value displayed
4879 // aLabel : is the title for aValue1
4880 // aTitle : is the main title
4881 // bottom : maximum value to be entered
4882 // top : minimum value to be entered
4883 // decimals : number of decimals
4884 //=======================================================================
4885 double SMESHGUI::Parameter( Standard_Boolean& res,
4886 const double aValue,
4889 const double bottom,
4891 const int decimals )
4893 SMESHGUI_aParameterDlg* Dialog =
4894 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4897 bottom, top, decimals,
4899 Dialog->setValue( aValue );
4901 res = ( Dialog->exec() == QDialog::Accepted );
4903 X = Dialog->getDblValue();
4907 //=======================================================================
4908 // function : Parameter()
4909 // purpose : return a parameter (int) from a dialog box
4911 // aValue : is a int used as a default value displayed
4912 // aLabel : is the title for aValue1
4913 // aTitle : is the main title
4914 // bottom : maximum value to be entered
4915 // top : minimum value to be entered
4916 //=======================================================================
4917 int SMESHGUI::Parameter( Standard_Boolean& res,
4924 SMESHGUI_aParameterDlg* Dialog =
4925 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4930 Dialog->setValue( aValue );
4932 res = ( Dialog->exec() == QDialog::Accepted );
4934 X = Dialog->getIntValue();
4938 //=============================================================================
4942 //=============================================================================
4943 void SMESHGUI::DisplayEdges(SMESH_Actor* ac, bool visibility)
4945 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4947 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
4950 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4951 gf->SetInput(ac->DataSource);
4952 vtkFeatureEdges *edges = vtkFeatureEdges::New();
4953 edges->SetInput(gf->GetOutput());
4954 edges->BoundaryEdgesOn();
4955 edges->ManifoldEdgesOn();
4957 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
4958 edgeMapper->SetInput(edges->GetOutput());
4959 edgeMapper->ScalarVisibilityOff();
4961 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4962 vtkActorCollection* actorList=theRenderer->GetActors();
4964 int test=actorList->IsItemPresent(ac->EdgeDevice);
4966 vtkProperty* prop = vtkProperty::New();
4967 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
4968 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
4969 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
4970 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
4971 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
4972 ac->EdgeDevice->SetProperty(prop);
4973 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
4974 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
4975 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
4976 ac->EdgeDevice->SetMapper(edgeMapper);
4978 theRenderer->AddActor(ac->EdgeDevice);
4980 ac->EdgeDevice->SetMapper(edgeMapper);
4981 edgeMapper->Update();
4984 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
4985 shrink->SetInput(ac->DataSource);
4986 shrink->SetShrinkFactor(ac->GetShrinkFactor());
4987 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
4988 Shrinkgf->SetInput( shrink->GetOutput() );
4989 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
4990 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
4991 ShrinkEdges->BoundaryEdgesOn();
4992 ShrinkEdges->ManifoldEdgesOn();
4994 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
4995 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
4996 ShrinkEdgeMapper->ScalarVisibilityOff();
4998 test=actorList->IsItemPresent(ac->EdgeShrinkDevice);
5000 vtkProperty* prop = vtkProperty::New();
5001 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5002 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5003 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5004 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5005 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5006 ac->EdgeShrinkDevice->SetProperty(prop);
5007 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5008 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5009 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5010 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5012 theRenderer->AddActor(ac->EdgeShrinkDevice);
5014 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5015 ShrinkEdgeMapper->Update();
5018 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5023 //=============================================================================
5027 //=============================================================================
5028 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5030 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh( aMesh );
5031 SALOMEDS::GenericAttribute_var anAttr;
5032 SALOMEDS::AttributeName_var aName;
5033 if ( !aSO_M->_is_nil() ) {
5034 if (aSO_M->FindAttribute(anAttr, "AttributeName") ) {
5035 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5036 Standard_Boolean result;
5037 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5039 SMESH_Actor* amesh = SMESH_Actor::New();
5040 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(aSO_M->GetID(),
5044 amesh->setName( aName->Value() );
5045 DisplayActor(amesh, false);
5052 //=============================================================================
5056 //=============================================================================
5057 void SMESHGUI::Update()
5059 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
5060 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5062 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5063 int nbSel = Sel->IObjectCount();
5065 vtkActorCollection* actorList=theRenderer->GetActors();
5066 actorList->InitTraversal();
5067 vtkActor *ac = actorList->GetNextActor();
5068 while(!(ac==NULL)) {
5069 if ( ac->IsA("SMESH_Actor") ) {
5070 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5071 if ( anActor->hasIO() ) {
5072 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5076 ac = actorList->GetNextActor();
5079 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5080 for ( ; It.More(); It.Next() ) {
5081 Handle(SALOME_InteractiveObject) IO = It.Value();
5085 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5088 QApplication::restoreOverrideCursor();
5092 //=============================================================================
5096 //=============================================================================
5097 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject)& IO)
5099 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5102 if ( IO->hasEntry() ) {
5103 Standard_Boolean res;
5104 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh( IO, res );
5106 SMESH_Actor* ac = FindActorByEntry( IO->getEntry(), res, false );
5108 // Check whether the actor belongs to the active view
5109 VTKViewer_RenderWindowInteractor* rwInter =
5110 ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5112 // The actor belongs to inactive view -> create a copy and display it in the active view
5113 if (!rwInter->isInViewer(IO)) {
5114 SMESH_Actor* acCopy = SMESH_Actor::New();
5115 acCopy->ShallowCopy(ac);
5117 smeshGUI->DisplayActor( acCopy, false );
5119 ac = ReadScript( aMesh );
5126 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
5134 //=============================================================================
5138 //=============================================================================
5139 vtkActor* SMESHGUI::SimulationMoveNode(SMESH_Actor* Mactor, int idnode)
5141 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5144 mySimulationActors = vtkActorCollection::New();
5145 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5147 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5148 vtkIdList *IdCells = vtkIdList::New();
5149 ugrid->GetPointCells( idnode, IdCells );
5151 vtkPoints *Pts = vtkPoints::New();
5152 Pts = ugrid->GetPoints();
5154 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
5155 ugridSimulation->SetPoints( Pts );
5156 vtkIdList *IdPts = vtkIdList::New();
5157 for (int j=0; j<IdCells->GetNumberOfIds(); j++) {
5158 ugrid->GetCellPoints( IdCells->GetId(j), IdPts );
5159 ugridSimulation->InsertNextCell( ugrid->GetCellType( IdCells->GetId(j) ), IdPts );
5162 vtkProperty* prop = vtkProperty::New();
5163 prop->SetColor( 1., 0., 0. );
5164 prop->SetRepresentationToWireframe();
5166 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
5167 if ( Edgewidth == 0 )
5169 prop->SetLineWidth( Edgewidth+1 );
5171 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5172 Mapper->SetInput( ugridSimulation );
5173 vtkActor* ac = vtkActor::New();
5174 ac->SetMapper( Mapper );
5175 ac->SetProperty( prop );
5177 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
5178 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
5180 mySimulationActors->AddItem( ac );
5181 theRenderer->AddActor( ac );
5183 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5190 //=============================================================================
5194 //=============================================================================
5195 void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5197 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5200 EraseSimulationActors();
5201 mySimulationActors = vtkActorCollection::New();
5202 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5203 Standard_Boolean result;
5204 SMESH_Actor* ac = FindActor( aMesh, result, true );
5207 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5208 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5210 vtkPoints *Pts = ugrid->GetPoints();
5211 vtkPoints *newPts = vtkPoints::New();
5212 int nbPts = Pts->GetNumberOfPoints();
5213 for ( int i = 0; i < nbPts; i++ ) {
5214 newPts->InsertPoint(i, Pts->GetPoint(i) );
5217 newugrid->SetPoints(newPts);
5218 newugrid->GetPoints()->InsertNextPoint( x, y, z );
5220 vtkMaskPoints* verts = vtkMaskPoints::New();
5221 verts->SetInput(newugrid);
5222 verts->SetGenerateVertices(1);
5223 verts->SetOnRatio(1);
5225 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
5226 vertMapper->SetInput( verts->GetOutput() );
5227 vertMapper->ScalarVisibilityOff();
5229 vtkActor* node = vtkActor::New();
5230 node->SetMapper( vertMapper );
5232 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5233 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5234 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5235 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5236 if ( !nodecolor.isValid() )
5237 nodecolor = QColor(0.,1.,0.);
5239 node->GetProperty()->SetColor( float(nodecolor.red())/255.,
5240 float(nodecolor.green())/255.,
5241 float(nodecolor.blue())/255.);
5243 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
5247 node->GetProperty()->SetPointSize( intValue );
5249 node->VisibilityOn();
5251 mySimulationActors->AddItem( node );
5252 theRenderer->AddActor(node);
5255 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5259 //=============================================================================
5263 //=============================================================================
5264 void SMESHGUI::DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z)
5266 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5269 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5270 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
5271 pt[0] = x; pt[1] = y; pt[2] = z;
5273 ac->GetMapper()->ImmediateModeRenderingOn();
5274 ac->GetProperty()->SetRepresentationToWireframe();
5276 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5282 //=============================================================================
5286 //=============================================================================
5287 void SMESHGUI::MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z)
5289 Standard_Boolean result;
5291 SMESH_Actor* MeshActor = FindActor(aMesh, result, true);
5297 //=============================================================================
5301 //=============================================================================
5302 void SMESHGUI::ScalarVisibilityOff()
5304 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5307 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5308 vtkActorCollection* actorList=theRenderer->GetActors();
5310 actorList->InitTraversal();
5311 vtkActor *ac = actorList->GetNextActor();
5312 while(!(ac==NULL)) {
5313 if ( ac->IsA("SMESH_Actor") ) {
5314 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5315 if ( anActor->GetVisibility() == 1 ) {
5316 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (anActor->getMapper());
5317 meshMapper->ScalarVisibilityOff();
5318 meshMapper->SetInput( anActor->DataSource );
5319 ChangeRepresentation( anActor, anActor->getDisplayMode() );
5322 ac = actorList->GetNextActor();
5325 theRenderer->Render();
5329 //=============================================================================
5333 //=============================================================================
5334 void SMESHGUI::DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5336 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5339 EraseSimulationActors();
5340 mySimulationActors = vtkActorCollection::New();
5341 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5342 Standard_Boolean result;
5343 SMESH_Actor* ac = FindActor( aMesh, result, true );
5345 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5349 vtkIdList *Ids = vtkIdList::New();
5350 for ( ; ite.More(); ite.Next() ) {
5351 idNodes[i] = ite.Key();
5355 Ids->InsertId( 0, idNodes[0] );
5356 pts[0] = idNodes[0];
5357 Ids->InsertId( 1, idNodes[1] );
5358 pts[1] = idNodes[1];
5360 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5361 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5362 newugrid->SetPoints( ugrid->GetPoints() ) ;
5363 newugrid->InsertNextCell(VTK_LINE, 2, pts);
5365 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5366 Mapper->SetInput( newugrid );
5369 vtkActor* edge = vtkActor::New();
5370 edge->SetMapper( Mapper );
5371 edge->SetProperty( ac->GetProperty() );
5372 edge->SetBackfaceProperty( ac->GetBackfaceProperty() );
5373 edge->VisibilityOn();
5374 mySimulationActors->AddItem( edge );
5375 theRenderer->AddActor(edge);
5378 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5383 //=============================================================================
5387 //=============================================================================
5388 void SMESHGUI::DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5390 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5393 EraseSimulationActors();
5394 mySimulationActors = vtkActorCollection::New();
5395 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5396 Standard_Boolean result;
5397 SMESH_Actor* ac = FindActor( aMesh, result, true );
5399 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5403 vtkIdList *Ids = vtkIdList::New();
5404 for ( ; ite.More(); ite.Next() ) {
5405 idNodes[i] = ite.Key();
5410 Ids->InsertId( 0, idNodes[2] );
5411 pts[0] = idNodes[2];
5412 Ids->InsertId( 1, idNodes[1] );
5413 pts[1] = idNodes[1];
5414 Ids->InsertId( 2, idNodes[0] );
5415 pts[2] = idNodes[0];
5417 Ids->InsertId( 0, idNodes[0] );
5418 pts[0] = idNodes[0];
5419 Ids->InsertId( 1, idNodes[1] );
5420 pts[1] = idNodes[1];
5421 Ids->InsertId( 2, idNodes[2] );
5422 pts[2] = idNodes[2];
5424 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5425 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5426 newugrid->SetPoints( ugrid->GetPoints() ) ;
5427 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
5429 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5430 Mapper->SetInput( newugrid );
5433 vtkActor* tri = vtkActor::New();
5434 tri->SetMapper( Mapper );
5435 tri->SetProperty( ac->GetProperty() );
5436 tri->SetBackfaceProperty( ac->GetBackfaceProperty() );
5437 tri->VisibilityOn();
5438 mySimulationActors->AddItem( tri );
5439 theRenderer->AddActor(tri);
5442 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5447 //=============================================================================
5451 //=============================================================================
5452 void SMESHGUI::DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5454 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5457 EraseSimulationActors();
5458 mySimulationActors = vtkActorCollection::New();
5459 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5460 Standard_Boolean result;
5461 SMESH_Actor* ac = FindActor( aMesh, result, true );
5463 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5466 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5469 vtkIdList *Ids = vtkIdList::New();
5470 for ( ; ite.More(); ite.Next() ) {
5471 idNodes[i] = ite.Key();
5475 float *p0 = ugrid->GetPoint(idNodes[0]);
5476 float *p1 = ugrid->GetPoint(idNodes[1]);
5477 float *p2 = ugrid->GetPoint(idNodes[2]);
5478 float *p3 = ugrid->GetPoint(idNodes[3]);
5480 gp_Pnt P0(p0[0],p0[1],p0[2]);
5482 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5483 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5484 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5486 gp_Vec Cross1 = V1 ^ V2;
5487 gp_Vec Cross2 = V2 ^ V3;
5490 if ( Cross1.Dot(Cross2) < 0 ) {
5491 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5492 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5496 if ( Cross1.Dot(Cross2) < 0 ) {
5498 idNodes[2] = idNodes[3];
5502 idNodes[1] = idNodes[2];
5508 Ids->InsertId( 0, idNodes[3] );
5509 Ids->InsertId( 1, idNodes[2] );
5510 Ids->InsertId( 2, idNodes[1] );
5511 Ids->InsertId( 3, idNodes[0] );
5513 Ids->InsertId( 0, idNodes[0] );
5514 Ids->InsertId( 1, idNodes[1] );
5515 Ids->InsertId( 2, idNodes[2] );
5516 Ids->InsertId( 3, idNodes[3] );
5519 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5520 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5521 newugrid->SetPoints( ugrid->GetPoints() ) ;
5522 newugrid->InsertNextCell(VTK_QUAD, Ids);
5524 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5525 Mapper->SetInput( newugrid );
5528 vtkActor* quad = vtkActor::New();
5529 quad->SetMapper( Mapper );
5530 quad->SetProperty( ac->GetProperty() );
5531 quad->SetBackfaceProperty( ac->GetBackfaceProperty() );
5532 quad->VisibilityOn();
5533 mySimulationActors->AddItem( quad );
5534 theRenderer->AddActor(quad);
5536 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5541 //=============================================================================
5545 //=============================================================================
5546 void SMESHGUI::DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5548 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5551 EraseSimulationActors();
5552 mySimulationActors = vtkActorCollection::New();
5553 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5554 Standard_Boolean result;
5555 SMESH_Actor* ac = FindActor( aMesh, result, true );
5557 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5560 vtkIdList *Ids = vtkIdList::New();
5561 for ( ; ite.More(); ite.Next() ) {
5562 idNodes[i] = ite.Key();
5566 Ids->InsertId( 0, idNodes[0] );
5567 Ids->InsertId( 1, idNodes[1] );
5568 Ids->InsertId( 2, idNodes[2] );
5569 Ids->InsertId( 3, idNodes[3] );
5571 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5572 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5573 newugrid->SetPoints( ugrid->GetPoints() ) ;
5574 newugrid->InsertNextCell(VTK_TETRA, Ids);
5576 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5577 Mapper->SetInput( newugrid );
5580 vtkActor* tetra = vtkActor::New();
5581 tetra->SetMapper( Mapper );
5582 tetra->SetProperty( ac->GetProperty() );
5583 tetra->SetBackfaceProperty( ac->GetBackfaceProperty() );
5584 tetra->VisibilityOn();
5585 mySimulationActors->AddItem( tetra );
5586 theRenderer->AddActor(tetra);
5588 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5593 //=============================================================================
5597 //=============================================================================
5598 void SMESHGUI::DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5600 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5603 EraseSimulationActors();
5604 mySimulationActors = vtkActorCollection::New();
5605 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5606 Standard_Boolean result;
5607 SMESH_Actor* ac = FindActor( aMesh, result, true );
5609 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5612 vtkIdList *Ids = vtkIdList::New();
5613 for ( ; ite.More(); ite.Next() ) {
5614 idNodes[i] = ite.Key();
5618 Ids->InsertId( 0, idNodes[0] );
5619 Ids->InsertId( 1, idNodes[1] );
5620 Ids->InsertId( 2, idNodes[2] );
5621 Ids->InsertId( 3, idNodes[3] );
5622 Ids->InsertId( 4, idNodes[4] );
5623 Ids->InsertId( 5, idNodes[5] );
5624 Ids->InsertId( 6, idNodes[6] );
5625 Ids->InsertId( 7, idNodes[7] );
5627 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5628 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5629 newugrid->SetPoints( ugrid->GetPoints() ) ;
5630 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5632 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5633 Mapper->SetInput( newugrid );
5636 vtkActor* hexa = vtkActor::New();
5637 hexa->SetMapper( Mapper );
5638 hexa->SetProperty( ac->GetProperty() );
5639 hexa->SetBackfaceProperty( ac->GetBackfaceProperty() );
5640 hexa->VisibilityOn();
5641 mySimulationActors->AddItem( hexa );
5642 theRenderer->AddActor(hexa);
5644 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5649 //=============================================================================
5653 //=============================================================================
5654 void SMESHGUI::AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5656 QApplication::setOverrideCursor( Qt::waitCursor );
5657 Standard_Boolean result;
5658 SMESH_Actor* ac = FindActor( aMesh, result, true );
5660 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5661 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5662 anArrayOfIdeces->length(MapIndex.Extent());
5665 for ( ; ite.More(); ite.Next() ) {
5666 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5671 if ( MapIndex.Extent() == 4 ) {
5674 TColStd_MapIteratorOfMapOfInteger ite1( MapIndex );
5675 for ( ; ite1.More(); ite1.Next() ) {
5676 idNodes[i] = ite1.Key();
5680 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5681 float *p0 = ugrid->GetPoint(idNodes[0]);
5682 float *p1 = ugrid->GetPoint(idNodes[1]);
5683 float *p2 = ugrid->GetPoint(idNodes[2]);
5684 float *p3 = ugrid->GetPoint(idNodes[3]);
5686 gp_Pnt P0(p0[0],p0[1],p0[2]);
5688 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5689 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5690 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5692 gp_Vec Cross1 = V1 ^ V2;
5693 gp_Vec Cross2 = V2 ^ V3;
5695 if ( Cross1.Dot(Cross2) < 0 ) {
5697 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5698 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5702 if ( Cross1.Dot(Cross2) < 0 ) {
5703 tmp = anArrayOfIdeces[2];
5704 anArrayOfIdeces[2] = anArrayOfIdeces[3];
5705 anArrayOfIdeces[3] = tmp;
5707 tmp = anArrayOfIdeces[1];
5708 anArrayOfIdeces[1] = anArrayOfIdeces[2];
5709 anArrayOfIdeces[2] = tmp;
5716 for (i=0; i < (MapIndex.Extent()/2); i++) {
5717 tmp = anArrayOfIdeces[i];
5718 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent()-i-1];
5719 anArrayOfIdeces[MapIndex.Extent()-i-1] = tmp;
5722 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5723 aMeshEditor->AddFace(anArrayOfIdeces);
5725 if ( myAutomaticUpdate ) {
5726 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5727 if ( Mesh != NULL ) {
5728 smeshGUI->DisplayActor( Mesh );
5729 smeshGUI->DisplayEdges( Mesh );
5730 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5731 AddActorInSelection( Mesh );
5734 QApplication::restoreOverrideCursor();
5738 //=============================================================================
5742 //=============================================================================
5743 void SMESHGUI::AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5745 QApplication::setOverrideCursor( Qt::waitCursor );
5746 Standard_Boolean result;
5747 SMESH_Actor* ac = FindActor( aMesh, result, true );
5749 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5750 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5751 anArrayOfIdeces->length(MapIndex.Extent());
5754 for ( ; ite.More(); ite.Next() ) {
5755 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5759 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5760 aMeshEditor->AddVolume(anArrayOfIdeces);
5762 if ( myAutomaticUpdate ) {
5763 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5764 if ( Mesh != NULL ) {
5765 smeshGUI->DisplayActor( Mesh );
5766 smeshGUI->DisplayEdges( Mesh );
5767 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5768 AddActorInSelection( Mesh );
5771 QApplication::restoreOverrideCursor();
5775 //=============================================================================
5779 //=============================================================================
5780 void SMESHGUI::AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5782 QApplication::setOverrideCursor( Qt::waitCursor );
5783 Standard_Boolean result;
5784 SMESH_Actor* ac = FindActor( aMesh, result, true );
5786 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5787 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5788 anArrayOfIdeces->length(MapIndex.Extent());
5791 for ( ; ite.More(); ite.Next() ) {
5792 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5796 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5797 aMeshEditor->AddEdge(anArrayOfIdeces);
5799 if ( myAutomaticUpdate ) {
5800 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5801 if ( Mesh != NULL ) {
5802 smeshGUI->DisplayActor( Mesh );
5803 smeshGUI->DisplayEdges( Mesh );
5804 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5805 AddActorInSelection( Mesh );
5808 QApplication::restoreOverrideCursor();
5811 //=============================================================================
5815 //=============================================================================
5816 void SMESHGUI::AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5818 QApplication::setOverrideCursor( Qt::waitCursor );
5819 Standard_Boolean result;
5820 SMESH_Actor* ac = FindActor( aMesh, result, true );
5822 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5823 aMeshEditor->AddNode(x,y,z);
5825 if ( myAutomaticUpdate ) {
5826 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5827 if ( Mesh != NULL ) {
5828 smeshGUI->DisplayActor( Mesh );
5829 smeshGUI->DisplayEdges( Mesh );
5830 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5831 AddActorInSelection( Mesh );
5835 QApplication::restoreOverrideCursor();
5838 //=============================================================================
5842 //=============================================================================
5843 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor *ac)
5845 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5848 EraseSimulationActors();
5849 mySimulationActors2D = vtkActor2DCollection::New();
5851 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5853 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
5854 gs2->SetGlyphTypeToTriangle();
5857 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
5858 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
5859 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
5861 legend->SetNumberOfEntries(4);
5862 legend->SetEntryString( 0, tr( "SMESH_BOUNDARYEDGES" ) );
5863 legend->SetEntrySymbol( 0, gs2->GetOutput() );
5864 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.) );
5865 legend->SetEntryString( 1, tr( "SMESH_MANIFOLDEDGES" ) );
5866 legend->SetEntrySymbol( 1, gs2->GetOutput() );
5867 legend->SetEntryColor(1, ac->GetMapper()->GetLookupTable()->GetColor(0.666667) );
5868 legend->SetEntryString( 2, tr( "SMESH_NONMANIFOLDEDGES" ) );
5869 legend->SetEntrySymbol( 2, gs2->GetOutput() );
5870 legend->SetEntryColor(2, ac->GetMapper()->GetLookupTable()->GetColor(0.222222) );
5871 legend->SetEntryString( 3, tr( "SMESH_FEATUREEDGES" ) );
5872 legend->SetEntrySymbol( 3, gs2->GetOutput() );
5873 legend->SetEntryColor(3, ac->GetMapper()->GetLookupTable()->GetColor(0.444444) );
5874 legend->SetPadding( 5 );
5875 // legend->GetProperty()->SetColor();
5877 mySimulationActors2D->AddItem( legend );
5878 theRenderer->AddActor2D( legend );
5881 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5884 //===============================================================================
5885 // function : OnEditDelete()
5887 //===============================================================================
5888 void SMESHGUI::OnEditDelete()
5890 if ( QAD_MessageBox::warn2
5891 ( QAD_Application::getDesktop(),
5892 tr ("SMESH_WRN_WARNING"),
5893 tr ("SMESH_REALLY_DELETE"),
5894 tr ("SMESH_BUT_YES"), tr ("SMESH_BUT_NO"), 1, 0, 0 ) != 1 )
5897 int nbSf = myActiveStudy->getStudyFramesCount();
5899 Standard_Boolean found;
5900 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5901 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
5902 SALOMEDS::GenericAttribute_var anAttr;
5903 SALOMEDS::AttributeIOR_var anIOR;
5905 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5906 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5907 for(;It.More();It.Next()) {
5908 Handle(SALOME_InteractiveObject) IObject = It.Value();
5909 if ( IObject->hasEntry() ) {
5910 SALOMEDS::SObject_var SO = myStudy->FindObjectID( IObject->getEntry() );
5912 /* Erase child graphical objects */
5913 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5914 for (; it->More();it->Next()) {
5915 SALOMEDS::SObject_var CSO= it->Value();
5916 if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
5917 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5919 for ( int i = 0; i < nbSf; i++ ) {
5920 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5921 if ( sf->getTypeView() == VIEW_VTK ) {
5922 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5923 SMESH_Actor* ac = smeshGUI->FindActorByEntry( CSO->GetID(), found, false );
5925 Renderer->RemoveActor(ac->EdgeDevice);
5926 Renderer->RemoveActor(ac->EdgeShrinkDevice);
5927 Renderer->RemoveActor(ac);
5934 /* Erase main graphical object */
5935 for ( int i = 0; i < nbSf; i++ ) {
5936 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5937 if ( sf->getTypeView() == VIEW_VTK ) {
5938 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5939 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
5940 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), found, false );
5942 Renderer->RemoveActor(ac->EdgeDevice);
5943 Renderer->RemoveActor(ac->EdgeShrinkDevice);
5945 myRenderInter->Remove( IObject );
5949 /* Erase objects in Study */
5950 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
5951 if ( !obj->_is_nil() ) {
5952 QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
5954 aStudyBuilder->RemoveObject(obj);
5958 } /* IObject->hasEntry() */
5961 /* Clear any previous selection */
5962 Sel->ClearIObjects() ;
5963 myActiveStudy->updateObjBrowser();