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>
135 // Open CASCADE Includes
136 #include <gp_Pnt.hxx>
137 #include <gp_Vec.hxx>
139 static GEOM_Client ShapeReader;
140 static SMESHGUI* smeshGUI = 0;
141 static CORBA::ORB_var _orb;
144 //=============================================================================
148 //=============================================================================
149 class CustomItem : public QCustomMenuItem
152 CustomItem( const QString& s, const QFont& f )
153 : string( s ), font( f ){};
156 void paint( QPainter* p, const QColorGroup& /*cg*/, bool /*act*/, bool /*enabled*/, int x, int y, int w, int h )
159 p->drawText( x, y, w, h, AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
164 return QFontMetrics( font ).size( AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string );
171 //=============================================================================
175 //=============================================================================
176 SMESHGUI::SMESHGUI() :
181 //=============================================================================
185 //=============================================================================
186 SMESHGUI::~SMESHGUI()
191 //=============================================================================
195 //=============================================================================
196 SMESHGUI* SMESHGUI::GetSMESHGUI( )
201 //=============================================================================
205 //=============================================================================
206 SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
208 if( smeshGUI == 0 ) {
210 smeshGUI = new SMESHGUI;
211 smeshGUI->myActiveDialogBox = 0 ;
212 smeshGUI->myState = -1 ;
213 smeshGUI->myDesktop = desktop ;
214 smeshGUI->myActiveStudy = desktop->getActiveStudy();
216 Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
217 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
219 Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");
220 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
222 /* GetCurrentStudy */
223 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
225 smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
226 // smeshGUI->myComponentGeom->NbLabels();
228 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
230 smeshGUI->myStudyAPI = SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
232 smeshGUI->myDocument = new SMESHDS_Document(1);//NBU
234 smeshGUI->mySimulationActors = vtkActorCollection::New();
235 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
237 /* study may have changed */
238 smeshGUI->myActiveStudy = desktop->getActiveStudy();
239 smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
242 /* Automatic Update */
243 if ( desktop->menuBar()->isItemChecked(1001) )
244 smeshGUI->myAutomaticUpdate = true;
246 smeshGUI->myAutomaticUpdate = false;
251 //=============================================================================
255 //=============================================================================
256 void SMESHGUI::SetState(int aState )
257 { this->myState = aState ; return ; }
260 //=============================================================================
264 //=============================================================================
265 void SMESHGUI::ResetState()
266 { this->myState = -1 ; return ; }
269 //=============================================================================
273 //=============================================================================
274 void SMESHGUI::EmitSignalDeactivateDialog()
276 emit this->SignalDeactivateActiveDialog() ;
280 //=============================================================================
284 //=============================================================================
285 void SMESHGUI::EmitSignalCloseAllDialogs()
287 emit this->SignalCloseAllDialogs() ;
292 //=============================================================================
296 //=============================================================================
297 QDialog* SMESHGUI::GetActiveDialogBox()
299 return this->myActiveDialogBox ;
302 //=============================================================================
306 //=============================================================================
307 void SMESHGUI::SetActiveDialogBox(QDialog* aDlg)
309 this->myActiveDialogBox = (QDialog*)aDlg ;
314 //=============================================================================
318 //=============================================================================
319 QAD_Study* SMESHGUI::GetActiveStudy()
321 return this->myActiveStudy ;
325 //=============================================================================
329 //=============================================================================
330 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
332 return SALOMEDS::Study::_narrow( myStudy );
335 //=============================================================================
339 //=============================================================================
340 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
345 //=============================================================================
349 //=============================================================================
350 QAD_Desktop* SMESHGUI::GetDesktop()
352 return this->myDesktop ;
355 //=============================================================================
359 //=============================================================================
360 vtkScalarBarActor* SMESHGUI::GetScalarBar()
362 vtkRenderer* aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
363 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
364 actor2DList->InitTraversal();
365 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
366 while (aActor2d != NULL) {
367 if (aActor2d->IsA("vtkScalarBarActor"))
368 return vtkScalarBarActor::SafeDownCast(aActor2d);
369 actor2DList->GetNextActor2D();
374 //=============================================================================
378 //=============================================================================
379 void SMESHGUI::activeStudyChanged( QAD_Desktop* parent )
381 MESSAGE ("SMESHGUI::activeStudyChanged init.")
382 /* Create or retrieve an object SMESHGUI */
383 SMESHGUI::GetOrCreateSMESHGUI(parent);
385 smeshGUI->EmitSignalCloseAllDialogs() ;
386 MESSAGE( "Active study changed : SMESHGUI nullified" << endl ) ;
390 //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
391 MESSAGE ("SMESHGUI::activeStudyChanged done.")
395 //=============================================================================
399 //=============================================================================
400 bool SMESHGUI::DefineDlgPosition(QWidget* aDlg, int& x, int& y)
402 /* Here the position is on the bottom right corner - 10 */
403 aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
404 QAD_Desktop* PP = QAD_Application::getDesktop() ;
405 x = abs ( PP->x() + PP->size().width() - aDlg->size().width() - 10 ) ;
406 y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ;
411 //=============================================================================
415 //=============================================================================
416 void SMESHGUI::EraseSimulationActors()
418 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
419 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
420 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
422 if ( mySimulationActors != NULL ) {
424 mySimulationActors->InitTraversal();
425 vtkActor *ac = mySimulationActors->GetNextActor();
427 theRenderer->RemoveActor(ac);
428 ac = mySimulationActors->GetNextActor();
430 mySimulationActors->RemoveAllItems();
432 if ( mySimulationActors2D != NULL ) {
433 mySimulationActors2D->InitTraversal();
434 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
436 theRenderer->RemoveActor2D(ac);
437 ac = mySimulationActors2D->GetNextActor2D();
439 mySimulationActors2D->RemoveAllItems();
445 //=============================================================================
449 //=============================================================================
450 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
453 if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
454 SMESH::SMESH_Mesh_var aMesh = myComponentMesh->Init( myComponentGeom, myStudyId, aShape);
456 if ( !aMesh->_is_nil() ) {
457 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh ( aMesh );
458 myStudyAPI.SetName( SM, NameMesh );
460 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
461 // not after loading from file, so let's use more reliable way to retrieve SObject
462 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
463 SALOMEDS::SObject_var SObject = myStudy->FindObjectIOR(ShapeIOR);
464 if ( !SObject->_is_nil() && !SM->_is_nil() ) {
465 myStudyAPI.SetShape( SM, SObject );
467 return SMESH::SMESH_Mesh::_narrow(aMesh);
471 catch (const SALOME::SALOME_Exception& S_ex) {
472 QtCatchCorbaException(S_ex);
474 myActiveStudy->updateObjBrowser(true);
475 return SMESH::SMESH_Mesh::_nil();
478 //=============================================================================
482 //=============================================================================
483 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh, GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
486 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
487 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
488 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
489 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
491 if ( !SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() && !aSubMesh->_is_nil() && !aMesh->_is_nil() ) {
492 SALOMEDS::SObject_var SO = myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh, aShape->ShapeType() );
493 myStudyAPI.SetName(SO, NameMesh);
495 SMESH_Actor* amesh = SMESH_Actor::New();
496 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(SO->GetID(),
500 amesh->setName( strdup(NameMesh) );
501 DisplayActor(amesh, false);
502 return SMESH::SMESH_subMesh::_narrow( aSubMesh );
505 catch (const SALOME::SALOME_Exception& S_ex) {
506 QtCatchCorbaException(S_ex);
508 myActiveStudy->updateObjBrowser(true);
509 return SMESH::SMESH_subMesh::_nil();
513 //=============================================================================
517 //=============================================================================
518 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis( QString TypeHypothesis,
519 QString NameHypothesis )
521 SMESH::SMESH_Hypothesis_var Hyp;
523 Hyp = myComponentMesh->CreateHypothesis( TypeHypothesis, myStudyId );
524 if ( !Hyp->_is_nil() ) {
525 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis( Hyp );
526 myStudyAPI.SetName( SHyp, NameHypothesis);
529 catch (const SALOME::SALOME_Exception& S_ex) {
530 QtCatchCorbaException(S_ex);
533 return SMESH::SMESH_Hypothesis::_narrow( Hyp );
536 //=============================================================================
540 //=============================================================================
541 void SMESHGUI::AddHypothesisOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
543 if ( !aMesh->_is_nil() ) {
544 QApplication::setOverrideCursor( Qt::waitCursor );
545 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
546 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
548 bool res = aMesh->AddHypothesis( aShape, aHyp );
550 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
551 if ( !SM->_is_nil() && !SH->_is_nil() ) {
552 myStudyAPI.SetHypothesis( SM, SH );
553 myStudyAPI.ModifiedMesh( SM, false );
555 QApplication::restoreOverrideCursor();
557 QApplication::restoreOverrideCursor();
558 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
559 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
562 catch (const SALOME::SALOME_Exception& S_ex) {
563 QtCatchCorbaException(S_ex);
566 myActiveStudy->updateObjBrowser(true);
567 QApplication::restoreOverrideCursor();
570 //=============================================================================
574 //=============================================================================
575 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( const Handle(SALOME_InteractiveObject)& IObject )
577 if ( IObject->hasReference() ) {
578 SMESH::SMESH_Hypothesis_var anHyp;
579 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getEntry() );
580 SALOMEDS::GenericAttribute_var anAttr;
581 SALOMEDS::AttributeIOR_var anIOR;
583 if ( !SO_Hypothesis->_is_nil() ) {
584 QApplication::setOverrideCursor( Qt::waitCursor );
585 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
586 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
587 anHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()) );
590 SALOMEDS::SObject_var SO_Applied_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getReference());
591 if ( !SO_Applied_Hypothesis->_is_nil() ) {
592 SALOMEDS::SObject_var MorSM = smeshGUI->myStudyAPI.GetMeshOrSubmesh( SO_Applied_Hypothesis );
593 if ( !MorSM->_is_nil() ) {
594 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
596 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
597 if ( !aShape->_is_nil() ) {
598 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
599 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
600 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
601 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
602 if ( !aMesh->_is_nil() ) {
603 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
605 QApplication::restoreOverrideCursor();
606 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
607 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
609 } else if ( !aSubMesh->_is_nil() ) {
610 aMesh = aSubMesh->GetFather();
611 if ( !aMesh->_is_nil() ) {
612 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
614 QApplication::restoreOverrideCursor();
615 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
616 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
620 if ( myAutomaticUpdate ) {
621 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
622 if ( Mesh != NULL ) {
626 DisplayActor( Mesh );
627 DisplayEdges( Mesh );
628 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
634 smeshGUI->myStudyAPI.UnSetHypothesis( SO_Applied_Hypothesis );
637 } else if ( IObject->hasEntry() ) {
638 MESSAGE ( "IObject entry " << IObject->getEntry() )
640 QApplication::restoreOverrideCursor();
643 //=============================================================================
647 //=============================================================================
648 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( SALOMEDS::SObject_ptr MorSM, SMESH::SMESH_Hypothesis_ptr anHyp )
650 SALOMEDS::SObject_var AHR, aRef;
651 SALOMEDS::GenericAttribute_var anAttr;
652 SALOMEDS::AttributeIOR_var anIOR;
654 if ( !MorSM->_is_nil() ) {
655 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
656 if ( !aShape->_is_nil() ) {
657 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
658 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
659 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
660 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
661 if ( !aMesh->_is_nil() ) {
662 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
664 QApplication::restoreOverrideCursor();
665 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
666 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
668 } else if ( !aSubMesh->_is_nil() ) {
669 aMesh = aSubMesh->GetFather();
670 if ( !aMesh->_is_nil() ) {
671 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
673 QApplication::restoreOverrideCursor();
674 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
675 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
679 if ( myAutomaticUpdate ) {
680 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
681 if ( Mesh != NULL ) {
685 DisplayActor( Mesh );
686 DisplayEdges( Mesh );
687 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
693 if ( MorSM->FindSubObject (2, AHR)) {
694 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
695 for (; it->More();it->Next()) {
696 SALOMEDS::SObject_var Obj = it->Value();
697 if ( Obj->ReferencedObject(aRef) ) {
698 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
699 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
700 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
701 smeshGUI->myStudyAPI.UnSetHypothesis( Obj );
708 if ( MorSM->FindSubObject (3, AHR)) {
709 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
710 for (; it->More();it->Next()) {
711 SALOMEDS::SObject_var Obj = it->Value();
712 if ( Obj->ReferencedObject(aRef) ) {
713 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
714 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
715 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
716 smeshGUI->myStudyAPI.UnSetAlgorithm( Obj );
723 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
725 QApplication::restoreOverrideCursor();
728 //=============================================================================
732 //=============================================================================
733 void SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
735 if ( !aMesh->_is_nil() ) {
736 QApplication::setOverrideCursor( Qt::waitCursor );
737 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
738 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
740 bool res = aMesh->AddHypothesis( aShape, aHyp );
742 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
743 if ( !SM->_is_nil() && !SH->_is_nil() ) {
744 myStudyAPI.SetAlgorithms( SM, SH );
745 myStudyAPI.ModifiedMesh( SM, false );
748 QApplication::restoreOverrideCursor();
749 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
750 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
753 catch (const SALOME::SALOME_Exception& S_ex) {
754 QtCatchCorbaException(S_ex);
757 myActiveStudy->updateObjBrowser(true);
758 QApplication::restoreOverrideCursor();
761 //=============================================================================
765 //=============================================================================
766 void SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
768 if ( !aSubMesh->_is_nil() ) {
769 QApplication::setOverrideCursor( Qt::waitCursor );
771 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
772 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
773 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
774 if ( !aMesh->_is_nil() ) {
775 bool res = aMesh->AddHypothesis( aShape, aHyp );
777 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
778 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
779 myStudyAPI.SetHypothesis( SsubM, SH );
780 myStudyAPI.ModifiedMesh( SsubM, false );
783 QApplication::restoreOverrideCursor();
784 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
785 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
789 catch (const SALOME::SALOME_Exception& S_ex) {
790 QtCatchCorbaException(S_ex);
793 myActiveStudy->updateObjBrowser(true);
794 QApplication::restoreOverrideCursor();
797 //=============================================================================
801 //=============================================================================
802 void SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
804 if ( !aSubMesh->_is_nil() ) {
805 QApplication::setOverrideCursor( Qt::waitCursor );
807 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
808 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
809 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
810 if ( !aMesh->_is_nil() ) {
811 bool res = aMesh->AddHypothesis( aShape, aHyp );
813 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
814 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
815 myStudyAPI.SetAlgorithms( SsubM, SH );
816 myStudyAPI.ModifiedMesh( SsubM, false );
819 QApplication::restoreOverrideCursor();
820 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
821 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
825 catch (const SALOME::SALOME_Exception& S_ex) {
826 QtCatchCorbaException(S_ex);
829 myActiveStudy->updateObjBrowser(true);
830 QApplication::restoreOverrideCursor();
833 //=============================================================================
837 //=============================================================================
838 void SMESHGUI::CreateAlgorithm( QString TypeAlgo, QString NameAlgo )
840 SMESH::SMESH_Hypothesis_var Hyp;
842 if ( TypeAlgo.compare("Regular_1D") == 0 )
843 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
844 else if ( TypeAlgo.compare("MEFISTO_2D") == 0 )
845 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
846 else if ( TypeAlgo.compare("Quadrangle_2D") == 0 )
847 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
848 else if ( TypeAlgo.compare("Hexa_3D") == 0 )
849 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
851 if ( !Hyp->_is_nil() ) {
852 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
853 myStudyAPI.SetName( SHyp, NameAlgo);
856 catch (const SALOME::SALOME_Exception& S_ex) {
857 QtCatchCorbaException(S_ex);
859 myActiveStudy->updateObjBrowser(true);
863 //=============================================================================
867 //=============================================================================
868 void SMESHGUI::CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length )
870 QApplication::setOverrideCursor( Qt::waitCursor );
872 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
873 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
874 if ( !LL->_is_nil() )
875 LL->SetLength( Length );
877 catch (const SALOME::SALOME_Exception& S_ex) {
878 QtCatchCorbaException(S_ex);
880 myActiveStudy->updateObjBrowser(true);
881 QApplication::restoreOverrideCursor();
884 //=============================================================================
888 //=============================================================================
889 void SMESHGUI::CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea )
891 QApplication::setOverrideCursor( Qt::waitCursor );
893 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
894 SMESH::SMESH_MaxElementArea_var MaxElArea = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
895 if ( !MaxElArea->_is_nil() )
896 MaxElArea->SetMaxElementArea( MaxArea );
898 catch (SALOME::SALOME_Exception& S_ex) {
899 QtCatchCorbaException(S_ex);
902 myActiveStudy->updateObjBrowser(true);
903 QApplication::restoreOverrideCursor();
906 //=============================================================================
910 //=============================================================================
911 void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume )
913 QApplication::setOverrideCursor( Qt::waitCursor );
915 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
916 SMESH::SMESH_MaxElementVolume_var MaxElVolume = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
917 if ( !MaxElVolume->_is_nil() )
918 MaxElVolume->SetMaxElementVolume( MaxVolume );
920 catch (const SALOME::SALOME_Exception& S_ex) {
921 QtCatchCorbaException(S_ex);
923 myActiveStudy->updateObjBrowser(true);
924 QApplication::restoreOverrideCursor();
927 //=============================================================================
931 //=============================================================================
932 void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments )
934 QApplication::setOverrideCursor( Qt::waitCursor );
936 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
937 SMESH::SMESH_NumberOfSegments_var NbS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
938 if ( !NbS->_is_nil() )
939 NbS->SetNumberOfSegments( nbSegments );
941 catch (const SALOME::SALOME_Exception& S_ex) {
942 QtCatchCorbaException(S_ex);
944 myActiveStudy->updateObjBrowser(true);
945 QApplication::restoreOverrideCursor();
948 //=============================================================================
952 //=============================================================================
953 int SMESHGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName )
955 int nbSel = Sel->IObjectCount() ;
957 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
958 aName = IObject->getName();
960 aName = tr( "SMESH_OBJECTS_SELECTED" ).arg( nbSel );
965 //=============================================================================
969 //=============================================================================
970 int SMESHGUI::GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName )
973 int nbSel = Sel->IObjectCount() ;
975 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
976 if ( !IObject->hasEntry() )
979 Standard_Boolean res;
980 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
984 TColStd_MapOfInteger MapIndex;
985 Sel->GetIndex( IObject, MapIndex );
986 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
988 nbNodes = MapIndex.Extent();
989 for ( ; ite.More(); ite.Next() ) {
990 aName = aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) + " ";
998 //=============================================================================
1002 //=============================================================================
1003 int SMESHGUI::GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName )
1006 int nbSel = Sel->IObjectCount() ;
1008 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1009 if ( !IObject->hasEntry() )
1012 Standard_Boolean res;
1013 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1017 TColStd_MapOfInteger MapIndex;
1018 Sel->GetIndex( IObject, MapIndex );
1019 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1021 nbElements = MapIndex.Extent();
1022 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1023 for ( ; ite.More(); ite.Next() ) {
1024 int idVTK = ite.Key();
1025 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1026 aName = aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1035 //=============================================================================
1039 //=============================================================================
1040 int SMESHGUI::GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName )
1043 int nbSel = Sel->IObjectCount() ;
1045 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1046 if ( !IObject->hasEntry() )
1049 Standard_Boolean res;
1050 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1054 TColStd_MapOfInteger MapIndex;
1055 Sel->GetIndex( IObject, MapIndex );
1056 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1058 nbElements = MapIndex.Extent();
1059 for ( ; ite.More(); ite.Next() ) {
1060 aName = aName + QString("%1").arg(ite.Key()) + " ";
1069 //=============================================================================
1073 //=============================================================================
1074 SMESH_Actor* SMESHGUI::FindActorByEntry(QString entry,
1075 Standard_Boolean& testResult,
1076 bool onlyInActiveView)
1078 int nbSf = myActiveStudy->getStudyFramesCount();
1079 for ( int i = 0; i < nbSf; i++ ) {
1080 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
1081 if ( sf->getTypeView() == VIEW_VTK ) {
1082 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1083 vtkActorCollection* theActors = Renderer->GetActors();
1084 theActors->InitTraversal();
1085 vtkActor *ac = theActors->GetNextActor();
1086 while(!(ac==NULL)) {
1087 if ( ac->IsA("SMESH_Actor") ) {
1088 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1089 if ( anActor->hasIO() ) {
1090 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1091 if ( strcmp( IO->getEntry(), entry ) == 0 ) {
1092 if ( onlyInActiveView ) {
1093 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
1104 ac = theActors->GetNextActor();
1109 MESSAGE ( " Actor Not Found " )
1111 return SMESH_Actor::New();
1114 //=============================================================================
1118 //=============================================================================
1119 SMESH_Actor* SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1120 Standard_Boolean& testResult,
1121 bool onlyInActiveView)
1123 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
1124 if ( SM->_is_nil() ) {
1125 MESSAGE ( " Actor Not Found " )
1128 return SMESH_Actor::New();
1131 return FindActorByEntry( SM->GetID(), testResult, onlyInActiveView);
1134 //=============================================================================
1138 //=============================================================================
1139 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO,
1140 Standard_Boolean& testResult)
1142 SMESH::SMESH_Mesh_var aMesh;
1143 testResult = false ;
1146 if ( IO->hasEntry() ) {
1147 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1148 SALOMEDS::GenericAttribute_var anAttr;
1149 SALOMEDS::AttributeIOR_var anIOR;
1150 if ( !obj->_is_nil() ) {
1151 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1152 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1153 aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1154 if ( !aMesh->_is_nil() ) {
1156 return SMESH::SMESH_Mesh::_duplicate( aMesh );
1161 return SMESH::SMESH_Mesh::_nil();
1164 //=============================================================================
1168 //=============================================================================
1169 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO,
1170 Standard_Boolean& testResult)
1172 SMESH::SMESH_subMesh_var aSubMesh;
1173 testResult = false ;
1176 if ( IO->hasEntry() ) {
1177 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1178 SALOMEDS::GenericAttribute_var anAttr;
1179 SALOMEDS::AttributeIOR_var anIOR;
1180 if ( !obj->_is_nil() ) {
1181 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1182 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1183 aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1184 if ( !aSubMesh->_is_nil() ) {
1186 return SMESH::SMESH_subMesh::_duplicate( aSubMesh );
1191 return SMESH::SMESH_subMesh::_nil();
1194 //=============================================================================
1198 //=============================================================================
1199 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO,
1200 Standard_Boolean& testResult )
1202 SMESH::SMESH_Hypothesis_var aHyp ;
1203 testResult = false ;
1206 if ( IO->hasEntry() ) {
1207 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1208 SALOMEDS::GenericAttribute_var anAttr;
1209 SALOMEDS::AttributeIOR_var anIOR;
1210 if ( !obj->_is_nil() ) {
1211 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1212 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1213 aHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()));
1214 if ( !aHyp->_is_nil() ) {
1216 return SMESH::SMESH_Hypothesis::_duplicate( aHyp );
1221 return SMESH::SMESH_Hypothesis::_nil();
1226 //=============================================================================
1230 //=============================================================================
1231 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO,
1232 Standard_Boolean& testResult )
1234 GEOM::GEOM_Shape_var aShape ;
1235 testResult = false ;
1238 if ( IO->hasEntry() ) {
1239 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1240 SALOMEDS::GenericAttribute_var anAttr;
1241 SALOMEDS::AttributeIOR_var anIOR;
1242 if ( !obj->_is_nil() ) {
1243 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1244 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1245 aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
1246 if ( !aShape->_is_nil() ) {
1248 return GEOM::GEOM_Shape::_duplicate( aShape );
1253 return GEOM::GEOM_Shape::_nil();
1257 //=============================================================================
1261 //=============================================================================
1262 void SMESHGUI::SetViewMode(int commandId)
1264 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1265 int nbSel = Sel->IObjectCount();
1267 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1268 for ( ; It.More(); It.Next() ) {
1269 Handle(SALOME_InteractiveObject) IObject = It.Value();
1270 if ( IObject->hasEntry() ) {
1271 Standard_Boolean res;
1272 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1274 switch (commandId) {
1276 ChangeRepresentation( ac, 0 );
1280 ChangeRepresentation( ac, 1 );
1284 ChangeRepresentation( ac, 2 );
1288 ChangeRepresentation( ac, 3 );
1295 if ( commandId == 1133 ) {
1296 ChangeRepresentation( SMESH_Actor::New(), 4 );
1301 //=============================================================================
1305 //=============================================================================
1306 void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
1308 if (ac->DataSource == NULL && type != 4 )
1312 if ( ac->getMapper() == NULL ) {
1318 QApplication::setOverrideCursor( Qt::waitCursor );
1319 if (ac->getDisplayMode()==2) {
1320 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1321 meshMapper->SetInput(ac->DataSource);
1323 ac->setDisplayMode(0);
1324 ac->GetProperty()->SetRepresentationToWireframe();
1325 // ac->SetActorProperty( ac->GetProperty() );
1326 QApplication::restoreOverrideCursor();
1330 QApplication::setOverrideCursor( Qt::waitCursor );
1331 if (ac->getDisplayMode()==2) {
1332 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1333 meshMapper->SetInput(ac->DataSource);
1335 ac->setDisplayMode(1);
1336 ac->GetProperty()->SetRepresentationToSurface();
1337 QApplication::restoreOverrideCursor();
1338 // ac->SetActorProperty( ac->GetProperty() );
1342 // if (!(ac->getDisplayMode()==2)) {
1343 // ChangeRepresentation(ac, 1);
1344 QApplication::setOverrideCursor( Qt::waitCursor );
1345 ac->setDisplayMode(2);
1346 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1347 meshMapper->SetInput(ac->DataSource);
1348 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1349 shrink->SetInput(meshMapper->GetInput());
1350 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1352 meshMapper->SetInput( shrink->GetOutput() );
1353 ac->SetMapper( meshMapper );
1354 QApplication::restoreOverrideCursor();
1362 float backfacecolor[3];
1364 ac->GetColor(color[0],color[1],color[2]);
1365 QColor c(color[0]*255,color[1]*255,color[2]*255);
1366 ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
1367 QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1368 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1369 QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1370 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
1371 QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1373 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1374 if ( Edgewidth == 0 )
1376 int intValue = ac->GetNodeSize() ;
1377 float Shrink = ac->GetShrinkFactor();
1379 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "" ) ;
1380 aDlg->SetColor(1,c);
1381 aDlg->SetColor(2,e);
1382 aDlg->SetColor(3,n);
1383 aDlg->SetColor(4,b);
1384 aDlg->SetIntValue(1,Edgewidth);
1385 aDlg->SetIntValue(2,intValue);
1386 aDlg->SetIntValue(3,int(Shrink*100.));
1388 if ( aDlg->exec() ) {
1389 QApplication::setOverrideCursor( Qt::waitCursor );
1390 QColor color = aDlg->GetColor(1);
1391 QColor edgecolor = aDlg->GetColor(2);
1392 QColor nodecolor = aDlg->GetColor(3);
1393 QColor backfacecolor = aDlg->GetColor(4);
1394 /* actor color and backface color */
1395 ac->GetProperty()->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1396 ac->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1397 ac->GetBackfaceProperty()->SetColor(float(backfacecolor.red())/255.,float(backfacecolor.green())/255.,float(backfacecolor.blue())/255.);
1400 ac->EdgeDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1401 float(edgecolor.green())/255.,
1402 float(edgecolor.blue())/255.);
1403 ac->EdgeShrinkDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1404 float(edgecolor.green())/255.,
1405 float(edgecolor.blue())/255.);
1406 ac->SetEdgeColor(float(edgecolor.red())/255.,
1407 float(edgecolor.green())/255.,
1408 float(edgecolor.blue())/255.);
1410 /* Shrink factor and size edges */
1411 ac->SetShrinkFactor( aDlg->GetIntValue(3)/100. );
1412 ac->EdgeDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1413 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1415 /* Nodes color and size */
1416 ac->SetNodeColor(float(nodecolor.red())/255.,
1417 float(nodecolor.green())/255.,
1418 float(nodecolor.blue())/255.);
1419 ac->SetNodeSize(aDlg->GetIntValue(2)) ;
1421 if (ac->getDisplayMode()==2) {
1422 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1423 meshMapper->SetInput(ac->DataSource);
1424 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1425 shrink->SetInput(meshMapper->GetInput());
1426 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1428 meshMapper->SetInput( shrink->GetOutput() );
1429 ac->SetMapper( meshMapper );
1433 QApplication::restoreOverrideCursor();
1438 EmitSignalDeactivateDialog() ;
1439 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1440 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg( QAD_Application::getDesktop(), "", Sel) ;
1444 QApplication::setOverrideCursor( Qt::waitCursor );
1445 ac->GetProperty()->SetRepresentationToPoints();
1446 QApplication::restoreOverrideCursor();
1451 QApplication::setOverrideCursor( Qt::waitCursor );
1452 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1453 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1454 theRenderer->Render();
1456 QApplication::restoreOverrideCursor();
1459 //=============================================================================
1463 //=============================================================================
1464 void SMESHGUI::UpdateView()
1466 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1469 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1470 theRenderer->Render();
1473 //=============================================================================
1477 //=============================================================================
1478 void SMESHGUI::DisplayActor(SMESH_Actor* ac, bool visibility)
1480 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1483 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1485 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1486 vtkActorCollection* theActors = theRenderer->GetActors();
1487 theActors->InitTraversal();
1488 if ( theActors->IsItemPresent(ac) == 0 ) {
1489 vtkProperty* prop = vtkProperty::New();
1490 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1491 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1492 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. ) ;
1494 prop->SetPointSize( QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
1495 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
1496 ac->SetProperty( prop );
1497 ac->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1498 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1499 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. );
1501 // prop->BackfaceCullingOn();
1502 vtkProperty* backprop = vtkProperty::New();
1503 backprop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed").toFloat()/255.,
1504 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").toFloat()/255.,
1505 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").toFloat()/255. ) ;
1506 ac->SetBackfaceProperty(backprop);
1508 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1511 ac->SetShrinkFactor( intValue/100. );
1513 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1514 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1516 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1517 if ( DisplayMode.compare("Wireframe") == 0 ){
1518 ac->setDisplayMode(0);
1519 ChangeRepresentation( ac, 0 );
1520 } else if ( DisplayMode.compare("Shading") == 0 ){
1521 ac->setDisplayMode(1);
1522 ChangeRepresentation( ac, 1 );
1523 } else if ( DisplayMode.compare("Shrink") == 0 ) {
1524 ac->setDisplayMode(2);
1525 ChangeRepresentation( ac, 2 );
1527 theRenderer->AddActor(ac);
1529 if (ac->GetMapper())
1530 ac->GetMapper()->Update();
1533 // if ( visibility )
1534 ac->SetVisibility(visibility);
1535 // ac->VisibilityOn();
1537 // ac->VisibilityOff();
1539 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1543 //=============================================================================
1547 //=============================================================================
1548 void SMESHGUI::EraseActor(SMESH_Actor* ac)
1550 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1553 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1555 //NRI- : 02/12/2002 : Fixed bugId 882
1556 // ac->EdgeDevice->VisibilityOff();
1557 // ac->EdgeShrinkDevice->VisibilityOff();
1558 // ac->VisibilityOff();
1559 ac->SetVisibility( false );
1561 theRenderer->Render();
1564 //=============================================================================
1568 //=============================================================================
1569 bool SMESHGUI::AddActorInSelection(SMESH_Actor* ac)
1571 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1572 Sel->ClearIObjects();
1574 return Sel->AddIObject( ac->getIO() );
1579 //=============================================================================
1583 //=============================================================================
1584 QString SMESHGUI::CheckHomogeneousSelection()
1586 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1589 SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
1590 for (; Itinit.More(); Itinit.Next()) {
1591 List.Append(Itinit.Value());
1594 QString RefType = CheckTypeObject( Sel->firstIObject() );
1595 SALOME_ListIteratorOfListIO It( List );
1596 for (; It.More(); It.Next()) {
1597 Handle(SALOME_InteractiveObject) IObject = It.Value();
1598 QString Type = CheckTypeObject( IObject );
1599 if ( Type.compare( RefType ) != 0 )
1600 return "Heterogeneous Selection";
1603 Sel->ClearIObjects();
1604 SALOME_ListIteratorOfListIO It1( List );
1605 for(;It1.More();It1.Next()) {
1606 int res = Sel->AddIObject( It1.Value() );
1608 myActiveStudy->highlight( It1.Value(), false );
1610 myActiveStudy->highlight( It1.Value(), true );
1615 //=============================================================================
1619 //=============================================================================
1620 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO)
1622 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
1623 if (!sobj->_is_nil()) {
1624 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1625 if (strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected
1630 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1631 Sel->ClearIObjects();
1633 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter( HYPOTHESIS );
1634 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter( ALGORITHM );
1635 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
1636 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
1637 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
1638 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter( SUBMESH_VERTEX );
1639 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter( SUBMESH_EDGE );
1640 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter( SUBMESH_FACE );
1641 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter( SUBMESH_SOLID );
1642 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter( SUBMESH_COMPOUND );
1644 Sel->AddFilter(aHypFilter);
1645 if ( Sel->AddIObject( IO ) != -1 ) {
1646 Sel->ClearFilters();
1647 return "Hypothesis";
1650 Sel->ClearFilters();
1651 Sel->AddFilter(anAlgoFilter);
1652 if ( Sel->AddIObject( IO ) != -1 ) {
1653 Sel->ClearFilters();
1657 Sel->ClearFilters();
1658 Sel->AddFilter(aMeshFilter);
1659 if ( Sel->AddIObject( IO ) != -1 ) {
1660 Sel->ClearFilters();
1664 Sel->ClearFilters();
1665 Sel->AddFilter(aSubMeshFilter);
1666 if ( Sel->AddIObject( IO ) != -1 ) {
1667 Sel->ClearFilters();
1671 Sel->ClearFilters();
1672 Sel->AddFilter(aSubMeshVextexFilter);
1673 if ( Sel->AddIObject( IO ) != -1 ) {
1674 Sel->ClearFilters();
1675 return "SubMeshVertex";
1678 Sel->ClearFilters();
1679 Sel->AddFilter(aSubMeshEdgeFilter);
1680 if ( Sel->AddIObject( IO ) != -1 ){
1681 Sel->ClearFilters();
1682 return "SubMeshEdge";
1685 Sel->ClearFilters();
1686 Sel->AddFilter(aSubMeshFaceFilter);
1687 if ( Sel->AddIObject( IO ) != -1 ) {
1688 Sel->ClearFilters();
1689 return "SubMeshFace";
1692 Sel->ClearFilters();
1693 Sel->AddFilter(aSubMeshSolidFilter);
1694 if ( Sel->AddIObject( IO ) != -1 ) {
1695 Sel->ClearFilters();
1696 return "SubMeshSolid";
1699 Sel->ClearFilters();
1700 Sel->AddFilter(aSubMeshCompoundFilter);
1701 if ( Sel->AddIObject( IO ) != -1 ) {
1702 Sel->ClearFilters();
1703 return "SubMeshCompound";
1706 Sel->ClearFilters();
1707 Sel->AddIObject( IO );
1711 //=============================================================================
1715 //=============================================================================
1716 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1718 /* Create or retrieve an object SMESHGUI */
1719 SMESHGUI::GetOrCreateSMESHGUI(parent);
1721 // NRI : Temporary added
1722 if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
1727 // QAD_Viewer3d* v3d;
1728 OCCViewer_Viewer3d* v3d;
1730 Handle(AIS_InteractiveContext) ic;
1731 vtkRenderer* Renderer;
1732 vtkRenderWindow* RenWin;
1734 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1735 v3d =((OCCViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1736 ic = v3d->getAISContext();
1737 } else if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1738 Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1739 RenWin = Renderer->GetRenderWindow();
1742 switch (theCommandID)
1745 smeshGUI->OnEditDelete();
1752 Import_Document(parent,theCommandID);//NBU
1753 //Import_Mesh(parent,theCommandID);
1757 case 122: // EXPORT MED
1761 Export_Mesh(parent, theCommandID);
1765 case 200: // SCALAR BAR
1767 smeshGUI->DisplayScalarBar(false);
1772 SMESHGUI_EditScalarBarDlg *aDlg = new SMESHGUI_EditScalarBarDlg( parent, "", false ) ;
1778 smeshGUI->DisplayScalarBar( true );
1782 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
1788 smeshGUI->SetViewMode(theCommandID);
1792 case 214 : // UPDATE
1800 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1801 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1803 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1804 for(;It.More();It.Next()) {
1805 Handle(SALOME_InteractiveObject) IOS = It.Value();
1806 if ( IOS->hasEntry() ) {
1807 Standard_Boolean res;
1808 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IOS->getEntry(), res, true );
1809 if ( res ) smeshGUI->EraseActor( ac );
1813 Sel->ClearIObjects();
1814 smeshGUI->myActiveStudy->updateObjBrowser( true );
1817 case 301 : // DISPLAY
1819 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1821 QApplication::setOverrideCursor( Qt::waitCursor );
1822 SALOMEDS::SObject_var fatherSF =
1823 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1825 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1826 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1828 for(;It.More();It.Next()) {
1829 Handle(SALOME_InteractiveObject) IObject = It.Value();
1830 if ( IObject->hasEntry() ) {
1831 Standard_Boolean res;
1832 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1834 smeshGUI->DisplayActor( ac, true );
1835 smeshGUI->DisplayEdges( ac );
1836 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1840 QApplication::restoreOverrideCursor();
1845 case 302 : // DISPLAY ONLY
1847 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1848 QApplication::setOverrideCursor( Qt::waitCursor );
1849 vtkActorCollection* theActors = Renderer->GetActors();
1850 theActors->InitTraversal();
1851 vtkActor *ac = theActors->GetNextActor();
1852 while(!(ac==NULL)) {
1853 if ( ac->IsA("SMESH_Actor") ) {
1854 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1855 if(!anActor->isHighlighted()) {
1856 //anActor->VisibilityOff();
1857 //NRI- : 02/12/2002 : Fixed bugId 882
1858 // anActor->EdgeDevice->VisibilityOff();
1859 // anActor->EdgeShrinkDevice->VisibilityOff();
1860 anActor->SetVisibility( false );
1863 ac = theActors->GetNextActor();
1866 // Display selection
1867 SALOMEDS::SObject_var fatherSF = smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1869 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1870 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1872 for(;It.More();It.Next()) {
1873 Handle(SALOME_InteractiveObject) IObject = It.Value();
1874 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1876 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
1877 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
1879 if(myRenderInter->isInViewer(IObject)) {
1880 if ( IObject->hasEntry() ) {
1881 Standard_Boolean res;
1882 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1884 smeshGUI->DisplayActor( ac, true );
1885 smeshGUI->DisplayEdges( ac );
1886 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1891 smeshGUI->myActiveStudy->updateObjBrowser( true );
1892 QApplication::restoreOverrideCursor();
1899 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1900 smeshGUI->EmitSignalDeactivateDialog() ;
1901 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1902 Sel->ClearIObjects();
1903 smeshGUI->myDesktop->SetSelectionMode(1, true);
1904 parent->menuBar()->setItemChecked(9010, false );
1905 parent->menuBar()->setItemChecked(9011, false );
1906 smeshGUI->ViewNodes();
1907 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg( parent, "", Sel ) ;
1909 QApplication::restoreOverrideCursor();
1910 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1911 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
1916 case 405: // MOVE NODE
1918 smeshGUI->myDesktop->SetSelectionMode(1, true);
1919 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1920 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, "", Sel ) ;
1924 case 701: // COMPUTE MESH
1926 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1927 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1928 int nbSel = Sel->IObjectCount();
1930 QApplication::restoreOverrideCursor();
1934 SMESH::SMESH_Mesh_var aM;
1935 SMESH::SMESH_subMesh_var aSubM;
1936 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1937 if ( IObject->hasEntry() ) {
1938 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1939 SALOMEDS::GenericAttribute_var anAttr;
1940 SALOMEDS::AttributeIOR_var anIOR;
1941 if ( !aMorSM->_is_nil() ) {
1942 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
1943 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1944 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : IOR = " << anIOR->Value() )
1945 CORBA::Object_var cobj;
1947 cobj = _orb->string_to_object(anIOR->Value());
1948 if ( CORBA::is_nil(cobj) ) {
1949 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : nil object" )
1952 catch(CORBA::COMM_FAILURE& ex) {
1953 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : exception (1)" )
1955 aM = SMESH::SMESH_Mesh::_narrow(cobj);
1956 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1957 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1958 if ( !aM->_is_nil() ) {
1959 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1960 if ( !refShape->_is_nil() ) {
1961 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1963 QApplication::restoreOverrideCursor();
1964 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1965 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1969 smeshGUI->myComponentMesh->Compute( aM, refShape);
1970 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1971 // TO Do : change icon of all submeshes
1973 catch (const SALOME::SALOME_Exception& S_ex) {
1974 QtCatchCorbaException(S_ex);
1977 } else if ( !aSubM->_is_nil() ) {
1978 aM = aSubM->GetFather();
1979 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1980 if ( !refShape->_is_nil() ) {
1981 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1983 QApplication::restoreOverrideCursor();
1984 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1985 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1989 smeshGUI->myComponentMesh->Compute( aM, refShape);
1990 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1991 // TO Do : change icon of all submeshes
1993 catch (const SALOME::SALOME_Exception& S_ex) {
1994 QtCatchCorbaException(S_ex);
2002 // Check whether the actor for the mesh exists at least in one view
2003 Standard_Boolean res;
2004 SMESH_Actor* ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2006 smeshGUI->InitActor( aM );
2008 // Check whether the actor belongs to the active view
2009 VTKViewer_RenderWindowInteractor* rwInter =
2010 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2012 // The actor belongs to inactive view -> create a copy and add it in the active view
2013 if (!rwInter->isInViewer(IObject)) {
2014 SMESH_Actor* acCopy = SMESH_Actor::New();
2015 acCopy->ShallowCopy(ac);
2017 smeshGUI->DisplayActor( acCopy, false );
2021 if ( smeshGUI->myAutomaticUpdate ) {
2022 SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
2023 if ( Mesh != NULL ) {
2027 smeshGUI->DisplayActor( Mesh, true );
2028 smeshGUI->DisplayEdges( Mesh, true );
2029 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
2033 QApplication::restoreOverrideCursor();
2034 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2035 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2037 QApplication::restoreOverrideCursor();
2041 case 702: // ADD SUB MESH
2043 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2044 smeshGUI->EmitSignalDeactivateDialog() ;
2045 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2046 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg( parent, "", Sel ) ;
2048 QApplication::restoreOverrideCursor();
2049 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2050 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2055 case 703: // INIT MESH
2057 smeshGUI->EmitSignalDeactivateDialog() ;
2058 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2059 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg( parent, "", Sel ) ;
2063 case 704: // EDIT Hypothesis
2065 smeshGUI->EmitSignalDeactivateDialog() ;
2066 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2067 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2071 case 705: // EDIT Global 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 706: // EDIT Local 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 806: // ORIENTATION ELEMENTS
2089 smeshGUI->EmitSignalDeactivateDialog() ;
2090 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2091 smeshGUI->myDesktop->SetSelectionMode(3, true);
2092 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg( parent, "", Sel ) ;
2096 case 807: // DIAGONAL INVERSION
2098 smeshGUI->EmitSignalDeactivateDialog() ;
2099 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2100 Sel->ClearIObjects();
2101 smeshGUI->myDesktop->SetSelectionMode(2, true);
2102 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg( parent, "", Sel ) ;
2106 case 900: // MESH INFOS
2108 smeshGUI->EmitSignalDeactivateDialog() ;
2109 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2110 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg( parent, "", Sel ) ;
2114 case 1001: // AUTOMATIC UPDATE PREFERENCES
2116 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001) );
2117 if ( parent->menuBar()->isItemChecked(1001) ) {
2118 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","true");
2119 smeshGUI->myAutomaticUpdate = true;
2121 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","false");
2122 smeshGUI->myAutomaticUpdate = false;
2127 case 1003: // MESH PREFERENCES
2129 smeshGUI->SetDisplaySettings();
2135 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2136 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2137 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2138 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2139 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2140 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2141 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2142 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2143 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2145 if ( Width == 0 ) Width = 0.17;
2146 if ( Height == 0 ) Height = 0.8;
2147 if ( NumberOfLabels == 0 ) NumberOfLabels = 5;
2148 if ( NumberOfColors == 0) NumberOfColors = 64;
2150 SMESHGUI_Preferences_ScalarBarDlg *aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, "", true) ;
2152 if ( Bold.compare("true") == 0 )
2153 aDlg->Bold->setChecked(true); else aDlg->Bold->setChecked(false);
2154 if ( Italic.compare("true") == 0 )
2155 aDlg->Italic->setChecked(true); else aDlg->Italic->setChecked(false);
2156 if ( Shadow.compare("true") == 0 )
2157 aDlg->Shadow->setChecked(true); else aDlg->Shadow->setChecked(false);
2159 if ( Orientation.compare("Horizontal") == 0 )
2160 aDlg->RadioHoriz->setChecked(true); else aDlg->RadioVert->setChecked(true);
2162 int NbItems = aDlg->ComboBox1->count();
2164 aDlg->ComboBox1->setCurrentItem( i );
2165 while ( i < NbItems ) {
2166 if ( FontFamily.compare( aDlg->ComboBox1->text( i ) ) == 0 )
2167 aDlg->ComboBox1->setCurrentItem( i );
2171 aDlg->LineEditWidth->setText( QString("%1").arg(Width) );
2172 aDlg->LineEditHeight->setText( QString("%1").arg(Height) );
2174 aDlg->SpinBoxLabels->setValue( NumberOfLabels );
2175 aDlg->SpinBoxColors->setValue( NumberOfColors );
2178 if ( aDlg->result() ) {
2179 if ( aDlg->RadioHoriz->isChecked() )
2180 Orientation = "Horizontal"; else Orientation = "Vertical";
2181 if ( aDlg->Bold->isChecked() )
2182 Bold = "true"; else Bold = "false";
2183 if ( aDlg->Italic->isChecked() )
2184 Italic = "true"; else Italic = "false";
2185 if ( aDlg->Shadow->isChecked() )
2186 Shadow = "true"; else Shadow = "false";
2188 FontFamily = aDlg->ComboBox1->currentText();
2189 Width = aDlg->LineEditWidth->text().toFloat();
2190 Height = aDlg->LineEditHeight->text().toFloat();
2191 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2192 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2195 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
2196 if ( aScalarBar != NULL ) {
2197 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2198 FontFamily, Orientation,
2199 Width, Height, NumberOfColors, NumberOfLabels);
2202 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2203 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2204 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2205 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2206 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2207 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2208 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2209 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2210 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2215 case 1100: // EDIT HYPOTHESIS
2217 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2218 int nbSel = Sel->IObjectCount() ;
2221 Standard_Boolean res;
2222 SMESH::SMESH_Hypothesis_var Hyp = smeshGUI->ConvertIOinSMESHHypothesis( Sel->firstIObject(), res );
2224 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2225 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2226 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2227 SALOMEDS::Study::ListOfSObject_var listSOmesh = smeshGUI->GetMeshesUsingAlgoOrHypothesis( Hyp) ;
2230 QString Name = Hyp->GetName();
2232 if ( Name.compare("LocalLength") == 0 ) {
2233 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
2234 double beforeLength = LL->GetLength() ;
2235 double Length = smeshGUI->Parameter( res,
2237 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2240 if ( res && Length != beforeLength ) {
2241 LL->SetLength( Length );
2242 for( int i=0; i<listSOmesh->length(); i++ ) {
2243 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2248 } else if ( Name.compare("NumberOfSegments") == 0 ) {
2249 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
2250 int beforeNbSeg = NOS->GetNumberOfSegments() ;
2251 int NbSeg = smeshGUI->Parameter( res,
2253 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2257 if ( res && NbSeg != beforeNbSeg ) {
2258 NOS->SetNumberOfSegments( NbSeg );
2259 for( int i=0; i<listSOmesh->length(); i++ ) {
2260 SALOMEDS::SObject_var SO = listSOmesh[i] ;
2261 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2266 } else if ( Name.compare("MaxElementArea") == 0 ) {
2267 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
2268 double beforeMaxArea = MEA->GetMaxElementArea() ;
2269 double MaxArea = smeshGUI->Parameter( res,
2271 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2274 if ( res && MaxArea != beforeMaxArea ) {
2275 MEA->SetMaxElementArea( MaxArea );
2276 for( int i=0; i<listSOmesh->length(); i++ ) {
2277 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2282 } else if ( Name.compare("MaxElementVolume") == 0 ) {
2283 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
2284 double beforeMaxVolume = MEV->GetMaxElementVolume() ;
2285 double MaxVolume = smeshGUI->Parameter( res,
2287 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2290 if ( res && MaxVolume != beforeMaxVolume ) {
2291 MEV->SetMaxElementVolume( MaxVolume );
2292 for( int i=0; i<listSOmesh->length(); i++ ) {
2293 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2298 } else if ( Name.compare("Regular_1D") == 0 ) {
2299 } else if ( Name.compare("MEFISTO_2D") == 0 ) {
2308 case 1101: // RENAME
2310 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2311 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2312 for ( ; It.More(); It.Next() ) {
2313 Handle(SALOME_InteractiveObject) IObject = It.Value();
2315 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2316 SALOMEDS::GenericAttribute_var anAttr;
2317 SALOMEDS::AttributeName_var aName;
2318 if ( !obj->_is_nil() ) {
2319 if (obj->FindAttribute(anAttr, "AttributeName")) {
2320 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2321 QString newName = QString( aName->Value() );
2322 newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName);
2323 if ( !newName.isEmpty() ) {
2324 QApplication::setOverrideCursor( Qt::waitCursor );
2325 smeshGUI->myActiveStudy->renameIObject( IObject, newName );
2327 QApplication::restoreOverrideCursor();
2334 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2336 QApplication::setOverrideCursor( Qt::waitCursor );
2337 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2338 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2339 for ( int i=0; It.More(); It.Next(), i++ ) {
2340 Handle(SALOME_InteractiveObject) IObject = It.Value();
2341 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh( IObject );
2343 Sel->ClearIObjects();
2344 smeshGUI->myActiveStudy->updateObjBrowser( true );
2345 QApplication::restoreOverrideCursor();
2349 case 401: // GEOM::EDGE
2351 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2352 smeshGUI->EmitSignalDeactivateDialog() ;
2353 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2354 Sel->ClearIObjects();
2355 smeshGUI->myDesktop->SetSelectionMode(1, true);
2356 parent->menuBar()->setItemChecked(9010, false );
2357 parent->menuBar()->setItemChecked(9011, false );
2358 smeshGUI->ViewNodes();
2359 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg( parent, "", Sel ) ;
2361 QApplication::restoreOverrideCursor();
2362 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2363 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2367 case 4021: // TRIANGLE
2369 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2370 smeshGUI->EmitSignalDeactivateDialog() ;
2371 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2372 Sel->ClearIObjects();
2373 smeshGUI->myDesktop->SetSelectionMode(1, true);
2374 parent->menuBar()->setItemChecked(9010, false );
2375 parent->menuBar()->setItemChecked(9011, false );
2376 smeshGUI->ViewNodes();
2377 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 3 ) ;
2379 QApplication::restoreOverrideCursor();
2380 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2381 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2387 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2388 smeshGUI->EmitSignalDeactivateDialog() ;
2389 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2390 Sel->ClearIObjects();
2391 smeshGUI->myDesktop->SetSelectionMode(1, true);
2392 parent->menuBar()->setItemChecked(9010, false );
2393 parent->menuBar()->setItemChecked(9011, false );
2394 smeshGUI->ViewNodes();
2395 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 4 ) ;
2397 QApplication::restoreOverrideCursor();
2398 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2399 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2405 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2406 smeshGUI->EmitSignalDeactivateDialog() ;
2407 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2408 Sel->ClearIObjects();
2409 smeshGUI->myDesktop->SetSelectionMode(1, true);
2410 parent->menuBar()->setItemChecked(9010, false );
2411 parent->menuBar()->setItemChecked(9011, false );
2412 smeshGUI->ViewNodes();
2413 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 4 ) ;
2415 QApplication::restoreOverrideCursor();
2416 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2417 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2423 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2424 smeshGUI->EmitSignalDeactivateDialog() ;
2425 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2426 Sel->ClearIObjects();
2427 smeshGUI->myDesktop->SetSelectionMode(1, true);
2428 parent->menuBar()->setItemChecked(9010, false );
2429 parent->menuBar()->setItemChecked(9011, false );
2430 smeshGUI->ViewNodes();
2431 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 8 ) ;
2433 QApplication::restoreOverrideCursor();
2434 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2435 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2440 case 4041: // REMOVES NODES
2442 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2443 smeshGUI->EmitSignalDeactivateDialog() ;
2444 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2445 Sel->ClearIObjects();
2446 smeshGUI->myDesktop->SetSelectionMode(1, true);
2447 parent->menuBar()->setItemChecked(9010, false );
2448 parent->menuBar()->setItemChecked(9011, false );
2449 smeshGUI->ViewNodes();
2450 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg( parent, "", Sel ) ;
2452 QApplication::restoreOverrideCursor();
2453 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2454 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2458 case 4042: // REMOVES ELEMENTS
2460 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2461 smeshGUI->EmitSignalDeactivateDialog() ;
2462 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2463 Sel->ClearIObjects();
2464 smeshGUI->myDesktop->SetSelectionMode(3, true);
2465 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg( parent, "", Sel ) ;
2467 QApplication::restoreOverrideCursor();
2468 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2469 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2474 case 5000: // HYPOTHESIS - ALGO
2476 smeshGUI->CreateAlgorithm("Regular_1D","Wire Discretisation");
2481 smeshGUI->CreateAlgorithm("MEFISTO_2D","Triangle (Mefisto)");
2486 smeshGUI->CreateAlgorithm("Quadrangle_2D","Quadrangle (Mapping)");
2491 smeshGUI->CreateAlgorithm("Hexa_3D","Hexaedral (i,j,k)");
2495 case 5030: // HYPOTHESIS - LOCAL LENGTH
2497 smeshGUI->EmitSignalDeactivateDialog() ;
2498 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2499 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg( parent, "" ) ;
2502 case 5031: // HYPOTHESIS - NB SEGMENTS
2504 smeshGUI->EmitSignalDeactivateDialog() ;
2505 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2506 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg( parent, "" ) ;
2510 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
2512 smeshGUI->EmitSignalDeactivateDialog() ;
2513 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2514 SMESHGUI_MaxElementAreaDlg *aDlg = new SMESHGUI_MaxElementAreaDlg( parent, "" ) ;
2518 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
2520 smeshGUI->EmitSignalDeactivateDialog() ;
2521 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2522 SMESHGUI_MaxElementVolumeDlg *aDlg = new SMESHGUI_MaxElementVolumeDlg( parent, "" ) ;
2526 case 6016: // CONTROLS
2534 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2535 int nbSel = Sel->IObjectCount();
2538 smeshGUI->Control(theCommandID);
2544 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2545 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2546 SMESHGUI_EdgesConnectivityDlg *Dlg = new SMESHGUI_EdgesConnectivityDlg( parent, "", Sel ) ;
2548 QApplication::restoreOverrideCursor();
2549 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2550 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2557 if ( !parent->menuBar()->isItemChecked(9010) ) {
2558 QApplication::setOverrideCursor( Qt::waitCursor );
2559 parent->menuBar()->setItemChecked(9011, false );
2561 smeshGUI->EraseSimulationActors();
2562 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2564 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2565 int nbSel = Sel->IObjectCount() ;
2567 Standard_Boolean res;
2568 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2570 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2572 // It's necessary to display SMDS IDs instead of VTK ones, so
2573 // vtkIdFilter is unacceptable here. We have to do it manually :(
2574 vtkUnstructuredGrid* ptGrid = vtkUnstructuredGrid::New();
2575 ptGrid->CopyStructure(MeshActor->DataSource);
2577 int numPts = MeshActor->DataSource->GetNumberOfPoints();
2579 // Loop over points and generate ids
2580 vtkIntArray *ptIds = vtkIntArray::New();
2581 ptIds->SetNumberOfValues(numPts);
2583 for (int id=0; id < numPts; id++) {
2584 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
2585 ptIds->SetValue(id, idSMDS);
2588 // mpv porting vtk4.2.2
2589 // vtkScalars* newScalars = vtkScalars::New();
2590 // newScalars->SetData(ptIds);
2591 // ptGrid->GetPointData()->SetScalars(newScalars);
2592 ptGrid->GetPointData()->SetScalars(ptIds);
2593 // newScalars->Delete();
2597 vtkMaskPoints* mask = vtkMaskPoints::New();
2598 mask->SetInput(ptGrid);
2599 mask->SetOnRatio( 1 );
2600 // mask->SetMaximumNumberOfPoints( 50 );
2601 // mask->RandomModeOn();
2603 vtkSelectVisiblePoints* visPts = vtkSelectVisiblePoints::New();
2604 visPts->SetInput(mask->GetOutput());
2605 visPts->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2606 //visPts->SetSelectInvisible(1);
2607 visPts->SelectInvisibleOff();
2608 visPts->SetTolerance(0.1);
2610 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2611 ldm->SetInput(visPts->GetOutput());
2612 ldm->SetLabelFormat("%g");
2613 ldm->SetLabelModeToLabelScalars();
2614 //ldm->SetLabelModeToLabelFieldData();
2616 ldm->SetFontFamilyToTimes();
2617 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2622 vtkActor2D* pointLabels = vtkActor2D::New();
2623 pointLabels->SetMapper(ldm);
2624 pointLabels->GetProperty()->SetColor(0,1,0);
2628 smeshGUI->mySimulationActors2D->AddItem( pointLabels );
2629 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( pointLabels );
2633 QApplication::setOverrideCursor( Qt::waitCursor );
2634 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2635 smeshGUI->EraseSimulationActors();
2636 smeshGUI->ScalarVisibilityOff();
2638 QApplication::restoreOverrideCursor();
2643 if ( !parent->menuBar()->isItemChecked(9011) ) {
2644 QApplication::setOverrideCursor( Qt::waitCursor );
2645 parent->menuBar()->setItemChecked(9010, false );
2647 smeshGUI->EraseSimulationActors();
2648 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2650 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2651 int nbSel = Sel->IObjectCount() ;
2653 Standard_Boolean res;
2654 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2656 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2658 // It's necessary to display SMDS IDs instead of VTK ones, so
2659 // vtkIdFilter is unacceptable here. We have to do it manually :(
2660 vtkUnstructuredGrid* elGrid = vtkUnstructuredGrid::New();
2661 elGrid->CopyStructure(MeshActor->DataSource);
2663 int numCells = MeshActor->DataSource->GetNumberOfCells();
2665 // Loop over points and generate ids
2666 vtkIntArray *cellIds = vtkIntArray::New();
2667 cellIds->SetNumberOfValues(numCells);
2669 for (int id=0; id < numCells; id++) {
2670 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
2671 cellIds->SetValue(id, idSMDS);
2674 // mpv porting vk4.2.2
2675 // vtkScalars* newScalars = vtkScalars::New();
2676 // newScalars->SetData(cellIds);
2677 elGrid->GetCellData()->SetScalars(cellIds);
2678 // elGrid->GetCellData()->SetScalars(newScalars);
2679 // newScalars->Delete();
2684 vtkCellCenters* cc = vtkCellCenters::New();
2685 cc->SetInput(elGrid);
2687 vtkSelectVisiblePoints* visCells = vtkSelectVisiblePoints::New();
2688 visCells->SetInput(cc->GetOutput());
2689 visCells->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2690 visCells->SelectInvisibleOff();
2691 visCells->SetTolerance(0.1);
2692 // visCells->SetSelectInvisible(1);
2694 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2695 ldm->SetInput(visCells->GetOutput());
2696 ldm->SetLabelFormat("%g");
2697 ldm->SetLabelModeToLabelScalars();
2699 ldm->SetFontFamilyToTimes();
2700 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2705 vtkActor2D* cellLabels = vtkActor2D::New();
2706 cellLabels->SetMapper(ldm);
2707 cellLabels->GetProperty()->SetColor(1,0,0);
2712 smeshGUI->mySimulationActors2D->AddItem( cellLabels );
2713 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( cellLabels );
2717 QApplication::setOverrideCursor( Qt::waitCursor );
2718 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2719 smeshGUI->EraseSimulationActors();
2720 smeshGUI->ScalarVisibilityOff();
2722 QApplication::restoreOverrideCursor();
2726 case 10001: // DISPLAY MODE PREFERENCE
2728 parent->menuBar()->setItemChecked(10001, !parent->menuBar()->isItemChecked(10001) );
2729 parent->menuBar()->setItemChecked(10002, false );
2730 parent->menuBar()->setItemChecked(10003, false );
2731 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2736 parent->menuBar()->setItemChecked(10002, !parent->menuBar()->isItemChecked(10002) );
2737 parent->menuBar()->setItemChecked(10001, false );
2738 parent->menuBar()->setItemChecked(10003, false );
2739 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2744 parent->menuBar()->setItemChecked(10003, !parent->menuBar()->isItemChecked(10003) );
2745 parent->menuBar()->setItemChecked(10002, false );
2746 parent->menuBar()->setItemChecked(10001, false );
2747 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
2753 smeshGUI->myActiveStudy->updateObjBrowser(true);
2758 //=============================================================================
2759 /*! function : GetMeshesUsingAlgoOrHypothesis()
2760 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
2761 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
2763 //=============================================================================
2764 SALOMEDS::Study::ListOfSObject* SMESHGUI::GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp )
2766 SALOMEDS::Study::ListOfSObject_var listSOmesh = new SALOMEDS::Study::ListOfSObject ;
2767 listSOmesh->length(0) ;
2768 unsigned int index = 0 ;
2769 if( !AlgoOrHyp->_is_nil() ) {
2770 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms( AlgoOrHyp );
2771 if( !SO_Hypothesis->_is_nil() ) {
2772 SALOMEDS::Study::ListOfSObject_var listSO = smeshGUI->myStudy->FindDependances(SO_Hypothesis) ;
2773 for( unsigned int i=0; i<listSO->length(); i++ ) {
2774 SALOMEDS::SObject_var SO = listSO[i] ;
2775 if( !SO->_is_nil() ) {
2776 SALOMEDS::SObject_var SOfatherFather = SO->GetFather()->GetFather() ;
2777 if( !SOfatherFather->_is_nil() ) {
2779 listSOmesh->length(index) ;
2780 listSOmesh[index-1] = SOfatherFather ;
2786 return listSOmesh._retn() ;
2790 //=============================================================================
2794 //=============================================================================
2795 void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
2799 Mesh_Reader* myReader;
2801 if (theCommandID==113) {
2802 filter = tr("MED files (*.med)");
2803 myExtension = string("MED");
2804 myReader = new DriverMED_R_SMESHDS_Mesh;
2806 else if (theCommandID==112) {
2807 filter = tr("IDEAS files (*.unv)");
2808 myExtension = string("UNV");
2810 else if (theCommandID==111) {
2811 filter = tr("DAT files (*.dat)");
2812 myExtension = string("MED");
2813 myReader = new DriverDAT_R_SMESHDS_Mesh;
2816 QString filename = QAD_FileDlg::getFileName(parent,
2821 if ( !filename.isEmpty() ) {
2822 QApplication::setOverrideCursor( Qt::waitCursor );
2823 string myClass = string("SMESHDS_Mesh");
2824 // Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
2826 int myMeshId = (smeshGUI->myDocument)->NewMesh();
2827 SMDS_Mesh* myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
2829 myReader->SetFile(string(filename.latin1()));
2830 myReader->SetMesh(myMesh);
2831 myReader->SetMeshId(myMeshId);
2834 QApplication::restoreOverrideCursor();
2838 //=============================================================================
2842 //=============================================================================
2843 void SMESHGUI::Export_Mesh(QAD_Desktop* parent, int theCommandID)
2845 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2846 int nbSel = Sel->IObjectCount() ;
2848 Standard_Boolean res;
2849 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2850 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh( IObject, res );
2852 if (theCommandID==122) { // EXPORT MED
2853 QString filename = QAD_FileDlg::getFileName(parent,
2855 tr("MED files (*.med)"),
2858 if ( !filename.isEmpty() ) {
2859 QApplication::setOverrideCursor( Qt::waitCursor );
2860 aMesh->ExportMED( filename.latin1() );
2861 QApplication::restoreOverrideCursor();
2864 else if (theCommandID==121) { // EXPORT DAT
2865 QString filename = QAD_FileDlg::getFileName(parent,
2867 tr("DAT files (*.dat)"),
2870 if ( !filename.isEmpty() ) {
2871 QApplication::setOverrideCursor( Qt::waitCursor );
2872 aMesh->ExportDAT( filename.latin1() );
2873 QApplication::restoreOverrideCursor();
2876 else if (theCommandID==123) { // EXPORT UNV
2877 QString filename = QAD_FileDlg::getFileName(parent,
2879 tr("IDEAS files (*.unv)"),
2882 if ( !filename.isEmpty() ) {
2883 QApplication::setOverrideCursor( Qt::waitCursor );
2884 aMesh->ExportUNV( filename.latin1() );
2885 QApplication::restoreOverrideCursor();
2888 aMesh->ExportDAT( filename.latin1() );
2890 QApplication::restoreOverrideCursor();
2892 if ( IObject->hasEntry() )
2895 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2896 SALOMEDS::GenericAttribute_var anAttr;
2897 SALOMEDS::AttributeComment_var aFileName;
2898 SALOMEDS::StudyBuilder_var aStudyBuilder = smeshGUI->myStudy->NewBuilder();
2899 anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
2900 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
2901 aFileName->SetValue(filename.latin1());
2908 //=============================================================================
2912 //=============================================================================
2913 void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
2917 Document_Reader* myReader;
2919 if (theCommandID==113) {
2920 filter = tr("MED files (*.med)");
2921 myExtension = string("MED");
2922 myReader = new DriverMED_R_SMESHDS_Document;
2924 else if (theCommandID==112) {
2925 filter = tr("IDEAS files (*.unv)");
2926 myExtension = string("UNV");
2927 myReader = new DriverUNV_R_SMESHDS_Document;
2929 else if (theCommandID==111) {
2930 filter = tr("DAT files (*.dat)");
2931 myExtension = string("DAT");
2932 myReader = new DriverDAT_R_SMESHDS_Document;
2935 QString filename = QAD_FileDlg::getFileName(parent,
2938 tr("Import document"),
2940 if ( !filename.isEmpty() ) {
2941 QApplication::setOverrideCursor( Qt::waitCursor );
2942 string myClass = string("SMESHDS_Document");
2943 // Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
2944 SMESHDS_Document* newDocument = new SMESHDS_Document(1);
2946 myReader->SetFile(string(filename.latin1()));
2947 myReader->SetDocument(smeshGUI->myDocument);
2949 QApplication::restoreOverrideCursor();
2953 void SMESHGUI::Export_Document(QAD_Desktop* parent, int theCommandID)
2956 Document_Writer* myWriter;
2959 if (theCommandID==122) {
2960 filter = tr("MED files (*.med)");
2961 myExtension = string("MED");
2962 myWriter = new DriverMED_W_SMESHDS_Document;
2964 else if (theCommandID==121) {
2965 filter = tr("DAT files (*.dat)");
2966 myExtension = string("DAT");
2967 myWriter = new DriverDAT_W_SMESHDS_Document;
2968 } else if (theCommandID==123) {
2969 filter = tr("IDEAS files (*.unv)");
2970 myExtension = string("UNV");
2971 myWriter = new DriverUNV_W_SMESHDS_Document;
2974 QString filename = QAD_FileDlg::getFileName(parent,
2977 tr("Export document"),
2979 if ( !filename.isEmpty() ) {
2980 QApplication::setOverrideCursor( Qt::waitCursor );
2981 string myClass = string("SMESHDS_Document");
2982 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
2984 myWriter->SetFile(string(filename.latin1()));
2985 myWriter->SetDocument(smeshGUI->myDocument);
2987 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
2988 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
2989 //myWriter->SetDocument(myDocument);
2992 QApplication::restoreOverrideCursor();
2996 //=============================================================================
3000 //=============================================================================
3001 bool SMESHGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3003 SMESHGUI::GetOrCreateSMESHGUI(parent);
3008 //=============================================================================
3012 //=============================================================================
3013 bool SMESHGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3015 SMESHGUI::GetOrCreateSMESHGUI(parent);
3021 //=============================================================================
3025 //=============================================================================
3026 bool SMESHGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3028 SMESHGUI::GetOrCreateSMESHGUI(parent);
3034 //=============================================================================
3038 //=============================================================================
3039 bool SMESHGUI::SetSettings( QAD_Desktop* parent )
3041 SMESHGUI::GetOrCreateSMESHGUI(parent);
3044 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3045 if ( DisplayMode.compare("") == 0 ) {
3046 DisplayMode = "Shading";
3047 QAD_CONFIG->addSetting("SMESH:DisplayMode","Shading");
3050 if ( DisplayMode.compare("Wireframe") == 0 ){
3051 parent->menuBar()->setItemChecked(10003, false );
3052 parent->menuBar()->setItemChecked(10002, false );
3053 parent->menuBar()->setItemChecked(10001, true );
3054 } else if ( DisplayMode.compare("Shading") == 0 ){
3055 parent->menuBar()->setItemChecked(10003, false );
3056 parent->menuBar()->setItemChecked(10002, true );
3057 parent->menuBar()->setItemChecked(10001, false );
3058 } else if ( DisplayMode.compare("Shrink") == 0 ) {
3059 parent->menuBar()->setItemChecked(10003, true );
3060 parent->menuBar()->setItemChecked(10002, false );
3061 parent->menuBar()->setItemChecked(10001, false );
3064 /* Automatic Update */
3065 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3066 if ( AutoUpdate.compare("true") == 0 ) {
3067 parent->menuBar()->setItemChecked(1001, true );
3068 smeshGUI->myAutomaticUpdate = true;
3070 parent->menuBar()->setItemChecked(1001, false );
3071 smeshGUI->myAutomaticUpdate = false;
3075 parent->menuBar()->setItemEnabled( 11, false); // IMPORT
3081 //=============================================================================
3085 //=============================================================================
3086 void SMESHGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
3088 /* Create or retrieve an object SMESHGUI */
3089 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3091 // NRI : Temporary added
3092 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3093 // theObject = "NothingSelected";
3094 // theContext = "NothingSelected";
3098 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3099 int nbSel = Sel->IObjectCount();
3101 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3102 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
3103 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1) ) {
3104 theObject = "ScalarBar";
3107 theObject = "NothingSelected";
3108 theContext = "NothingSelected";
3111 theObject = "NothingSelected";
3112 theContext = "NothingSelected";
3114 } else if (nbSel == 1 ) {
3115 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3118 theObject = smeshGUI->CheckHomogeneousSelection();
3123 //=============================================================================
3127 //=============================================================================
3128 bool SMESHGUI::CustomPopup( QAD_Desktop* parent,
3130 const QString& theContext,
3131 const QString& theParent,
3132 const QString& theObject )
3134 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3135 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3137 /* Create or retrieve an object SMESHGUI */
3138 SMESHGUI::GetOrCreateSMESHGUI(parent);
3140 // NRI : Temporary added
3141 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3146 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3147 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3148 int nbSel = Sel->IObjectCount();
3151 if (studyFrame->getTypeView() != VIEW_VTK)
3154 } else if (nbSel == 1 ) {
3155 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3156 // First check type of active viewer (VTK required)
3157 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3159 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3161 int id = popup->idAt(0);
3162 if (id <= QAD_TopLabel_Popup_ID)
3163 popup->removeItemAt(0);
3167 if (theObject.compare("Component") == 0) {
3168 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3173 // Remove common popup items for Submesh, Hypothesis and Algorithm
3174 if (theObject.compare("SubMesh") == 0 ||
3175 theObject.compare("Hypothesis") == 0 ||
3176 theObject.compare("Algorithm") == 0 ) {
3177 popup->removeItem(QAD_Display_Popup_ID);
3178 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3179 popup->removeItem(QAD_Erase_Popup_ID);
3180 int id = popup->idAt(popup->count()-1); // last item
3181 if (id < 0 && id != -1) popup->removeItem(id); // separator
3184 if (theObject.compare("Component") == 0) {
3185 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3189 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3190 QFont f = QApplication::font();
3193 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3195 if ( theParent.compare("Viewer")==0 ) {
3196 if (popup->idAt(0) == id) {
3197 popup->removeItem(id);
3198 popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), id, 0 );
3201 Standard_Boolean res;
3202 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3203 if ( res && studyFrame->getTypeView() == VIEW_VTK) {
3204 VTKViewer_RenderWindowInteractor* myRenderInter=
3205 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3206 if ( myRenderInter->isVisible( IObject ) ) {
3207 popup->removeItem(QAD_Display_Popup_ID);
3209 popup->removeItem(QAD_Erase_Popup_ID);
3212 popup->removeItem(QAD_Erase_Popup_ID);
3213 if (!res) {// mesh not computed -> can't display it
3214 popup->removeItem(QAD_Display_Popup_ID);
3215 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3216 popup->removeItemAt(popup->count() - 1);//separator
3219 } else if ( theParent.compare("ObjectBrowser")==0 ) {
3220 if (theObject.compare("Mesh") == 0 ||
3221 theObject.compare("SubMesh") == 0 ||
3222 theObject.compare("Hypothesis") == 0 ||
3223 theObject.compare("Algorithm") == 0 ) {
3224 popup->removeItemAt(0);
3226 if (popup->idAt(0) == id) {
3227 popup->removeItem(id);
3228 popup->removeItemAt(0);//separator
3232 Standard_Boolean res;
3233 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3234 if ( res && studyFrame->getTypeView() == VIEW_VTK ) {
3235 VTKViewer_RenderWindowInteractor* myRenderInter=
3236 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3237 if ( myRenderInter->isVisible( IObject ) ) {
3238 popup->removeItem(QAD_Display_Popup_ID);
3240 popup->removeItem(QAD_Erase_Popup_ID);
3243 if (theObject.compare("Mesh") == 0 ||
3244 theObject.compare("SubMesh") == 0 ||
3245 theObject.compare("Hypothesis") == 0 ||
3246 theObject.compare("Algorithm") == 0 ) {
3248 popup->removeItem(QAD_Erase_Popup_ID);
3249 if (!res) {// mesh not computed -> can't display it
3250 popup->removeItem(QAD_Display_Popup_ID);
3251 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3252 popup->removeItemAt(popup->count() - 1);//separator
3258 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3259 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3260 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3262 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3264 int id = popup->idAt(0);
3265 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3266 popup->removeItemAt(0);
3270 if (parentComp.isNull()) { // objects from several components are selected
3271 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3272 popup->removeItem(QAD_Display_Popup_ID);
3273 popup->removeItem(QAD_Erase_Popup_ID);
3274 int id = popup->idAt(popup->count()-1); // last item
3275 if (id < 0 && id != -1) popup->removeItem(id); // separator
3280 QString type = smeshGUI->CheckHomogeneousSelection();
3281 if ( type.compare("Heterogeneous Selection") != 0 ) {
3282 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3283 QFont f = QApplication::font();
3285 popup->removeItem(id);
3286 popup->insertItem( new CustomItem ( QString("%1 ").arg(nbSel) + type + " (s) ", f), id, 0 );
3292 //=============================================================================
3293 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3294 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3296 //=============================================================================
3297 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3299 /* Create or retrieve an object SMESHGUI */
3300 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3302 QAD_StudyFrame* activeFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3303 if (activeFrame->getTypeView() == VIEW_VTK) {
3305 SALOMEDS::SObject_var fatherSF =
3306 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
3308 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3309 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3311 // for(;It.More();It.Next()) {
3312 // Handle(SALOME_InteractiveObject) IObject = It.Value();
3313 Handle(SALOME_InteractiveObject) IObject = theIO;
3314 if ( IObject->hasEntry() ) {
3315 // Look for the actor in all views
3316 Standard_Boolean res;
3317 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3319 // Actor not found at all -> mesh is not computed -> do nothing!!!
3321 /*SMESH::SMESH_Mesh_var aM;
3322 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3323 SALOMEDS::SObject_var father = aMorSM->GetFather();
3324 SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
3326 // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
3327 if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
3330 SALOMEDS::GenericAttribute_var anAttr;
3331 SALOMEDS::AttributeIOR_var anIOR;
3332 if ( !aMorSM->_is_nil() ) {
3333 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
3334 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3335 aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
3339 if (!aM->_is_nil()) {
3340 smeshGUI->InitActor(aM);
3341 ac = smeshGUI->ReadScript(aM);
3345 smeshGUI->DisplayActor( ac, true );
3346 smeshGUI->DisplayEdges( ac );
3347 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3350 } else { // The actor exists in some view
3351 // Check whether the actor belongs to the active view
3352 VTKViewer_RenderWindowInteractor* rwInter =
3353 ((VTKViewer_ViewFrame*)activeFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3355 // The actor belongs to inactive view -> create a copy and display it in the active view
3356 if (!rwInter->isInViewer(IObject)) {
3357 SMESH_Actor* acCopy = SMESH_Actor::New();
3358 acCopy->ShallowCopy(ac);
3361 smeshGUI->DisplayActor( ac, false );
3362 smeshGUI->DisplayEdges( ac );
3363 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3368 MESSAGE("BuildPresentation() must not be called while non-VTK view is active")
3372 //=============================================================================
3376 //=============================================================================
3377 void SMESHGUI::setOrb()
3380 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
3381 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
3382 _orb = init( 0 , 0 );
3384 INFOS("internal error : orb not found");
3387 ASSERT(! CORBA::is_nil(_orb));
3391 //=============================================================================
3395 //=============================================================================
3396 SMESH_Actor* SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
3398 SMESH_Actor* MeshActor;
3399 if ( !aMesh->_is_nil() ) {
3400 Standard_Boolean result;
3401 MeshActor = FindActor(aMesh, result, true);
3403 SMESH::log_array_var aSeq = aMesh->GetLog(true);
3405 if (aSeq->length() == 0) {
3406 MESSAGE("ReadScript(): log is empty")
3410 for (unsigned int ind = 0; ind < aSeq->length();ind++) {
3411 switch ( aSeq[ind].commandType )
3413 case SMESH::ADD_NODE :
3415 AddNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3418 case SMESH::ADD_EDGE :
3420 // AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3423 case SMESH::ADD_TRIANGLE :
3425 AddTriangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3428 case SMESH::ADD_QUADRANGLE :
3430 AddQuadrangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3433 case SMESH::ADD_TETRAHEDRON :
3435 AddTetras( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3438 case SMESH::ADD_PYRAMID :
3442 case SMESH::ADD_PRISM :
3446 case SMESH::ADD_HEXAHEDRON :
3448 AddHexaedres( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3451 case SMESH::REMOVE_NODE :
3453 RemoveNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3456 case SMESH::REMOVE_ELEMENT :
3458 RemoveElements( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3470 //=============================================================================
3474 //=============================================================================
3475 void SMESHGUI::Dump(SMESH_Actor* Mactor)
3477 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3478 vtkPoints *Pts = ugrid->GetPoints();
3479 int nbPts = Pts->GetNumberOfPoints();
3480 int nbCells = ugrid->GetNumberOfCells();
3484 In = fopen("/tmp/dumpMesh","w+");
3485 fprintf(In,"%d %d\n",nbPts,nbCells);
3486 for ( int i = 0; i < nbPts; i++ ) {
3487 float *p = ugrid->GetPoint(i);
3488 fprintf(In,"%d %e %e %e\n",i, p[0], p[1], p[2] );
3491 for ( int i = 0; i < nbCells; i++ ) {
3492 fprintf(In,"%d %d",i,ugrid->GetCell(i)->GetCellType());
3493 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3494 for (j=0; j<Id->GetNumberOfIds(); j++) {
3495 fprintf(In," %d",Id->GetId(j));
3503 //=============================================================================
3507 //=============================================================================
3508 void SMESHGUI::AddNodes( SMESH_Actor* Mactor, int number,
3509 const SMESH::double_array& coords,
3510 const SMESH::long_array& indexes)
3512 QApplication::setOverrideCursor( Qt::waitCursor );
3513 if ( Mactor->GetMapper() == NULL ) {
3514 vtkPoints *Pts = vtkPoints::New();
3515 SMESH_Grid *ugrid = SMESH_Grid::New();
3520 while ( i <= number ) {
3521 int idVTK = Pts->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3522 //Mactor->AddNode( indexes[i-1], idVTK );
3523 ugrid->AddNode( indexes[i-1], idVTK );
3527 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3528 ugrid->SetPoints(Pts);
3529 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3530 PtsMapper->SetInput( ugrid );
3531 Mactor->DataSource = PtsMapper->GetInput();
3532 Mactor->SetMapper(PtsMapper);
3534 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3535 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3538 while ( i <= number ) {
3539 int idVTK = ugrid->GetPoints()->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3540 ugrid->AddNode( indexes[i-1], idVTK );
3544 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3545 PtsMapper->SetInput( ugrid );
3546 Mactor->DataSource = PtsMapper->GetInput();
3547 Mactor->SetMapper(PtsMapper);
3549 QApplication::restoreOverrideCursor();
3552 //=============================================================================
3556 //=============================================================================
3557 void SMESHGUI::AddNode(SMESH_Actor* Mactor, int idnode, float x, float y, float z)
3559 QApplication::setOverrideCursor( Qt::waitCursor );
3560 MESSAGE ( "SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z )
3561 if ( Mactor->GetMapper() == NULL ) {
3562 vtkPoints *Pts = vtkPoints::New();
3563 int idVTK = Pts->InsertNextPoint( x, y, z );
3564 //Mactor->AddNode( idnode, idVTK );
3565 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3566 SMESH_Grid *ugrid = SMESH_Grid::New();
3568 ugrid->AddNode( idnode, idVTK );
3569 ugrid->SetPoints(Pts);
3570 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3571 PtsMapper->SetInput( ugrid );
3572 Mactor->DataSource = PtsMapper->GetInput();
3573 Mactor->SetMapper(PtsMapper);
3575 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3576 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3577 int idVTK = ugrid->GetPoints()->InsertNextPoint( x, y, z );
3578 //Mactor->AddNode( idnode, idVTK );
3579 ugrid->AddNode( idnode, idVTK );
3580 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3581 PtsMapper->SetInput( ugrid );
3582 Mactor->DataSource = PtsMapper->GetInput();
3583 Mactor->SetMapper(PtsMapper);
3585 QApplication::restoreOverrideCursor();
3588 //=============================================================================
3592 //=============================================================================
3593 void SMESHGUI::RemoveNode(SMESH_Actor* Mactor, int idnode)
3595 MESSAGE ( " OLD RemoveNode method " )
3596 // int id = Mactor->GetIdVTKNode( idnode );
3597 // MESSAGE ( " RemoveNode id VTK " << id )
3598 // if ( Mactor->GetMapper() != NULL ) {
3599 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3600 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3601 // vtkPoints *Pts = ugrid->GetPoints();
3602 // vtkPoints *newPts = vtkPoints::New();
3603 // int nbPts = Pts->GetNumberOfPoints();
3604 // bool findPt = false;
3605 // for ( int i = 0; i < nbPts; i++ ) {
3608 // newPts->InsertPoint(i, Pts->GetPoint(i) );
3610 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
3613 // Mactor->RemoveNode( idnode );
3617 // newUgrid->SetPoints(newPts);
3618 // int nbCells = ugrid->GetNumberOfCells();
3619 // for ( int i = 0; i < nbCells; i++ ) {
3620 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3621 // vtkIdList *newIds = vtkIdList::New();
3622 // int nbIds = Ids->GetNumberOfIds();
3623 // newIds->SetNumberOfIds(nbIds);
3624 // for ( int j = 0; j < nbIds; j++ ) {
3625 // int theid = Ids->GetId(j);
3626 // if ( theid > id ) {
3627 // newIds->SetId( j, theid-1 );
3629 // newIds->SetId( j, theid );
3631 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3632 // Mactor->RemoveElement( idSMDSel, false );
3633 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3634 // Mactor->AddElement( idSMDSel, idVTKel );
3638 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3639 // Mapper->SetInput( newUgrid );
3640 // Mactor->DataSource = Mapper->GetInput();
3641 // Mactor->SetMapper(Mapper);
3647 //=============================================================================
3651 //=============================================================================
3652 void SMESHGUI::RemoveNodes(SMESH_Actor* Mactor, int number,
3653 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3655 QApplication::setOverrideCursor( Qt::waitCursor );
3657 while ( i <= number ) {
3658 Mactor->RemoveNode( indexes[i-1] );
3662 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
3663 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
3664 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
3666 if ( Mactor->GetMapper() != NULL ) {
3667 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3668 SMESH_Grid *newUgrid = SMESH_Grid::New();
3669 newUgrid->CopyMaps(ugrid);
3671 vtkPoints *Pts = ugrid->GetPoints();
3672 vtkPoints *newPts = vtkPoints::New();
3673 int nbPts = Pts->GetNumberOfPoints();
3675 for ( int i = 0; i < nbPts; i++ ) {
3676 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
3677 if ( idSMESHDSNode != -1 ) {
3678 newPts->InsertPoint(j, Pts->GetPoint(i) );
3680 newMapVTKNodes.Bind(j, idSMESHDSNode);
3681 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
3683 MapOldNodesToNewNodes.Bind(i,j);
3688 newUgrid->SetIdsVTKNode(newMapVTKNodes);
3689 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
3690 newUgrid->SetPoints(newPts);
3692 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3693 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3695 int nbCells = ugrid->GetNumberOfCells();
3696 for ( int i = 0; i < nbCells; i++ ) {
3697 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3698 vtkIdList *newIds = vtkIdList::New();
3699 int nbIds = Ids->GetNumberOfIds();
3700 newIds->SetNumberOfIds(nbIds);
3702 for ( int j = 0; j < nbIds; j++ ) {
3703 int theid = Ids->GetId(j);
3704 if ( MapOldNodesToNewNodes.IsBound( theid ) ) {
3705 newIds->SetId( j, MapOldNodesToNewNodes.Find( theid ) );
3712 // Filtering out cells based on non-existing nodes
3714 int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3715 int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3717 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
3718 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
3722 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3723 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3725 // Copy new data to the old DatSource: keep the single DataSource for all actors
3726 ugrid->DeepCopy(newUgrid);
3728 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3729 Mapper->SetInput( ugrid );
3730 Mactor->SetMapper(Mapper);
3732 // Commented to avoid multiple viewer updates when called by ReadScript()
3736 QApplication::restoreOverrideCursor();
3739 //=============================================================================
3743 //=============================================================================
3744 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3746 QApplication::setOverrideCursor( Qt::waitCursor );
3747 Standard_Boolean result;
3748 SMESH_Actor* ac = FindActor( aMesh, result, true );
3750 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3751 anArrayOfIdeces->length(MapIndex.Extent());
3752 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3754 for ( ; ite.More(); ite.Next() ) {
3755 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
3756 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
3759 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3760 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3763 if ( myAutomaticUpdate ) {
3764 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3765 if ( Mesh != NULL ) {
3766 smeshGUI->DisplayActor( Mesh );
3767 smeshGUI->DisplayEdges( Mesh );
3768 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3769 AddActorInSelection( Mesh );
3772 QApplication::restoreOverrideCursor();
3775 //=============================================================================
3779 //=============================================================================
3780 void SMESHGUI::RemoveElement(SMESH_Actor* Mactor, int idelement)
3782 MESSAGE ( " OLD RemoveElement method " )
3783 // int id = Mactor->GetIdVTKElement( idelement );
3784 // MESSAGE ( " RemoveElement id VTK : " << id )
3785 // if ( Mactor->GetMapper() != NULL ) {
3786 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3787 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3789 // int nbCells = ugrid->GetNumberOfCells();
3790 // for ( int i = 0; i < nbCells; i++ ) {
3792 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3793 // ugrid->GetCell(i)->GetPointIds() );
3795 // Mactor->RemoveElement( idelement );
3797 // newUgrid->SetPoints(ugrid->GetPoints());
3799 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3800 // Mapper->SetInput( newUgrid );
3801 // Mactor->DataSource = Mapper->GetInput();
3802 // Mactor->SetMapper(Mapper);
3808 //=============================================================================
3812 //=============================================================================
3813 void SMESHGUI::RemoveElements(SMESH_Actor* Mactor, int number,
3814 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3816 QApplication::setOverrideCursor( Qt::waitCursor );
3818 while ( i <= number ) {
3819 Mactor->RemoveElement( indexes[i-1] );
3822 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3823 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3825 if ( Mactor->GetMapper() != NULL ) {
3826 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3827 SMESH_Grid* newUgrid = SMESH_Grid::New();
3828 newUgrid->CopyMaps(ugrid);
3830 int nbCells = ugrid->GetNumberOfCells();
3831 for ( int i = 0; i < nbCells; i++ ) {
3832 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
3833 if ( idSMESHDSElement != -1 ) {
3834 int newId = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3835 ugrid->GetCell(i)->GetPointIds() );
3836 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
3837 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
3841 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3842 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3844 newUgrid->SetPoints(ugrid->GetPoints());
3846 // Copy new data to the old DatSource: keep the single DataSource for all actors
3847 ugrid->DeepCopy(newUgrid);
3849 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3850 Mapper->SetInput( ugrid );
3851 Mactor->SetMapper(Mapper);
3853 // Commented to avoid multiple viewer updates when called by ReadScript()
3856 QApplication::restoreOverrideCursor();
3859 //=============================================================================
3863 //=============================================================================
3864 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3866 QApplication::setOverrideCursor( Qt::waitCursor );
3867 Standard_Boolean result;
3868 SMESH_Actor* ac = FindActor( aMesh, result, true );
3870 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3871 anArrayOfIdeces->length(MapIndex.Extent());
3872 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3874 for ( ; ite.More(); ite.Next() ) {
3875 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
3876 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
3880 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3881 aMeshEditor->RemoveElements(anArrayOfIdeces);
3884 if ( myAutomaticUpdate ) {
3885 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3886 if ( Mesh != NULL ) {
3887 smeshGUI->DisplayActor( Mesh );
3888 smeshGUI->DisplayEdges( Mesh );
3889 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3890 AddActorInSelection( Mesh );
3896 QApplication::restoreOverrideCursor();
3900 //=============================================================================
3904 //=============================================================================
3905 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3907 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3910 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3911 Standard_Boolean result;
3912 SMESH_Actor* ac = FindActor( aMesh, result, true );
3914 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3915 SMESH_Grid* UGrid = SMESH_Grid::New();
3916 SMESH_Grid* oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
3917 UGrid->CopyMaps(oldGrid);
3919 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3920 gf->SetInput( ac->DataSource );
3922 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3923 Mapper->SetInput( gf->GetOutput() );
3926 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3927 for ( ; ite.More(); ite.Next() ) {
3928 Mapper->GetInput()->ReverseCell( ite.Key() );
3931 UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
3932 int nbCells = Mapper->GetInput()->GetNumberOfCells();
3933 for ( int i = 0; i < nbCells; i++ ) {
3934 UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
3937 // Copy new data to the old DatSource: keep the single DataSource for all actors
3938 oldGrid->DeepCopy(UGrid);
3940 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
3941 //NewMapper->SetInput( UGrid );
3942 NewMapper->SetInput( oldGrid );
3943 NewMapper->Update();
3945 //ac->DataSource = NewMapper->GetInput();
3946 ac->SetMapper( NewMapper );
3948 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3950 QApplication::restoreOverrideCursor();
3954 //=============================================================================
3958 //=============================================================================
3959 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3961 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3964 QApplication::setOverrideCursor( Qt::waitCursor );
3965 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3966 Standard_Boolean result;
3968 SMESH_Actor* ac = FindActor( aMesh, result, true );
3970 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3971 SMESH_Grid* UGrid = SMESH_Grid::New();
3972 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3973 gf->SetInput( ac->DataSource );
3975 vtkExtractEdges *edges = vtkExtractEdges::New();
3976 edges->SetInput( ac->DataSource );
3978 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3979 Mapper->SetInput( edges->GetOutput() );
3982 int nb = Mapper->GetInput()->GetNumberOfCells();
3983 //MESSAGE ( "nb : " << nb )
3985 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3986 for ( ; ite.More(); ite.Next() ) {
3987 vtkCell* StartEdge = Mapper->GetInput()->GetCell(ite.Key());
3988 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
3989 int CellType = StartEdge->GetCellType();
3990 //MESSAGE( "DCQ : Cell Type = " << CellType)
3991 int nbPoints = StartEdge->GetNumberOfPoints();
3993 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
3994 if ( nbPoints == 2 ) {
3995 vtkUnstructuredGrid* StartUGrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
3997 vtkIdList *IdCells = vtkIdList::New();
3998 vtkIdList *IdPoints = StartEdge->GetPointIds();
4002 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),p1);
4003 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),p2);
4005 int idp1 = StartUGrid->FindPoint(p1);
4006 int idp2 = StartUGrid->FindPoint(p2);
4008 StartUGrid->GetPointCells( idp1, IdCells );
4010 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4011 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4013 //MESSAGE ( " pt 0 : " << idp1 )
4014 //MESSAGE ( " pt 1 : " << idp2 )
4016 vtkIdList *IdPts = vtkIdList::New();
4017 if (IdCells->GetNumberOfIds() >= 2) {
4018 int nbCells = IdCells->GetNumberOfIds();
4019 //MESSAGE ( " nbCells : " << nbCells )
4020 for (int j=0; j<nbCells; j++) {
4021 StartUGrid->GetCellPoints( IdCells->GetId(j), IdPts );
4022 if ( IdPts->IsId( idp2 ) == -1 ) {
4023 IdCells->DeleteId( IdCells->GetId(j) );
4028 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4030 vtkIdList *IdPts0 = vtkIdList::New();
4031 vtkIdList *IdPts1 = vtkIdList::New();
4033 if (IdCells->GetNumberOfIds() == 2) {
4034 StartUGrid->GetCellPoints( IdCells->GetId(0), IdPts0 );
4035 StartUGrid->GetCellPoints( IdCells->GetId(1), IdPts1 );
4038 TColStd_MapOfInteger EndMapIndex;
4039 for (int j = 0; j < 3; j++ ) {
4040 if ( IdPts0->GetId(j) != idp1 && IdPts0->GetId(j) != idp2 ) {
4041 EndMapIndex.Add( IdPts0->GetId(j) );
4043 if ( IdPts1->GetId(j) != idp1 && IdPts1->GetId(j) != idp2 ) {
4044 EndMapIndex.Add( IdPts1->GetId(j) );
4048 bool MyAU = myAutomaticUpdate ;
4049 myAutomaticUpdate = false ;
4051 EndMapIndex.Add( idp1 );
4052 TColStd_MapIteratorOfMapOfInteger ite1( EndMapIndex );
4054 while ( ite1.More() ) {
4055 if ( ite1.Key() == idp1 )
4060 bool reverse1 = ( i == 2 );
4061 this->AddFace( aMesh, EndMapIndex, reverse1 );
4063 EndMapIndex.Remove( idp1 );
4064 EndMapIndex.Add( idp2 );
4065 TColStd_MapIteratorOfMapOfInteger ite2( EndMapIndex );
4067 while ( ite2.More() ) {
4068 if ( ite2.Key() == idp2 )
4073 bool reverse2 = ( i == 2 );
4074 this->AddFace( aMesh, EndMapIndex, !(reverse1 == reverse2) );
4076 myAutomaticUpdate = MyAU ;
4077 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4080 TColStd_MapOfInteger StartMapIndex;
4081 StartMapIndex.Add( IdCells->GetId(0) );
4082 StartMapIndex.Add( IdCells->GetId(1) );
4083 this->RemoveElements( aMesh, StartMapIndex );
4091 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4092 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4093 // for ( int i = 0; i < nbCells; i++ ) {
4094 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4097 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4098 // NewMapper->SetInput( UGrid );
4099 // NewMapper->Update();
4101 // ac->DataSource = NewMapper->GetInput();
4102 // ac->SetMapper( NewMapper );
4104 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4106 QApplication::restoreOverrideCursor();
4110 //=============================================================================
4114 //=============================================================================
4115 void SMESHGUI::AddEdges( SMESH_Actor* Mactor, int number,
4116 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4118 QApplication::setOverrideCursor( Qt::waitCursor );
4119 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4120 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4123 while ( i <= number ) {
4124 vtkIdList *Ids = vtkIdList::New();
4125 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4126 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4127 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4128 Mactor->AddElement( indexes[j-1], id );
4132 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4133 EdgeMapper->SetInput( ugrid );
4134 Mactor->DataSource = EdgeMapper->GetInput();
4135 Mactor->SetMapper(EdgeMapper);
4136 QApplication::restoreOverrideCursor();
4139 //=============================================================================
4143 //=============================================================================
4144 void SMESHGUI::AddEdge(SMESH_Actor* Mactor, int idedge, int idnode1, int idnode2)
4146 QApplication::setOverrideCursor( Qt::waitCursor );
4147 MESSAGE ( "SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" << idnode2 )
4148 vtkIdList *Ids = vtkIdList::New();
4149 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4150 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4152 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4153 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4154 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4155 Mactor->AddElement( idedge, id );
4157 MESSAGE ( " Edge VTK id " << id )
4159 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4160 EdgeMapper->SetInput( ugrid );
4161 Mactor->DataSource = EdgeMapper->GetInput();
4162 Mactor->SetMapper(EdgeMapper);
4163 QApplication::restoreOverrideCursor();
4166 //=============================================================================
4170 //=============================================================================
4171 void SMESHGUI::AddTriangles( SMESH_Actor* Mactor, int number,
4172 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4174 QApplication::setOverrideCursor( Qt::waitCursor );
4175 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4176 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4179 while ( i <= number ) {
4180 vtkIdList *Ids = vtkIdList::New();
4181 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4182 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4183 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4184 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4185 Mactor->AddElement( indexes[j-1], id );
4189 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4190 TriMapper->SetInput( ugrid );
4191 Mactor->DataSource = TriMapper->GetInput();
4192 Mactor->SetMapper(TriMapper);
4193 QApplication::restoreOverrideCursor();
4195 void SMESHGUI::AddTriangle(SMESH_Actor* Mactor, int idtri, int idnode1, int idnode2, int idnode3)
4197 QApplication::setOverrideCursor( Qt::waitCursor );
4198 vtkIdList *Ids = vtkIdList::New();
4199 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4200 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4201 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4203 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4204 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4205 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4206 Mactor->AddElement( idtri, id );
4208 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4209 TriMapper->SetInput( ugrid );
4210 Mactor->DataSource = TriMapper->GetInput();
4211 Mactor->SetMapper(TriMapper);
4212 QApplication::restoreOverrideCursor();
4215 //=============================================================================
4219 //=============================================================================
4220 void SMESHGUI::AddQuadrangles( SMESH_Actor* Mactor, int number,
4221 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4223 QApplication::setOverrideCursor( Qt::waitCursor );
4224 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4225 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4228 while ( i <= number ) {
4229 vtkIdList *Ids = vtkIdList::New();
4230 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4231 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4232 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4233 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4234 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4235 Mactor->AddElement( indexes[j-1], id );
4239 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4240 QuadMapper->SetInput( ugrid );
4241 Mactor->DataSource = QuadMapper->GetInput();
4242 Mactor->SetMapper(QuadMapper);
4243 QApplication::restoreOverrideCursor();
4247 //=============================================================================
4251 //=============================================================================
4252 void SMESHGUI::AddQuadrangle(SMESH_Actor* Mactor, int idquad, int idnode1, int idnode2,
4253 int idnode3, int idnode4)
4255 QApplication::setOverrideCursor( Qt::waitCursor );
4256 vtkIdList *Ids = vtkIdList::New();
4257 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4258 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4259 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4260 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4262 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4263 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4264 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4265 Mactor->AddElement( idquad, id );
4267 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4268 QuadMapper->SetInput( ugrid );
4269 Mactor->DataSource = QuadMapper->GetInput();
4270 Mactor->SetMapper(QuadMapper);
4271 QApplication::restoreOverrideCursor();
4275 //=============================================================================
4279 //=============================================================================
4280 void SMESHGUI::AddTetras( SMESH_Actor* Mactor, int number,
4281 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4283 QApplication::setOverrideCursor( Qt::waitCursor );
4284 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4285 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4288 while ( i <= number ) {
4289 vtkIdList *Ids = vtkIdList::New();
4290 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4291 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4292 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4293 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4294 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4295 Mactor->AddElement( indexes[j-1], id );
4299 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4300 TetraMapper->SetInput( ugrid );
4301 Mactor->DataSource = TetraMapper->GetInput();
4302 Mactor->SetMapper(TetraMapper);
4303 QApplication::restoreOverrideCursor();
4307 //=============================================================================
4311 //=============================================================================
4312 void SMESHGUI::AddTetra(SMESH_Actor* Mactor, int idtetra, int idnode1, int idnode2,
4313 int idnode3, int idnode4)
4315 QApplication::setOverrideCursor( Qt::waitCursor );
4316 MESSAGE ( "SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" << idnode2
4317 << ";" << idnode3 << ";" << idnode4 )
4318 vtkIdList *Ids = vtkIdList::New();
4319 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4320 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4321 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4322 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4324 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4325 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4326 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4327 Mactor->AddElement( idtetra, id );
4329 MESSAGE ( " Tetra VTK id " << id )
4331 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4332 TetraMapper->SetInput( ugrid );
4333 Mactor->DataSource = TetraMapper->GetInput();
4334 Mactor->SetMapper(TetraMapper);
4335 QApplication::restoreOverrideCursor();
4339 //=============================================================================
4343 //=============================================================================
4344 void SMESHGUI::AddHexaedres( SMESH_Actor* Mactor, int number,
4345 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4347 QApplication::setOverrideCursor( Qt::waitCursor );
4348 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4349 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4352 while ( i <= number ) {
4353 vtkIdList *Ids = vtkIdList::New();
4354 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4355 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4356 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4357 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4358 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+4] ) );
4359 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+5] ) );
4360 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+6] ) );
4361 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+7] ) );
4362 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4363 Mactor->AddElement( indexes[j-1], id );
4367 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4368 HexaMapper->SetInput( ugrid );
4369 Mactor->DataSource = HexaMapper->GetInput();
4370 Mactor->SetMapper(HexaMapper);
4371 QApplication::restoreOverrideCursor();
4375 //=============================================================================
4379 //=============================================================================
4380 void SMESHGUI::AddHexaedre(SMESH_Actor* Mactor, int idhexa, int idnode1, int idnode2,
4381 int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
4383 QApplication::setOverrideCursor( Qt::waitCursor );
4384 MESSAGE ( "SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" << idnode2
4385 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" << idnode6
4386 << ";" << idnode7 << ";" << idnode8)
4388 vtkIdList *Ids = vtkIdList::New();
4389 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4390 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4391 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4392 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4393 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode5 ) );
4394 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode6 ) );
4395 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode7 ) );
4396 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode8 ) );
4398 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4399 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4400 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4401 Mactor->AddElement( idhexa, id );
4403 MESSAGE ( " Hexa VTK id " << id )
4405 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4406 HexaMapper->SetInput( ugrid );
4407 Mactor->DataSource = HexaMapper->GetInput();
4408 Mactor->SetMapper(HexaMapper);
4409 QApplication::restoreOverrideCursor();
4412 //=====================================================================================
4414 //=====================================================================================
4417 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
4419 return SMESHGUI::OnGUIEvent(theCommandID, parent);
4422 bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4424 return SMESHGUI::OnKeyPress (pe, parent, studyFrame);
4427 bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4429 return SMESHGUI::OnMousePress (pe, parent, studyFrame);
4432 bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4434 return SMESHGUI::OnMouseMove (pe, parent, studyFrame);
4437 bool SetSettings ( QAD_Desktop* parent )
4439 return SMESHGUI::SetSettings( parent );
4442 bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
4443 const QString & theParent, const QString & theObject )
4445 return SMESHGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
4448 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
4450 SMESHGUI::DefinePopup( theContext, theParent, theObject );
4453 bool activeStudyChanged ( QAD_Desktop* parent )
4455 SMESHGUI::activeStudyChanged( parent );
4458 void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
4460 SMESHGUI::BuildPresentation(theIO);
4463 void supportedViewType(int* buffer, int bufferSize)
4465 if (!buffer || !bufferSize) return;
4466 buffer[0] = (int)VIEW_VTK;
4472 //=============================================================================
4476 //=============================================================================
4477 void SMESHGUI::ViewNodes()
4479 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4482 EraseSimulationActors();
4483 mySimulationActors = vtkActorCollection::New();
4484 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4485 vtkActorCollection* theActors = theRenderer->GetActors();
4486 theActors->InitTraversal();
4487 vtkActor *ac = theActors->GetNextActor();
4488 while(!(ac==NULL)) {
4489 if ( ac->IsA("SMESH_Actor") ) {
4490 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
4491 if ( anActor->GetVisibility() == 1 ) {
4492 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4493 gf->SetInput( anActor->DataSource );
4494 vtkMaskPoints *verts = vtkMaskPoints::New();
4495 verts->SetInput(gf->GetOutput());
4496 verts->GenerateVerticesOn();
4497 verts->SetOnRatio(1);
4499 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4500 vertMapper->SetInput(verts->GetOutput());
4501 vertMapper->ScalarVisibilityOff();
4503 vtkActor *vertActor = vtkActor::New();
4504 vertActor->SetMapper(vertMapper);
4507 anActor->GetNodeColor(r, g, b ) ;
4508 vertActor->GetProperty()->SetColor( r, g, b ) ;
4510 vertActor->GetProperty()->SetPointSize( anActor->GetNodeSize() );
4512 vertActor->PickableOff();
4514 mySimulationActors->AddItem( vertActor );
4515 theRenderer->AddActor( vertActor );
4518 ac = theActors->GetNextActor();
4521 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4526 //=============================================================================
4530 //=============================================================================
4531 void SMESHGUI::Control(int theCommandID)
4533 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4536 QApplication::setOverrideCursor( Qt::waitCursor );
4537 DisplayScalarBar( false );
4539 // mpv porting vtk 4.2.2
4540 // vtkScalars *scalars = vtkScalars::New();
4541 vtkIntArray *scalars = vtkIntArray::New();
4542 scalars->SetNumberOfComponents(1);
4544 vtkDataSetMapper* meshMapper = 0;
4545 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4546 int nbSel = Sel->IObjectCount();
4547 Standard_Boolean result;
4548 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
4549 SMESH_Actor* MeshActor = FindActorByEntry(IObject->getEntry(), result, true);
4551 // Mesh may be not updated after Compute
4552 if (!MeshActor->DataSource || !MeshActor->GetMapper()) {
4553 QApplication::restoreOverrideCursor();
4557 bool ValidateScalars = false;
4560 switch (theCommandID)
4562 case 6001: //Length Edges
4564 type = tr( "SMESH_CONTROL_LENGTH_EDGES");
4565 meshMapper = (vtkDataSetMapper*)MeshActor->EdgeDevice->GetMapper();
4566 vtkUnstructuredGrid* grid = (vtkUnstructuredGrid*)meshMapper->GetInput();
4567 MESSAGE ( " init minimum length " << grid->GetNumberOfCells() )
4568 for (int i=0; i<grid->GetNumberOfCells(); i++ ) {
4569 vtkCell* cell = grid->GetCell(i);
4570 float len = SMESHGUI_ComputeScalarValue::LengthEdges(cell);
4571 if (len == 0) continue;
4573 ValidateScalars = true;
4574 // mpv porting vtk 4.2.2
4575 // scalars->InsertScalar(i,len);
4576 scalars->InsertTuple1(i,len);
4579 if (ValidateScalars && (MeshActor->getDisplayMode()!=0))
4580 ChangeRepresentation( MeshActor, 1 );// limitation; in Wireframe, colored edges are not visible
4583 case 6011: // Area Elements
4585 type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
4586 for (int i=0; i< MeshActor->GetMapper()->GetInput()->GetNumberOfCells(); i++ ) {
4587 vtkCell* cell = MeshActor->GetMapper()->GetInput()->GetCell(i);
4588 float area = SMESHGUI_ComputeScalarValue::AreaElements(cell);
4589 if (area == 0) continue;
4591 ValidateScalars = true;
4592 // mpv porting vtk 4.2.2
4593 // scalars->InsertScalar(i,area);
4594 scalars->InsertTuple1(i,area);
4597 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4598 ChangeRepresentation( MeshActor, 1 );
4603 type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
4604 for (int i=0; i< MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4605 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4606 float taper = SMESHGUI_ComputeScalarValue::Taper(cell);
4607 if (taper == 0) continue;
4609 ValidateScalars = true;
4610 // mpv porting vtk 4.2.2
4611 // scalars->InsertScalar(i,taper);
4612 scalars->InsertTuple1(i,taper);
4617 case 6013: // Aspect ratio
4619 type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
4620 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4621 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4622 float aspect = SMESHGUI_ComputeScalarValue::AspectRatio(cell);
4623 if (aspect == 0) continue;
4625 ValidateScalars = true;
4626 // mpv porting vtk 4.2.2
4627 // scalars->InsertScalar(i,aspect);
4628 scalars->InsertTuple1(i,aspect);
4631 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4632 ChangeRepresentation( MeshActor, 1 );
4635 case 6014: // Minimum angle
4637 type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
4638 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4639 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4640 float angle = SMESHGUI_ComputeScalarValue::MinimumAngle(cell);
4641 if (angle == 0) continue;
4643 ValidateScalars = true;
4644 // mpv porting vtk 4.2.2
4645 // scalars->InsertScalar(i,angle);
4646 scalars->InsertTuple1(i,angle);
4649 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4650 ChangeRepresentation( MeshActor, 1 );
4655 type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
4656 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4657 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4658 float Warp = SMESHGUI_ComputeScalarValue::Warp(cell);
4659 if (Warp == 0) continue;
4661 ValidateScalars = true;
4662 // mpv porting vtk 4.2.2
4663 // scalars->InsertScalar(i,Warp);
4664 scalars->InsertTuple1(i,Warp);
4671 type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
4672 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4673 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4674 float angle = SMESHGUI_ComputeScalarValue::Skew(cell);
4675 if (angle == 0) continue;
4677 ValidateScalars = true;
4678 // mpv porting vtk 4.2.2
4679 // scalars->InsertScalar(i,angle);
4680 scalars->InsertTuple1(i,angle);
4687 if ( !ValidateScalars ) {
4688 QApplication::restoreOverrideCursor();
4693 scalars->GetRange(range);
4695 vtkLookupTable* wat = vtkLookupTable::New();
4696 wat->SetRange( range );
4699 scalars->SetLookupTable(wat);
4701 if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
4702 meshMapper->SetScalarModeToUseCellData();
4703 meshMapper->GetInput()->GetCellData()->SetScalars(scalars);
4704 meshMapper->SetScalarRange( range );
4705 meshMapper->ScalarVisibilityOn();
4707 vtkScalarBarActor* aScalarBar = GetScalarBar();
4708 if ( aScalarBar == NULL ) {
4709 aScalarBar = vtkScalarBarActor::New();
4710 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
4711 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
4712 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
4713 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
4714 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
4715 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
4716 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
4717 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
4718 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
4720 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily, Orientation,
4721 Width, Height, NumberOfColors, NumberOfLabels);
4722 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4723 theRenderer->AddActor2D(aScalarBar);
4725 aScalarBar->SetLookupTable( wat );
4726 aScalarBar->SetTitle( type.latin1() );
4730 DisplayScalarBar( true );
4732 QApplication::restoreOverrideCursor();
4736 //=============================================================================
4740 //=============================================================================
4741 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
4742 QString Bold, QString Italic,
4743 QString Shadow, QString FontFamily,
4744 QString Orientation, float Width, float Height,
4745 int NbColors, int NbLabels )
4747 if ( Bold.isNull() || Bold.isEmpty() || (Bold.compare( "true" ) == 0) )
4748 theScalarBar->BoldOn();
4750 theScalarBar->BoldOff();
4752 if ( Italic.isNull() || Italic.isEmpty() || (Italic.compare( "true" ) == 0) )
4753 theScalarBar->ItalicOn();
4755 theScalarBar->ItalicOff();
4757 if ( Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare( "true" ) == 0) )
4758 theScalarBar->ShadowOn();
4760 theScalarBar->ShadowOff();
4762 if ( FontFamily.compare( "Arial" ) == 0 )
4763 theScalarBar->SetFontFamilyToArial();
4764 else if ( FontFamily.compare( "Courier" ) == 0 )
4765 theScalarBar->SetFontFamilyToCourier();
4766 else if ( FontFamily.compare( "Times" ) == 0 )
4767 theScalarBar->SetFontFamilyToTimes();
4769 theScalarBar->SetFontFamilyToArial();
4771 if ( Orientation.isNull() || Orientation.isEmpty() || (Orientation.compare( "Vertical" ) == 0) )
4772 theScalarBar->SetOrientationToVertical();
4774 theScalarBar->SetOrientationToHorizontal();
4777 theScalarBar->SetWidth((Width == 0)? 0.17 : Width);
4778 theScalarBar->SetHeight((Height == 0)? 0.8 : Height);
4780 theScalarBar->SetNumberOfLabels((NbLabels == 0)? 5 : NbLabels);
4781 theScalarBar->SetMaximumNumberOfColors((NbColors == 0)? 64 : NbColors);
4785 //=============================================================================
4789 //=============================================================================
4790 void SMESHGUI::DisplayScalarBar(bool visibility)
4792 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4795 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4796 vtkScalarBarActor* aScalarBar = GetScalarBar();
4798 if ( aScalarBar == NULL ) {
4799 MESSAGE("myScalarBar is NULL");
4804 aScalarBar->VisibilityOn();
4806 aScalarBar->VisibilityOff();
4807 //Turn off mesh coloring (influences on all views)
4808 vtkActorCollection* actorList=theRenderer->GetActors();
4809 actorList->InitTraversal();
4810 vtkActor *ac = actorList->GetNextActor();
4812 if (ac->GetMapper() != NULL) {
4813 ac->GetMapper()->ScalarVisibilityOff();
4815 ac = actorList->GetNextActor();
4817 // Turn off ScalarBar in all views
4818 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
4819 for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
4820 if (aFrame->getTypeView() == VIEW_VTK) {
4821 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
4822 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
4823 actor2DList->InitTraversal();
4824 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
4825 while (aActor2d != NULL) {
4826 if (aActor2d->IsA("vtkScalarBarActor")) {
4827 aActor2d->VisibilityOff();
4830 actor2DList->GetNextActor2D();
4835 myActiveStudy->update3dViewers();
4839 //=============================================================================
4843 //=============================================================================
4844 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
4846 vtkScalarBarActor* aScalarBar = GetScalarBar();
4847 if ( aScalarBar == NULL ) {
4848 MESSAGE("myScalarBar is NULL");
4851 DisplayScalarBar(false);
4853 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
4854 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4855 vtkActorCollection* aActorList = aRenderer->GetActors();
4856 aActorList->InitTraversal();
4857 vtkActor *aActor = aActorList->GetNextActor();
4858 while(aActor != NULL) {
4859 if (aActor->IsA("SMESH_Actor")) {
4860 SMESH_Actor* aMeshActor = SMESH_Actor::SafeDownCast(aActor);
4861 vtkDataSetMapper* aMeshMapper = (vtkDataSetMapper*) (aMeshActor->getMapper());
4862 if ((aMeshMapper != NULL)) {
4863 aMeshMapper->SetScalarRange( MinRange, MaxRange );
4864 aMeshMapper->ScalarVisibilityOn();
4867 aActor = aActorList->GetNextActor();
4869 DisplayScalarBar(true);
4873 //=============================================================================
4877 //=============================================================================
4878 void SMESHGUI::SetDisplaySettings()
4880 EmitSignalDeactivateDialog() ;
4881 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "") ;
4883 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
4884 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
4885 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
4886 QColor color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4887 aDlg->SetColor(1,color);
4889 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
4890 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
4891 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4892 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4893 aDlg->SetColor(2,color);
4895 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4896 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4897 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4898 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4899 aDlg->SetColor(3,color);
4901 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4902 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4903 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4904 color = QColor (SBr.toInt(), SBg.toInt(), SBb.toInt());
4905 aDlg->SetColor(4,color);
4907 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4908 aDlg->SetIntValue(1,intValue.toInt());
4909 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4910 aDlg->SetIntValue(2,intValue.toInt());
4911 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4912 aDlg->SetIntValue(3,intValue.toInt());
4914 if ( aDlg->exec() ) {
4915 QColor colorFill = aDlg->GetColor( 1 );
4916 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4917 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4918 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4920 QColor colorOutline = aDlg->GetColor( 2 );
4921 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4922 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4923 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4925 QColor colorNode = aDlg->GetColor( 3 );
4926 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4927 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4928 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4930 QColor colorBackFace = aDlg->GetColor( 4 );
4931 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4932 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4933 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4935 int width = aDlg->GetIntValue( 1 );
4936 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4938 int nodes_size = aDlg->GetIntValue( 2 );
4939 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4941 int shrink_coeff = aDlg->GetIntValue( 3 );
4942 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4948 //=======================================================================
4949 // function : Parameter()
4950 // purpose : return a parameter (double) from a dialog box
4952 // aValue : is a double used as a default value displayed
4953 // aLabel : is the title for aValue1
4954 // aTitle : is the main title
4955 // bottom : maximum value to be entered
4956 // top : minimum value to be entered
4957 // decimals : number of decimals
4958 //=======================================================================
4959 double SMESHGUI::Parameter( Standard_Boolean& res,
4960 const double aValue,
4963 const double bottom,
4965 const int decimals )
4967 SMESHGUI_aParameterDlg* Dialog =
4968 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4971 bottom, top, decimals,
4973 Dialog->setValue( aValue );
4975 res = ( Dialog->exec() == QDialog::Accepted );
4977 X = Dialog->getDblValue();
4981 //=======================================================================
4982 // function : Parameter()
4983 // purpose : return a parameter (int) from a dialog box
4985 // aValue : is a int used as a default value displayed
4986 // aLabel : is the title for aValue1
4987 // aTitle : is the main title
4988 // bottom : maximum value to be entered
4989 // top : minimum value to be entered
4990 //=======================================================================
4991 int SMESHGUI::Parameter( Standard_Boolean& res,
4998 SMESHGUI_aParameterDlg* Dialog =
4999 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
5004 Dialog->setValue( aValue );
5006 res = ( Dialog->exec() == QDialog::Accepted );
5008 X = Dialog->getIntValue();
5012 //=============================================================================
5016 //=============================================================================
5017 void SMESHGUI::DisplayEdges(SMESH_Actor* ac, bool visibility)
5019 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5021 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5024 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5025 gf->SetInput(ac->DataSource);
5026 vtkFeatureEdges *edges = vtkFeatureEdges::New();
5027 edges->SetInput(gf->GetOutput());
5028 edges->BoundaryEdgesOn();
5029 edges->ManifoldEdgesOn();
5031 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5032 edgeMapper->SetInput(edges->GetOutput());
5033 edgeMapper->ScalarVisibilityOff();
5035 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5036 vtkActorCollection* actorList=theRenderer->GetActors();
5038 int test=actorList->IsItemPresent(ac->EdgeDevice);
5040 vtkProperty* prop = vtkProperty::New();
5041 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5042 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5043 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5044 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5045 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5046 ac->EdgeDevice->SetProperty(prop);
5047 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5048 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5049 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5050 ac->EdgeDevice->SetMapper(edgeMapper);
5052 theRenderer->AddActor(ac->EdgeDevice);
5054 ac->EdgeDevice->SetMapper(edgeMapper);
5055 edgeMapper->Update();
5058 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5059 shrink->SetInput(ac->DataSource);
5060 shrink->SetShrinkFactor(ac->GetShrinkFactor());
5061 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5062 Shrinkgf->SetInput( shrink->GetOutput() );
5063 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5064 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5065 ShrinkEdges->BoundaryEdgesOn();
5066 ShrinkEdges->ManifoldEdgesOn();
5068 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5069 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5070 ShrinkEdgeMapper->ScalarVisibilityOff();
5072 test=actorList->IsItemPresent(ac->EdgeShrinkDevice);
5074 vtkProperty* prop = vtkProperty::New();
5075 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5076 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5077 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5078 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5079 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5080 ac->EdgeShrinkDevice->SetProperty(prop);
5081 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5082 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5083 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5084 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5086 theRenderer->AddActor(ac->EdgeShrinkDevice);
5088 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5089 ShrinkEdgeMapper->Update();
5092 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5097 //=============================================================================
5101 //=============================================================================
5102 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5104 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh( aMesh );
5105 SALOMEDS::GenericAttribute_var anAttr;
5106 SALOMEDS::AttributeName_var aName;
5107 if ( !aSO_M->_is_nil() ) {
5108 if (aSO_M->FindAttribute(anAttr, "AttributeName") ) {
5109 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5110 Standard_Boolean result;
5111 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5113 SMESH_Actor* amesh = SMESH_Actor::New();
5114 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(aSO_M->GetID(),
5118 amesh->setName( aName->Value() );
5119 DisplayActor(amesh, false);
5126 //=============================================================================
5130 //=============================================================================
5131 void SMESHGUI::Update()
5133 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
5134 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5136 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5137 int nbSel = Sel->IObjectCount();
5139 vtkActorCollection* actorList=theRenderer->GetActors();
5140 actorList->InitTraversal();
5141 vtkActor *ac = actorList->GetNextActor();
5142 while(!(ac==NULL)) {
5143 if ( ac->IsA("SMESH_Actor") ) {
5144 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5145 if ( anActor->hasIO() ) {
5146 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5150 ac = actorList->GetNextActor();
5153 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5154 for ( ; It.More(); It.Next() ) {
5155 Handle(SALOME_InteractiveObject) IO = It.Value();
5159 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5162 QApplication::restoreOverrideCursor();
5166 //=============================================================================
5170 //=============================================================================
5171 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject)& IO)
5173 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5176 if ( IO->hasEntry() ) {
5177 Standard_Boolean res;
5178 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh( IO, res );
5180 SMESH_Actor* ac = FindActorByEntry( IO->getEntry(), res, false );
5182 // Check whether the actor belongs to the active view
5183 VTKViewer_RenderWindowInteractor* rwInter =
5184 ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5186 // The actor belongs to inactive view -> create a copy and display it in the active view
5187 if (!rwInter->isInViewer(IO)) {
5188 SMESH_Actor* acCopy = SMESH_Actor::New();
5189 acCopy->ShallowCopy(ac);
5191 smeshGUI->DisplayActor( acCopy, false );
5193 ac = ReadScript( aMesh );
5200 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
5208 //=============================================================================
5212 //=============================================================================
5213 vtkActor* SMESHGUI::SimulationMoveNode(SMESH_Actor* Mactor, int idnode)
5215 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5218 mySimulationActors = vtkActorCollection::New();
5219 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5221 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5222 vtkIdList *IdCells = vtkIdList::New();
5223 ugrid->GetPointCells( idnode, IdCells );
5225 vtkPoints *Pts = vtkPoints::New();
5226 Pts = ugrid->GetPoints();
5228 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
5229 ugridSimulation->SetPoints( Pts );
5230 vtkIdList *IdPts = vtkIdList::New();
5231 for (int j=0; j<IdCells->GetNumberOfIds(); j++) {
5232 ugrid->GetCellPoints( IdCells->GetId(j), IdPts );
5233 ugridSimulation->InsertNextCell( ugrid->GetCellType( IdCells->GetId(j) ), IdPts );
5236 vtkProperty* prop = vtkProperty::New();
5237 prop->SetColor( 1., 0., 0. );
5238 prop->SetRepresentationToWireframe();
5240 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
5241 if ( Edgewidth == 0 )
5243 prop->SetLineWidth( Edgewidth+1 );
5245 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5246 Mapper->SetInput( ugridSimulation );
5247 vtkActor* ac = vtkActor::New();
5248 ac->SetMapper( Mapper );
5249 ac->SetProperty( prop );
5251 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
5252 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
5254 mySimulationActors->AddItem( ac );
5255 theRenderer->AddActor( ac );
5257 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5264 //=============================================================================
5268 //=============================================================================
5269 void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5271 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5274 EraseSimulationActors();
5275 mySimulationActors = vtkActorCollection::New();
5276 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5277 Standard_Boolean result;
5278 SMESH_Actor* ac = FindActor( aMesh, result, true );
5281 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5282 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5284 vtkPoints *Pts = ugrid->GetPoints();
5285 vtkPoints *newPts = vtkPoints::New();
5286 int nbPts = Pts->GetNumberOfPoints();
5287 for ( int i = 0; i < nbPts; i++ ) {
5288 newPts->InsertPoint(i, Pts->GetPoint(i) );
5291 newugrid->SetPoints(newPts);
5292 newugrid->GetPoints()->InsertNextPoint( x, y, z );
5294 vtkMaskPoints* verts = vtkMaskPoints::New();
5295 verts->SetInput(newugrid);
5296 verts->SetGenerateVertices(1);
5297 verts->SetOnRatio(1);
5299 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
5300 vertMapper->SetInput( verts->GetOutput() );
5301 vertMapper->ScalarVisibilityOff();
5303 vtkActor* node = vtkActor::New();
5304 node->SetMapper( vertMapper );
5306 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5307 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5308 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5309 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5310 if ( !nodecolor.isValid() )
5311 nodecolor = QColor(0.,1.,0.);
5313 node->GetProperty()->SetColor( float(nodecolor.red())/255.,
5314 float(nodecolor.green())/255.,
5315 float(nodecolor.blue())/255.);
5317 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
5321 node->GetProperty()->SetPointSize( intValue );
5323 node->VisibilityOn();
5325 mySimulationActors->AddItem( node );
5326 theRenderer->AddActor(node);
5329 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5333 //=============================================================================
5337 //=============================================================================
5338 void SMESHGUI::DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z)
5340 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5343 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5344 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
5345 pt[0] = x; pt[1] = y; pt[2] = z;
5347 ac->GetMapper()->ImmediateModeRenderingOn();
5348 ac->GetProperty()->SetRepresentationToWireframe();
5350 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5356 //=============================================================================
5360 //=============================================================================
5361 void SMESHGUI::MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z)
5363 Standard_Boolean result;
5365 SMESH_Actor* MeshActor = FindActor(aMesh, result, true);
5371 //=============================================================================
5375 //=============================================================================
5376 void SMESHGUI::ScalarVisibilityOff()
5378 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5381 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5382 vtkActorCollection* actorList=theRenderer->GetActors();
5384 actorList->InitTraversal();
5385 vtkActor *ac = actorList->GetNextActor();
5386 while(!(ac==NULL)) {
5387 if ( ac->IsA("SMESH_Actor") ) {
5388 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5389 if ( anActor->GetVisibility() == 1 ) {
5390 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (anActor->getMapper());
5391 meshMapper->ScalarVisibilityOff();
5392 meshMapper->SetInput( anActor->DataSource );
5393 ChangeRepresentation( anActor, anActor->getDisplayMode() );
5396 ac = actorList->GetNextActor();
5399 theRenderer->Render();
5403 //=============================================================================
5407 //=============================================================================
5408 void SMESHGUI::DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5410 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5413 EraseSimulationActors();
5414 mySimulationActors = vtkActorCollection::New();
5415 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5416 Standard_Boolean result;
5417 SMESH_Actor* ac = FindActor( aMesh, result, true );
5419 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5423 vtkIdList *Ids = vtkIdList::New();
5424 for ( ; ite.More(); ite.Next() ) {
5425 idNodes[i] = ite.Key();
5429 Ids->InsertId( 0, idNodes[0] );
5430 pts[0] = idNodes[0];
5431 Ids->InsertId( 1, idNodes[1] );
5432 pts[1] = idNodes[1];
5434 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5435 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5436 newugrid->SetPoints( ugrid->GetPoints() ) ;
5437 newugrid->InsertNextCell(VTK_LINE, 2, pts);
5439 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5440 Mapper->SetInput( newugrid );
5443 vtkActor* edge = vtkActor::New();
5444 edge->SetMapper( Mapper );
5445 edge->SetProperty( ac->GetProperty() );
5446 edge->SetBackfaceProperty( ac->GetBackfaceProperty() );
5447 edge->VisibilityOn();
5448 mySimulationActors->AddItem( edge );
5449 theRenderer->AddActor(edge);
5452 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5457 //=============================================================================
5461 //=============================================================================
5462 void SMESHGUI::DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5464 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5467 EraseSimulationActors();
5468 mySimulationActors = vtkActorCollection::New();
5469 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5470 Standard_Boolean result;
5471 SMESH_Actor* ac = FindActor( aMesh, result, true );
5473 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5477 vtkIdList *Ids = vtkIdList::New();
5478 for ( ; ite.More(); ite.Next() ) {
5479 idNodes[i] = ite.Key();
5484 Ids->InsertId( 0, idNodes[2] );
5485 pts[0] = idNodes[2];
5486 Ids->InsertId( 1, idNodes[1] );
5487 pts[1] = idNodes[1];
5488 Ids->InsertId( 2, idNodes[0] );
5489 pts[2] = idNodes[0];
5491 Ids->InsertId( 0, idNodes[0] );
5492 pts[0] = idNodes[0];
5493 Ids->InsertId( 1, idNodes[1] );
5494 pts[1] = idNodes[1];
5495 Ids->InsertId( 2, idNodes[2] );
5496 pts[2] = idNodes[2];
5498 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5499 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5500 newugrid->SetPoints( ugrid->GetPoints() ) ;
5501 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
5503 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5504 Mapper->SetInput( newugrid );
5507 vtkActor* tri = vtkActor::New();
5508 tri->SetMapper( Mapper );
5509 tri->SetProperty( ac->GetProperty() );
5510 tri->SetBackfaceProperty( ac->GetBackfaceProperty() );
5511 tri->VisibilityOn();
5512 mySimulationActors->AddItem( tri );
5513 theRenderer->AddActor(tri);
5516 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5521 //=============================================================================
5525 //=============================================================================
5526 void SMESHGUI::DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5528 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5531 EraseSimulationActors();
5532 mySimulationActors = vtkActorCollection::New();
5533 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5534 Standard_Boolean result;
5535 SMESH_Actor* ac = FindActor( aMesh, result, true );
5537 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5540 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5543 vtkIdList *Ids = vtkIdList::New();
5544 for ( ; ite.More(); ite.Next() ) {
5545 idNodes[i] = ite.Key();
5549 float *p0 = ugrid->GetPoint(idNodes[0]);
5550 float *p1 = ugrid->GetPoint(idNodes[1]);
5551 float *p2 = ugrid->GetPoint(idNodes[2]);
5552 float *p3 = ugrid->GetPoint(idNodes[3]);
5554 gp_Pnt P0(p0[0],p0[1],p0[2]);
5556 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5557 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5558 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5560 gp_Vec Cross1 = V1 ^ V2;
5561 gp_Vec Cross2 = V2 ^ V3;
5564 if ( Cross1.Dot(Cross2) < 0 ) {
5565 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5566 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5570 if ( Cross1.Dot(Cross2) < 0 ) {
5572 idNodes[2] = idNodes[3];
5576 idNodes[1] = idNodes[2];
5582 Ids->InsertId( 0, idNodes[3] );
5583 Ids->InsertId( 1, idNodes[2] );
5584 Ids->InsertId( 2, idNodes[1] );
5585 Ids->InsertId( 3, idNodes[0] );
5587 Ids->InsertId( 0, idNodes[0] );
5588 Ids->InsertId( 1, idNodes[1] );
5589 Ids->InsertId( 2, idNodes[2] );
5590 Ids->InsertId( 3, idNodes[3] );
5593 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5594 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5595 newugrid->SetPoints( ugrid->GetPoints() ) ;
5596 newugrid->InsertNextCell(VTK_QUAD, Ids);
5598 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5599 Mapper->SetInput( newugrid );
5602 vtkActor* quad = vtkActor::New();
5603 quad->SetMapper( Mapper );
5604 quad->SetProperty( ac->GetProperty() );
5605 quad->SetBackfaceProperty( ac->GetBackfaceProperty() );
5606 quad->VisibilityOn();
5607 mySimulationActors->AddItem( quad );
5608 theRenderer->AddActor(quad);
5610 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5615 //=============================================================================
5619 //=============================================================================
5620 void SMESHGUI::DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5622 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5625 EraseSimulationActors();
5626 mySimulationActors = vtkActorCollection::New();
5627 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5628 Standard_Boolean result;
5629 SMESH_Actor* ac = FindActor( aMesh, result, true );
5631 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5634 vtkIdList *Ids = vtkIdList::New();
5635 for ( ; ite.More(); ite.Next() ) {
5636 idNodes[i] = ite.Key();
5640 Ids->InsertId( 0, idNodes[0] );
5641 Ids->InsertId( 1, idNodes[1] );
5642 Ids->InsertId( 2, idNodes[2] );
5643 Ids->InsertId( 3, idNodes[3] );
5645 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5646 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5647 newugrid->SetPoints( ugrid->GetPoints() ) ;
5648 newugrid->InsertNextCell(VTK_TETRA, Ids);
5650 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5651 Mapper->SetInput( newugrid );
5654 vtkActor* tetra = vtkActor::New();
5655 tetra->SetMapper( Mapper );
5656 tetra->SetProperty( ac->GetProperty() );
5657 tetra->SetBackfaceProperty( ac->GetBackfaceProperty() );
5658 tetra->VisibilityOn();
5659 mySimulationActors->AddItem( tetra );
5660 theRenderer->AddActor(tetra);
5662 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5667 //=============================================================================
5671 //=============================================================================
5672 void SMESHGUI::DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5674 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5677 EraseSimulationActors();
5678 mySimulationActors = vtkActorCollection::New();
5679 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5680 Standard_Boolean result;
5681 SMESH_Actor* ac = FindActor( aMesh, result, true );
5683 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5686 vtkIdList *Ids = vtkIdList::New();
5687 for ( ; ite.More(); ite.Next() ) {
5688 idNodes[i] = ite.Key();
5692 Ids->InsertId( 0, idNodes[0] );
5693 Ids->InsertId( 1, idNodes[1] );
5694 Ids->InsertId( 2, idNodes[2] );
5695 Ids->InsertId( 3, idNodes[3] );
5696 Ids->InsertId( 4, idNodes[4] );
5697 Ids->InsertId( 5, idNodes[5] );
5698 Ids->InsertId( 6, idNodes[6] );
5699 Ids->InsertId( 7, idNodes[7] );
5701 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5702 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5703 newugrid->SetPoints( ugrid->GetPoints() ) ;
5704 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5706 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5707 Mapper->SetInput( newugrid );
5710 vtkActor* hexa = vtkActor::New();
5711 hexa->SetMapper( Mapper );
5712 hexa->SetProperty( ac->GetProperty() );
5713 hexa->SetBackfaceProperty( ac->GetBackfaceProperty() );
5714 hexa->VisibilityOn();
5715 mySimulationActors->AddItem( hexa );
5716 theRenderer->AddActor(hexa);
5718 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5723 //=============================================================================
5727 //=============================================================================
5728 void SMESHGUI::AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5730 QApplication::setOverrideCursor( Qt::waitCursor );
5731 Standard_Boolean result;
5732 SMESH_Actor* ac = FindActor( aMesh, result, true );
5734 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5735 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5736 anArrayOfIdeces->length(MapIndex.Extent());
5739 for ( ; ite.More(); ite.Next() ) {
5740 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5745 if ( MapIndex.Extent() == 4 ) {
5748 TColStd_MapIteratorOfMapOfInteger ite1( MapIndex );
5749 for ( ; ite1.More(); ite1.Next() ) {
5750 idNodes[i] = ite1.Key();
5754 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5755 float *p0 = ugrid->GetPoint(idNodes[0]);
5756 float *p1 = ugrid->GetPoint(idNodes[1]);
5757 float *p2 = ugrid->GetPoint(idNodes[2]);
5758 float *p3 = ugrid->GetPoint(idNodes[3]);
5760 gp_Pnt P0(p0[0],p0[1],p0[2]);
5762 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5763 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5764 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5766 gp_Vec Cross1 = V1 ^ V2;
5767 gp_Vec Cross2 = V2 ^ V3;
5769 if ( Cross1.Dot(Cross2) < 0 ) {
5771 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5772 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5776 if ( Cross1.Dot(Cross2) < 0 ) {
5777 tmp = anArrayOfIdeces[2];
5778 anArrayOfIdeces[2] = anArrayOfIdeces[3];
5779 anArrayOfIdeces[3] = tmp;
5781 tmp = anArrayOfIdeces[1];
5782 anArrayOfIdeces[1] = anArrayOfIdeces[2];
5783 anArrayOfIdeces[2] = tmp;
5790 for (i=0; i < (MapIndex.Extent()/2); i++) {
5791 tmp = anArrayOfIdeces[i];
5792 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent()-i-1];
5793 anArrayOfIdeces[MapIndex.Extent()-i-1] = tmp;
5796 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5797 aMeshEditor->AddFace(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();
5812 //=============================================================================
5816 //=============================================================================
5817 void SMESHGUI::AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5819 QApplication::setOverrideCursor( Qt::waitCursor );
5820 Standard_Boolean result;
5821 SMESH_Actor* ac = FindActor( aMesh, result, true );
5823 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5824 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5825 anArrayOfIdeces->length(MapIndex.Extent());
5828 for ( ; ite.More(); ite.Next() ) {
5829 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5833 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5834 aMeshEditor->AddVolume(anArrayOfIdeces);
5836 if ( myAutomaticUpdate ) {
5837 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5838 if ( Mesh != NULL ) {
5839 smeshGUI->DisplayActor( Mesh );
5840 smeshGUI->DisplayEdges( Mesh );
5841 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5842 AddActorInSelection( Mesh );
5845 QApplication::restoreOverrideCursor();
5849 //=============================================================================
5853 //=============================================================================
5854 void SMESHGUI::AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5856 QApplication::setOverrideCursor( Qt::waitCursor );
5857 Standard_Boolean result;
5858 SMESH_Actor* ac = FindActor( aMesh, result, true );
5860 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5861 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5862 anArrayOfIdeces->length(MapIndex.Extent());
5865 for ( ; ite.More(); ite.Next() ) {
5866 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5870 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5871 aMeshEditor->AddEdge(anArrayOfIdeces);
5873 if ( myAutomaticUpdate ) {
5874 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5875 if ( Mesh != NULL ) {
5876 smeshGUI->DisplayActor( Mesh );
5877 smeshGUI->DisplayEdges( Mesh );
5878 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5879 AddActorInSelection( Mesh );
5882 QApplication::restoreOverrideCursor();
5885 //=============================================================================
5889 //=============================================================================
5890 void SMESHGUI::AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5892 QApplication::setOverrideCursor( Qt::waitCursor );
5893 Standard_Boolean result;
5894 SMESH_Actor* ac = FindActor( aMesh, result, true );
5896 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5897 aMeshEditor->AddNode(x,y,z);
5899 if ( myAutomaticUpdate ) {
5900 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5901 if ( Mesh != NULL ) {
5902 smeshGUI->DisplayActor( Mesh );
5903 smeshGUI->DisplayEdges( Mesh );
5904 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5905 AddActorInSelection( Mesh );
5909 QApplication::restoreOverrideCursor();
5912 //=============================================================================
5916 //=============================================================================
5917 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor *ac)
5919 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5922 EraseSimulationActors();
5923 mySimulationActors2D = vtkActor2DCollection::New();
5925 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5927 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
5928 gs2->SetGlyphTypeToTriangle();
5931 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
5932 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
5933 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
5935 legend->SetNumberOfEntries(4);
5936 legend->SetEntryString( 0, tr( "SMESH_BOUNDARYEDGES" ) );
5937 legend->SetEntrySymbol( 0, gs2->GetOutput() );
5938 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.) );
5939 legend->SetEntryString( 1, tr( "SMESH_MANIFOLDEDGES" ) );
5940 legend->SetEntrySymbol( 1, gs2->GetOutput() );
5941 legend->SetEntryColor(1, ac->GetMapper()->GetLookupTable()->GetColor(0.666667) );
5942 legend->SetEntryString( 2, tr( "SMESH_NONMANIFOLDEDGES" ) );
5943 legend->SetEntrySymbol( 2, gs2->GetOutput() );
5944 legend->SetEntryColor(2, ac->GetMapper()->GetLookupTable()->GetColor(0.222222) );
5945 legend->SetEntryString( 3, tr( "SMESH_FEATUREEDGES" ) );
5946 legend->SetEntrySymbol( 3, gs2->GetOutput() );
5947 legend->SetEntryColor(3, ac->GetMapper()->GetLookupTable()->GetColor(0.444444) );
5948 legend->SetPadding( 5 );
5949 // legend->GetProperty()->SetColor();
5951 mySimulationActors2D->AddItem( legend );
5952 theRenderer->AddActor2D( legend );
5955 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5958 //===============================================================================
5959 // function : OnEditDelete()
5961 //===============================================================================
5962 void SMESHGUI::OnEditDelete()
5964 if ( QAD_MessageBox::warn2
5965 ( QAD_Application::getDesktop(),
5966 tr ("SMESH_WRN_WARNING"),
5967 tr ("SMESH_REALLY_DELETE"),
5968 tr ("SMESH_BUT_YES"), tr ("SMESH_BUT_NO"), 1, 0, 0 ) != 1 )
5971 int nbSf = myActiveStudy->getStudyFramesCount();
5973 Standard_Boolean found;
5974 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5975 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
5976 SALOMEDS::GenericAttribute_var anAttr;
5977 SALOMEDS::AttributeIOR_var anIOR;
5979 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5980 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5981 for(;It.More();It.Next()) {
5982 Handle(SALOME_InteractiveObject) IObject = It.Value();
5983 if ( IObject->hasEntry() ) {
5984 SALOMEDS::SObject_var SO = myStudy->FindObjectID( IObject->getEntry() );
5986 /* Erase child graphical objects */
5987 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5988 for (; it->More();it->Next()) {
5989 SALOMEDS::SObject_var CSO= it->Value();
5990 if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
5991 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5993 for ( int i = 0; i < nbSf; i++ ) {
5994 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5995 if ( sf->getTypeView() == VIEW_VTK ) {
5996 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5997 SMESH_Actor* ac = smeshGUI->FindActorByEntry( CSO->GetID(), found, false );
5999 Renderer->RemoveActor(ac->EdgeDevice);
6000 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6001 Renderer->RemoveActor(ac);
6008 /* Erase main graphical object */
6009 for ( int i = 0; i < nbSf; i++ ) {
6010 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
6011 if ( sf->getTypeView() == VIEW_VTK ) {
6012 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6013 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
6014 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), found, false );
6016 Renderer->RemoveActor(ac->EdgeDevice);
6017 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6019 myRenderInter->Remove( IObject );
6023 /* Erase objects in Study */
6024 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
6025 if ( !obj->_is_nil() ) {
6026 QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
6028 aStudyBuilder->RemoveObject(obj);
6032 } /* IObject->hasEntry() */
6035 /* Clear any previous selection */
6036 Sel->ClearIObjects() ;
6037 myActiveStudy->updateObjBrowser();