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 QAD_Desktop* PP = QAD_Application::getDesktop() ;
404 x = abs ( PP->x() + PP->size().width() - aDlg->size().width() - 10 ) ;
405 y = abs ( PP->y() + PP->size().height() - aDlg->size().height() - 10 ) ;
410 //=============================================================================
414 //=============================================================================
415 void SMESHGUI::EraseSimulationActors()
417 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
418 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
419 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
421 if ( mySimulationActors != NULL ) {
423 mySimulationActors->InitTraversal();
424 vtkActor *ac = mySimulationActors->GetNextActor();
426 theRenderer->RemoveActor(ac);
427 ac = mySimulationActors->GetNextActor();
429 mySimulationActors->RemoveAllItems();
431 if ( mySimulationActors2D != NULL ) {
432 mySimulationActors2D->InitTraversal();
433 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
435 theRenderer->RemoveActor2D(ac);
436 ac = mySimulationActors2D->GetNextActor2D();
438 mySimulationActors2D->RemoveAllItems();
444 //=============================================================================
448 //=============================================================================
449 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
452 if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
453 SMESH::SMESH_Mesh_var aMesh = myComponentMesh->Init( myComponentGeom, myStudyId, aShape);
455 if ( !aMesh->_is_nil() ) {
456 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh ( aMesh );
457 myStudyAPI.SetName( SM, NameMesh );
459 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
460 // not after loading from file, so let's use more reliable way to retrieve SObject
461 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
462 SALOMEDS::SObject_var SObject = myStudy->FindObjectIOR(ShapeIOR);
463 if ( !SObject->_is_nil() && !SM->_is_nil() ) {
464 myStudyAPI.SetShape( SM, SObject );
466 return SMESH::SMESH_Mesh::_narrow(aMesh);
470 catch (const SALOME::SALOME_Exception& S_ex) {
471 QtCatchCorbaException(S_ex);
473 myActiveStudy->updateObjBrowser(true);
474 return SMESH::SMESH_Mesh::_nil();
477 //=============================================================================
481 //=============================================================================
482 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh, GEOM::GEOM_Shape_ptr aShape, QString NameMesh )
485 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
486 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
487 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
488 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
490 if ( !SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() && !aSubMesh->_is_nil() && !aMesh->_is_nil() ) {
491 SALOMEDS::SObject_var SO = myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh, aShape->ShapeType() );
492 myStudyAPI.SetName(SO, NameMesh);
494 SMESH_Actor* amesh = SMESH_Actor::New();
495 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(SO->GetID(),
499 amesh->setName( strdup(NameMesh) );
500 DisplayActor(amesh, false);
501 return SMESH::SMESH_subMesh::_narrow( aSubMesh );
504 catch (const SALOME::SALOME_Exception& S_ex) {
505 QtCatchCorbaException(S_ex);
507 myActiveStudy->updateObjBrowser(true);
508 return SMESH::SMESH_subMesh::_nil();
512 //=============================================================================
516 //=============================================================================
517 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis( QString TypeHypothesis,
518 QString NameHypothesis )
520 SMESH::SMESH_Hypothesis_var Hyp;
522 Hyp = myComponentMesh->CreateHypothesis( TypeHypothesis, myStudyId );
523 if ( !Hyp->_is_nil() ) {
524 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis( Hyp );
525 myStudyAPI.SetName( SHyp, NameHypothesis);
528 catch (const SALOME::SALOME_Exception& S_ex) {
529 QtCatchCorbaException(S_ex);
532 return SMESH::SMESH_Hypothesis::_narrow( Hyp );
535 //=============================================================================
539 //=============================================================================
540 void SMESHGUI::AddHypothesisOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
542 if ( !aMesh->_is_nil() ) {
543 QApplication::setOverrideCursor( Qt::waitCursor );
544 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
545 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
547 bool res = aMesh->AddHypothesis( aShape, aHyp );
549 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
550 if ( !SM->_is_nil() && !SH->_is_nil() ) {
551 myStudyAPI.SetHypothesis( SM, SH );
552 myStudyAPI.ModifiedMesh( SM, false );
554 QApplication::restoreOverrideCursor();
556 QApplication::restoreOverrideCursor();
557 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
558 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
561 catch (const SALOME::SALOME_Exception& S_ex) {
562 QtCatchCorbaException(S_ex);
565 myActiveStudy->updateObjBrowser(true);
566 QApplication::restoreOverrideCursor();
569 //=============================================================================
573 //=============================================================================
574 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( const Handle(SALOME_InteractiveObject)& IObject )
576 if ( IObject->hasReference() ) {
577 SMESH::SMESH_Hypothesis_var anHyp;
578 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getEntry() );
579 SALOMEDS::GenericAttribute_var anAttr;
580 SALOMEDS::AttributeIOR_var anIOR;
582 if ( !SO_Hypothesis->_is_nil() ) {
583 QApplication::setOverrideCursor( Qt::waitCursor );
584 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
585 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
586 anHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()) );
589 SALOMEDS::SObject_var SO_Applied_Hypothesis = smeshGUI->myStudy->FindObjectID(IObject->getReference());
590 if ( !SO_Applied_Hypothesis->_is_nil() ) {
591 SALOMEDS::SObject_var MorSM = smeshGUI->myStudyAPI.GetMeshOrSubmesh( SO_Applied_Hypothesis );
592 if ( !MorSM->_is_nil() ) {
593 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
595 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
596 if ( !aShape->_is_nil() ) {
597 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
598 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
599 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
600 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
601 if ( !aMesh->_is_nil() ) {
602 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
604 QApplication::restoreOverrideCursor();
605 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
606 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
608 } else if ( !aSubMesh->_is_nil() ) {
609 aMesh = aSubMesh->GetFather();
610 if ( !aMesh->_is_nil() ) {
611 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
613 QApplication::restoreOverrideCursor();
614 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
615 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
619 if ( myAutomaticUpdate ) {
620 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
621 if ( Mesh != NULL ) {
625 DisplayActor( Mesh );
626 DisplayEdges( Mesh );
627 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
633 smeshGUI->myStudyAPI.UnSetHypothesis( SO_Applied_Hypothesis );
636 } else if ( IObject->hasEntry() ) {
637 MESSAGE ( "IObject entry " << IObject->getEntry() )
639 QApplication::restoreOverrideCursor();
642 //=============================================================================
646 //=============================================================================
647 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh( SALOMEDS::SObject_ptr MorSM, SMESH::SMESH_Hypothesis_ptr anHyp )
649 SALOMEDS::SObject_var AHR, aRef;
650 SALOMEDS::GenericAttribute_var anAttr;
651 SALOMEDS::AttributeIOR_var anIOR;
653 if ( !MorSM->_is_nil() ) {
654 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( MorSM );
655 if ( !aShape->_is_nil() ) {
656 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
657 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
658 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
659 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
660 if ( !aMesh->_is_nil() ) {
661 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
663 QApplication::restoreOverrideCursor();
664 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
665 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
667 } else if ( !aSubMesh->_is_nil() ) {
668 aMesh = aSubMesh->GetFather();
669 if ( !aMesh->_is_nil() ) {
670 bool res = aMesh->RemoveHypothesis( aShape, anHyp );
672 QApplication::restoreOverrideCursor();
673 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
674 tr ("SMESH_WRN_HYPOTHESIS_NOTEXIST"), tr ("SMESH_BUT_YES") );
678 if ( myAutomaticUpdate ) {
679 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
680 if ( Mesh != NULL ) {
684 DisplayActor( Mesh );
685 DisplayEdges( Mesh );
686 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
692 if ( MorSM->FindSubObject (2, AHR)) {
693 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
694 for (; it->More();it->Next()) {
695 SALOMEDS::SObject_var Obj = it->Value();
696 if ( Obj->ReferencedObject(aRef) ) {
697 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
698 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
699 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
700 smeshGUI->myStudyAPI.UnSetHypothesis( Obj );
707 if ( MorSM->FindSubObject (3, AHR)) {
708 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
709 for (; it->More();it->Next()) {
710 SALOMEDS::SObject_var Obj = it->Value();
711 if ( Obj->ReferencedObject(aRef) ) {
712 if (aRef->FindAttribute(anAttr, "AttributeIOR")) {
713 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
714 if ( strcmp( anIOR->Value(), _orb->object_to_string(anHyp) ) == 0 ) {
715 smeshGUI->myStudyAPI.UnSetAlgorithm( Obj );
722 smeshGUI->myStudyAPI.ModifiedMesh( MorSM, false );
724 QApplication::restoreOverrideCursor();
727 //=============================================================================
731 //=============================================================================
732 void SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
734 if ( !aMesh->_is_nil() ) {
735 QApplication::setOverrideCursor( Qt::waitCursor );
736 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
737 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
739 bool res = aMesh->AddHypothesis( aShape, aHyp );
741 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
742 if ( !SM->_is_nil() && !SH->_is_nil() ) {
743 myStudyAPI.SetAlgorithms( SM, SH );
744 myStudyAPI.ModifiedMesh( SM, false );
747 QApplication::restoreOverrideCursor();
748 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
749 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
752 catch (const SALOME::SALOME_Exception& S_ex) {
753 QtCatchCorbaException(S_ex);
756 myActiveStudy->updateObjBrowser(true);
757 QApplication::restoreOverrideCursor();
760 //=============================================================================
764 //=============================================================================
765 void SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
767 if ( !aSubMesh->_is_nil() ) {
768 QApplication::setOverrideCursor( Qt::waitCursor );
770 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
771 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
772 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
773 if ( !aMesh->_is_nil() ) {
774 bool res = aMesh->AddHypothesis( aShape, aHyp );
776 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
777 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
778 myStudyAPI.SetHypothesis( SsubM, SH );
779 myStudyAPI.ModifiedMesh( SsubM, false );
782 QApplication::restoreOverrideCursor();
783 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
784 tr ("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
788 catch (const SALOME::SALOME_Exception& S_ex) {
789 QtCatchCorbaException(S_ex);
792 myActiveStudy->updateObjBrowser(true);
793 QApplication::restoreOverrideCursor();
796 //=============================================================================
800 //=============================================================================
801 void SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh, SMESH::SMESH_Hypothesis_ptr aHyp )
803 if ( !aSubMesh->_is_nil() ) {
804 QApplication::setOverrideCursor( Qt::waitCursor );
806 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
807 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh( aSubMesh );
808 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
809 if ( !aMesh->_is_nil() ) {
810 bool res = aMesh->AddHypothesis( aShape, aHyp );
812 SALOMEDS::SObject_var SH = myStudyAPI.FindHypothesisOrAlgorithms( aHyp );
813 if ( !SsubM->_is_nil() && !SH->_is_nil() ) {
814 myStudyAPI.SetAlgorithms( SsubM, SH );
815 myStudyAPI.ModifiedMesh( SsubM, false );
818 QApplication::restoreOverrideCursor();
819 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
820 tr ("SMESH_WRN_ALGORITHM_ALREADYEXIST"), tr ("SMESH_BUT_YES") );
824 catch (const SALOME::SALOME_Exception& S_ex) {
825 QtCatchCorbaException(S_ex);
828 myActiveStudy->updateObjBrowser(true);
829 QApplication::restoreOverrideCursor();
832 //=============================================================================
836 //=============================================================================
837 void SMESHGUI::CreateAlgorithm( QString TypeAlgo, QString NameAlgo )
839 SMESH::SMESH_Hypothesis_var Hyp;
841 if ( TypeAlgo.compare("Regular_1D") == 0 )
842 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
843 else if ( TypeAlgo.compare("MEFISTO_2D") == 0 )
844 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
845 else if ( TypeAlgo.compare("Quadrangle_2D") == 0 )
846 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
847 else if ( TypeAlgo.compare("Hexa_3D") == 0 )
848 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
849 else if ( TypeAlgo.compare("Tetra_3D") == 0 )
850 Hyp = myComponentMesh->CreateHypothesis( TypeAlgo, myStudyId );
852 if ( !Hyp->_is_nil() ) {
853 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
854 myStudyAPI.SetName( SHyp, NameAlgo);
857 catch (const SALOME::SALOME_Exception& S_ex) {
858 QtCatchCorbaException(S_ex);
860 myActiveStudy->updateObjBrowser(true);
864 //=============================================================================
868 //=============================================================================
869 void SMESHGUI::CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length )
871 QApplication::setOverrideCursor( Qt::waitCursor );
873 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
874 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
875 if ( !LL->_is_nil() )
876 LL->SetLength( Length );
878 catch (const SALOME::SALOME_Exception& S_ex) {
879 QtCatchCorbaException(S_ex);
881 myActiveStudy->updateObjBrowser(true);
882 QApplication::restoreOverrideCursor();
885 //=============================================================================
889 //=============================================================================
890 void SMESHGUI::CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea )
892 QApplication::setOverrideCursor( Qt::waitCursor );
894 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
895 SMESH::SMESH_MaxElementArea_var MaxElArea = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
896 if ( !MaxElArea->_is_nil() )
897 MaxElArea->SetMaxElementArea( MaxArea );
899 catch (SALOME::SALOME_Exception& S_ex) {
900 QtCatchCorbaException(S_ex);
903 myActiveStudy->updateObjBrowser(true);
904 QApplication::restoreOverrideCursor();
907 //=============================================================================
911 //=============================================================================
912 void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume )
914 QApplication::setOverrideCursor( Qt::waitCursor );
916 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
917 SMESH::SMESH_MaxElementVolume_var MaxElVolume = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
918 if ( !MaxElVolume->_is_nil() )
919 MaxElVolume->SetMaxElementVolume( MaxVolume );
921 catch (const SALOME::SALOME_Exception& S_ex) {
922 QtCatchCorbaException(S_ex);
924 myActiveStudy->updateObjBrowser(true);
925 QApplication::restoreOverrideCursor();
928 //=============================================================================
932 //=============================================================================
933 void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments )
935 QApplication::setOverrideCursor( Qt::waitCursor );
937 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
938 SMESH::SMESH_NumberOfSegments_var NbS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
939 if ( !NbS->_is_nil() )
940 NbS->SetNumberOfSegments( nbSegments );
942 catch (const SALOME::SALOME_Exception& S_ex) {
943 QtCatchCorbaException(S_ex);
945 myActiveStudy->updateObjBrowser(true);
946 QApplication::restoreOverrideCursor();
949 //=============================================================================
953 //=============================================================================
954 int SMESHGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName )
956 int nbSel = Sel->IObjectCount() ;
958 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
959 aName = IObject->getName();
961 aName = tr( "SMESH_OBJECTS_SELECTED" ).arg( nbSel );
966 //=============================================================================
970 //=============================================================================
971 int SMESHGUI::GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName )
974 int nbSel = Sel->IObjectCount() ;
976 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
977 if ( !IObject->hasEntry() )
980 Standard_Boolean res;
981 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
985 TColStd_MapOfInteger MapIndex;
986 Sel->GetIndex( IObject, MapIndex );
987 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
989 nbNodes = MapIndex.Extent();
990 for ( ; ite.More(); ite.Next() ) {
991 aName = aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) + " ";
999 //=============================================================================
1003 //=============================================================================
1004 int SMESHGUI::GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName )
1007 int nbSel = Sel->IObjectCount() ;
1009 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1010 if ( !IObject->hasEntry() )
1013 Standard_Boolean res;
1014 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1018 TColStd_MapOfInteger MapIndex;
1019 Sel->GetIndex( IObject, MapIndex );
1020 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1022 nbElements = MapIndex.Extent();
1023 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1024 for ( ; ite.More(); ite.Next() ) {
1025 int idVTK = ite.Key();
1026 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1027 aName = aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1036 //=============================================================================
1040 //=============================================================================
1041 int SMESHGUI::GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName )
1044 int nbSel = Sel->IObjectCount() ;
1046 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1047 if ( !IObject->hasEntry() )
1050 Standard_Boolean res;
1051 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1055 TColStd_MapOfInteger MapIndex;
1056 Sel->GetIndex( IObject, MapIndex );
1057 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1059 nbElements = MapIndex.Extent();
1060 for ( ; ite.More(); ite.Next() ) {
1061 aName = aName + QString("%1").arg(ite.Key()) + " ";
1070 //=============================================================================
1074 //=============================================================================
1075 SMESH_Actor* SMESHGUI::FindActorByEntry(QString entry,
1076 Standard_Boolean& testResult,
1077 bool onlyInActiveView)
1079 int nbSf = myActiveStudy->getStudyFramesCount();
1080 for ( int i = 0; i < nbSf; i++ ) {
1081 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
1082 if ( sf->getTypeView() == VIEW_VTK ) {
1083 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1084 vtkActorCollection* theActors = Renderer->GetActors();
1085 theActors->InitTraversal();
1086 vtkActor *ac = theActors->GetNextActor();
1087 while(!(ac==NULL)) {
1088 if ( ac->IsA("SMESH_Actor") ) {
1089 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1090 if ( anActor->hasIO() ) {
1091 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1092 if ( strcmp( IO->getEntry(), entry ) == 0 ) {
1093 if ( onlyInActiveView ) {
1094 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
1105 ac = theActors->GetNextActor();
1110 MESSAGE ( " Actor Not Found " )
1112 return SMESH_Actor::New();
1115 //=============================================================================
1119 //=============================================================================
1120 SMESH_Actor* SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1121 Standard_Boolean& testResult,
1122 bool onlyInActiveView)
1124 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
1125 if ( SM->_is_nil() ) {
1126 MESSAGE ( " Actor Not Found " )
1129 return SMESH_Actor::New();
1132 return FindActorByEntry( SM->GetID(), testResult, onlyInActiveView);
1135 //=============================================================================
1139 //=============================================================================
1140 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO,
1141 Standard_Boolean& testResult)
1143 SMESH::SMESH_Mesh_var aMesh;
1144 testResult = false ;
1147 if ( IO->hasEntry() ) {
1148 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1149 SALOMEDS::GenericAttribute_var anAttr;
1150 SALOMEDS::AttributeIOR_var anIOR;
1151 if ( !obj->_is_nil() ) {
1152 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1153 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1154 aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1155 if ( !aMesh->_is_nil() ) {
1157 return SMESH::SMESH_Mesh::_duplicate( aMesh );
1162 return SMESH::SMESH_Mesh::_nil();
1165 //=============================================================================
1169 //=============================================================================
1170 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO,
1171 Standard_Boolean& testResult)
1173 SMESH::SMESH_subMesh_var aSubMesh;
1174 testResult = false ;
1177 if ( IO->hasEntry() ) {
1178 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1179 SALOMEDS::GenericAttribute_var anAttr;
1180 SALOMEDS::AttributeIOR_var anIOR;
1181 if ( !obj->_is_nil() ) {
1182 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1183 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1184 aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1185 if ( !aSubMesh->_is_nil() ) {
1187 return SMESH::SMESH_subMesh::_duplicate( aSubMesh );
1192 return SMESH::SMESH_subMesh::_nil();
1195 //=============================================================================
1199 //=============================================================================
1200 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO,
1201 Standard_Boolean& testResult )
1203 SMESH::SMESH_Hypothesis_var aHyp ;
1204 testResult = false ;
1207 if ( IO->hasEntry() ) {
1208 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1209 SALOMEDS::GenericAttribute_var anAttr;
1210 SALOMEDS::AttributeIOR_var anIOR;
1211 if ( !obj->_is_nil() ) {
1212 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1213 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1214 aHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()));
1215 if ( !aHyp->_is_nil() ) {
1217 return SMESH::SMESH_Hypothesis::_duplicate( aHyp );
1222 return SMESH::SMESH_Hypothesis::_nil();
1227 //=============================================================================
1231 //=============================================================================
1232 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO,
1233 Standard_Boolean& testResult )
1235 GEOM::GEOM_Shape_var aShape ;
1236 testResult = false ;
1239 if ( IO->hasEntry() ) {
1240 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1241 SALOMEDS::GenericAttribute_var anAttr;
1242 SALOMEDS::AttributeIOR_var anIOR;
1243 if ( !obj->_is_nil() ) {
1244 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1245 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1246 aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
1247 if ( !aShape->_is_nil() ) {
1249 return GEOM::GEOM_Shape::_duplicate( aShape );
1254 return GEOM::GEOM_Shape::_nil();
1258 //=============================================================================
1262 //=============================================================================
1263 void SMESHGUI::SetViewMode(int commandId)
1265 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1266 int nbSel = Sel->IObjectCount();
1268 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1269 for ( ; It.More(); It.Next() ) {
1270 Handle(SALOME_InteractiveObject) IObject = It.Value();
1271 if ( IObject->hasEntry() ) {
1272 Standard_Boolean res;
1273 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1275 switch (commandId) {
1277 ChangeRepresentation( ac, 0 );
1281 ChangeRepresentation( ac, 1 );
1285 ChangeRepresentation( ac, 2 );
1289 ChangeRepresentation( ac, 3 );
1296 if ( commandId == 1133 ) {
1297 ChangeRepresentation( SMESH_Actor::New(), 4 );
1302 //=============================================================================
1306 //=============================================================================
1307 void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
1309 if (ac->DataSource == NULL && type != 4 )
1313 if ( ac->getMapper() == NULL ) {
1319 QApplication::setOverrideCursor( Qt::waitCursor );
1320 if (ac->getDisplayMode()==2) {
1321 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1322 meshMapper->SetInput(ac->DataSource);
1324 ac->setDisplayMode(0);
1325 ac->GetProperty()->SetRepresentationToWireframe();
1326 // ac->SetActorProperty( ac->GetProperty() );
1327 QApplication::restoreOverrideCursor();
1331 QApplication::setOverrideCursor( Qt::waitCursor );
1332 if (ac->getDisplayMode()==2) {
1333 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1334 meshMapper->SetInput(ac->DataSource);
1336 ac->setDisplayMode(1);
1337 ac->GetProperty()->SetRepresentationToSurface();
1338 QApplication::restoreOverrideCursor();
1339 // ac->SetActorProperty( ac->GetProperty() );
1343 // if (!(ac->getDisplayMode()==2)) {
1344 // ChangeRepresentation(ac, 1);
1345 QApplication::setOverrideCursor( Qt::waitCursor );
1346 ac->setDisplayMode(2);
1347 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1348 meshMapper->SetInput(ac->DataSource);
1349 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1350 shrink->SetInput(meshMapper->GetInput());
1351 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1353 meshMapper->SetInput( shrink->GetOutput() );
1354 ac->SetMapper( meshMapper );
1355 QApplication::restoreOverrideCursor();
1363 float backfacecolor[3];
1365 ac->GetColor(color[0],color[1],color[2]);
1366 QColor c(color[0]*255,color[1]*255,color[2]*255);
1367 ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
1368 QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1369 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1370 QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1371 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
1372 QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1374 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1375 if ( Edgewidth == 0 )
1377 int intValue = ac->GetNodeSize() ;
1378 float Shrink = ac->GetShrinkFactor();
1380 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "" ) ;
1381 aDlg->SetColor(1,c);
1382 aDlg->SetColor(2,e);
1383 aDlg->SetColor(3,n);
1384 aDlg->SetColor(4,b);
1385 aDlg->SetIntValue(1,Edgewidth);
1386 aDlg->SetIntValue(2,intValue);
1387 aDlg->SetIntValue(3,int(Shrink*100.));
1389 if ( aDlg->exec() ) {
1390 QApplication::setOverrideCursor( Qt::waitCursor );
1391 QColor color = aDlg->GetColor(1);
1392 QColor edgecolor = aDlg->GetColor(2);
1393 QColor nodecolor = aDlg->GetColor(3);
1394 QColor backfacecolor = aDlg->GetColor(4);
1395 /* actor color and backface color */
1396 ac->GetProperty()->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1397 ac->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1398 ac->GetBackfaceProperty()->SetColor(float(backfacecolor.red())/255.,float(backfacecolor.green())/255.,float(backfacecolor.blue())/255.);
1401 ac->EdgeDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1402 float(edgecolor.green())/255.,
1403 float(edgecolor.blue())/255.);
1404 ac->EdgeShrinkDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1405 float(edgecolor.green())/255.,
1406 float(edgecolor.blue())/255.);
1407 ac->SetEdgeColor(float(edgecolor.red())/255.,
1408 float(edgecolor.green())/255.,
1409 float(edgecolor.blue())/255.);
1411 /* Shrink factor and size edges */
1412 ac->SetShrinkFactor( aDlg->GetIntValue(3)/100. );
1413 ac->EdgeDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1414 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1416 /* Nodes color and size */
1417 ac->SetNodeColor(float(nodecolor.red())/255.,
1418 float(nodecolor.green())/255.,
1419 float(nodecolor.blue())/255.);
1420 ac->SetNodeSize(aDlg->GetIntValue(2)) ;
1422 if (ac->getDisplayMode()==2) {
1423 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1424 meshMapper->SetInput(ac->DataSource);
1425 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1426 shrink->SetInput(meshMapper->GetInput());
1427 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1429 meshMapper->SetInput( shrink->GetOutput() );
1430 ac->SetMapper( meshMapper );
1434 QApplication::restoreOverrideCursor();
1439 EmitSignalDeactivateDialog() ;
1440 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1441 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg( QAD_Application::getDesktop(), "", Sel) ;
1445 QApplication::setOverrideCursor( Qt::waitCursor );
1446 ac->GetProperty()->SetRepresentationToPoints();
1447 QApplication::restoreOverrideCursor();
1452 QApplication::setOverrideCursor( Qt::waitCursor );
1453 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1454 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1455 theRenderer->Render();
1457 QApplication::restoreOverrideCursor();
1460 //=============================================================================
1464 //=============================================================================
1465 void SMESHGUI::UpdateView()
1467 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1470 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1471 theRenderer->Render();
1474 //=============================================================================
1478 //=============================================================================
1479 void SMESHGUI::DisplayActor(SMESH_Actor* ac, bool visibility)
1481 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1484 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1486 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1487 vtkActorCollection* theActors = theRenderer->GetActors();
1488 theActors->InitTraversal();
1489 if ( theActors->IsItemPresent(ac) == 0 ) {
1490 vtkProperty* prop = vtkProperty::New();
1491 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1492 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1493 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. ) ;
1495 prop->SetPointSize( QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
1496 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
1497 ac->SetProperty( prop );
1498 ac->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1499 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1500 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. );
1502 // prop->BackfaceCullingOn();
1503 vtkProperty* backprop = vtkProperty::New();
1504 backprop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed").toFloat()/255.,
1505 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").toFloat()/255.,
1506 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").toFloat()/255. ) ;
1507 ac->SetBackfaceProperty(backprop);
1509 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1512 ac->SetShrinkFactor( intValue/100. );
1514 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1515 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1517 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1518 if ( DisplayMode.compare("Wireframe") == 0 ){
1519 ac->setDisplayMode(0);
1520 ChangeRepresentation( ac, 0 );
1521 } else if ( DisplayMode.compare("Shading") == 0 ){
1522 ac->setDisplayMode(1);
1523 ChangeRepresentation( ac, 1 );
1524 } else if ( DisplayMode.compare("Shrink") == 0 ) {
1525 ac->setDisplayMode(2);
1526 ChangeRepresentation( ac, 2 );
1528 theRenderer->AddActor(ac);
1530 if (ac->GetMapper())
1531 ac->GetMapper()->Update();
1534 // if ( visibility )
1535 ac->SetVisibility(visibility);
1536 // ac->VisibilityOn();
1538 // ac->VisibilityOff();
1540 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1544 //=============================================================================
1548 //=============================================================================
1549 void SMESHGUI::EraseActor(SMESH_Actor* ac)
1551 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1554 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1556 //NRI- : 02/12/2002 : Fixed bugId 882
1557 // ac->EdgeDevice->VisibilityOff();
1558 // ac->EdgeShrinkDevice->VisibilityOff();
1559 // ac->VisibilityOff();
1560 ac->SetVisibility( false );
1562 theRenderer->Render();
1565 //=============================================================================
1569 //=============================================================================
1570 bool SMESHGUI::AddActorInSelection(SMESH_Actor* ac)
1572 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1573 Sel->ClearIObjects();
1575 return Sel->AddIObject( ac->getIO() );
1580 //=============================================================================
1584 //=============================================================================
1585 QString SMESHGUI::CheckHomogeneousSelection()
1587 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1590 SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
1591 for (; Itinit.More(); Itinit.Next()) {
1592 List.Append(Itinit.Value());
1595 QString RefType = CheckTypeObject( Sel->firstIObject() );
1596 SALOME_ListIteratorOfListIO It( List );
1597 for (; It.More(); It.Next()) {
1598 Handle(SALOME_InteractiveObject) IObject = It.Value();
1599 QString Type = CheckTypeObject( IObject );
1600 if ( Type.compare( RefType ) != 0 )
1601 return "Heterogeneous Selection";
1604 Sel->ClearIObjects();
1605 SALOME_ListIteratorOfListIO It1( List );
1606 for(;It1.More();It1.Next()) {
1607 int res = Sel->AddIObject( It1.Value() );
1609 myActiveStudy->highlight( It1.Value(), false );
1611 myActiveStudy->highlight( It1.Value(), true );
1616 //=============================================================================
1620 //=============================================================================
1621 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO)
1623 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
1624 if (!sobj->_is_nil()) {
1625 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1626 if (strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected
1631 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1632 Sel->ClearIObjects();
1634 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter( HYPOTHESIS );
1635 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter( ALGORITHM );
1636 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
1637 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
1638 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
1639 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter( SUBMESH_VERTEX );
1640 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter( SUBMESH_EDGE );
1641 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter( SUBMESH_FACE );
1642 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter( SUBMESH_SOLID );
1643 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter( SUBMESH_COMPOUND );
1645 Sel->AddFilter(aHypFilter);
1646 if ( Sel->AddIObject( IO ) != -1 ) {
1647 Sel->ClearFilters();
1648 return "Hypothesis";
1651 Sel->ClearFilters();
1652 Sel->AddFilter(anAlgoFilter);
1653 if ( Sel->AddIObject( IO ) != -1 ) {
1654 Sel->ClearFilters();
1658 Sel->ClearFilters();
1659 Sel->AddFilter(aMeshFilter);
1660 if ( Sel->AddIObject( IO ) != -1 ) {
1661 Sel->ClearFilters();
1665 Sel->ClearFilters();
1666 Sel->AddFilter(aSubMeshFilter);
1667 if ( Sel->AddIObject( IO ) != -1 ) {
1668 Sel->ClearFilters();
1672 Sel->ClearFilters();
1673 Sel->AddFilter(aSubMeshVextexFilter);
1674 if ( Sel->AddIObject( IO ) != -1 ) {
1675 Sel->ClearFilters();
1676 return "SubMeshVertex";
1679 Sel->ClearFilters();
1680 Sel->AddFilter(aSubMeshEdgeFilter);
1681 if ( Sel->AddIObject( IO ) != -1 ){
1682 Sel->ClearFilters();
1683 return "SubMeshEdge";
1686 Sel->ClearFilters();
1687 Sel->AddFilter(aSubMeshFaceFilter);
1688 if ( Sel->AddIObject( IO ) != -1 ) {
1689 Sel->ClearFilters();
1690 return "SubMeshFace";
1693 Sel->ClearFilters();
1694 Sel->AddFilter(aSubMeshSolidFilter);
1695 if ( Sel->AddIObject( IO ) != -1 ) {
1696 Sel->ClearFilters();
1697 return "SubMeshSolid";
1700 Sel->ClearFilters();
1701 Sel->AddFilter(aSubMeshCompoundFilter);
1702 if ( Sel->AddIObject( IO ) != -1 ) {
1703 Sel->ClearFilters();
1704 return "SubMeshCompound";
1707 Sel->ClearFilters();
1708 Sel->AddIObject( IO );
1712 //=============================================================================
1716 //=============================================================================
1717 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1719 /* Create or retrieve an object SMESHGUI */
1720 SMESHGUI::GetOrCreateSMESHGUI(parent);
1722 // NRI : Temporary added
1723 if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
1728 // QAD_Viewer3d* v3d;
1729 OCCViewer_Viewer3d* v3d;
1731 Handle(AIS_InteractiveContext) ic;
1732 vtkRenderer* Renderer;
1733 vtkRenderWindow* RenWin;
1735 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1736 v3d =((OCCViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1737 ic = v3d->getAISContext();
1738 } else if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1739 Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1740 RenWin = Renderer->GetRenderWindow();
1743 switch (theCommandID)
1746 smeshGUI->OnEditDelete();
1753 Import_Document(parent,theCommandID);//NBU
1754 //Import_Mesh(parent,theCommandID);
1758 case 122: // EXPORT MED
1762 Export_Mesh(parent, theCommandID);
1766 case 200: // SCALAR BAR
1768 smeshGUI->DisplayScalarBar(false);
1773 SMESHGUI_EditScalarBarDlg *aDlg = new SMESHGUI_EditScalarBarDlg( parent, "", false ) ;
1779 smeshGUI->DisplayScalarBar( true );
1783 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
1789 smeshGUI->SetViewMode(theCommandID);
1793 case 214 : // UPDATE
1801 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1802 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1804 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1805 for(;It.More();It.Next()) {
1806 Handle(SALOME_InteractiveObject) IOS = It.Value();
1807 if ( IOS->hasEntry() ) {
1808 Standard_Boolean res;
1809 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IOS->getEntry(), res, true );
1810 if ( res ) smeshGUI->EraseActor( ac );
1814 Sel->ClearIObjects();
1815 smeshGUI->myActiveStudy->updateObjBrowser( true );
1818 case 301 : // DISPLAY
1820 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1822 QApplication::setOverrideCursor( Qt::waitCursor );
1823 SALOMEDS::SObject_var fatherSF =
1824 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1826 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1827 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1829 for(;It.More();It.Next()) {
1830 Handle(SALOME_InteractiveObject) IObject = It.Value();
1831 if ( IObject->hasEntry() ) {
1832 Standard_Boolean res;
1833 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1835 smeshGUI->DisplayActor( ac, true );
1836 smeshGUI->DisplayEdges( ac );
1837 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1841 QApplication::restoreOverrideCursor();
1846 case 302 : // DISPLAY ONLY
1848 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1849 QApplication::setOverrideCursor( Qt::waitCursor );
1850 vtkActorCollection* theActors = Renderer->GetActors();
1851 theActors->InitTraversal();
1852 vtkActor *ac = theActors->GetNextActor();
1853 while(!(ac==NULL)) {
1854 if ( ac->IsA("SMESH_Actor") ) {
1855 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1856 if(!anActor->isHighlighted()) {
1857 //anActor->VisibilityOff();
1858 //NRI- : 02/12/2002 : Fixed bugId 882
1859 // anActor->EdgeDevice->VisibilityOff();
1860 // anActor->EdgeShrinkDevice->VisibilityOff();
1861 anActor->SetVisibility( false );
1864 ac = theActors->GetNextActor();
1867 // Display selection
1868 SALOMEDS::SObject_var fatherSF = smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1870 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1871 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1873 for(;It.More();It.Next()) {
1874 Handle(SALOME_InteractiveObject) IObject = It.Value();
1875 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1877 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
1878 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
1880 if(myRenderInter->isInViewer(IObject)) {
1881 if ( IObject->hasEntry() ) {
1882 Standard_Boolean res;
1883 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1885 smeshGUI->DisplayActor( ac, true );
1886 smeshGUI->DisplayEdges( ac );
1887 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1892 smeshGUI->myActiveStudy->updateObjBrowser( true );
1893 QApplication::restoreOverrideCursor();
1900 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1901 smeshGUI->EmitSignalDeactivateDialog() ;
1902 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1903 Sel->ClearIObjects();
1904 smeshGUI->myDesktop->SetSelectionMode(1, true);
1905 parent->menuBar()->setItemChecked(9010, false );
1906 parent->menuBar()->setItemChecked(9011, false );
1907 smeshGUI->ViewNodes();
1908 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg( parent, "", Sel ) ;
1910 QApplication::restoreOverrideCursor();
1911 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1912 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
1917 case 405: // MOVE NODE
1919 smeshGUI->myDesktop->SetSelectionMode(1, true);
1920 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1921 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, "", Sel ) ;
1925 case 701: // COMPUTE MESH
1927 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1928 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1929 int nbSel = Sel->IObjectCount();
1931 QApplication::restoreOverrideCursor();
1935 SMESH::SMESH_Mesh_var aM;
1936 SMESH::SMESH_subMesh_var aSubM;
1937 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1938 if ( IObject->hasEntry() ) {
1939 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1940 SALOMEDS::GenericAttribute_var anAttr;
1941 SALOMEDS::AttributeIOR_var anIOR;
1942 if ( !aMorSM->_is_nil() ) {
1943 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
1944 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1945 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : IOR = " << anIOR->Value() )
1946 CORBA::Object_var cobj;
1948 cobj = _orb->string_to_object(anIOR->Value());
1949 if ( CORBA::is_nil(cobj) ) {
1950 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : nil object" )
1953 catch(CORBA::COMM_FAILURE& ex) {
1954 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : exception (1)" )
1956 aM = SMESH::SMESH_Mesh::_narrow(cobj);
1957 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1958 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1959 if ( !aM->_is_nil() ) {
1960 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1961 if ( !refShape->_is_nil() ) {
1962 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1964 QApplication::restoreOverrideCursor();
1965 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1966 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1970 smeshGUI->myComponentMesh->Compute( aM, refShape);
1971 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1972 // TO Do : change icon of all submeshes
1974 catch (const SALOME::SALOME_Exception& S_ex) {
1975 QtCatchCorbaException(S_ex);
1978 } else if ( !aSubM->_is_nil() ) {
1979 aM = aSubM->GetFather();
1980 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1981 if ( !refShape->_is_nil() ) {
1982 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1984 QApplication::restoreOverrideCursor();
1985 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1986 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1990 smeshGUI->myComponentMesh->Compute( aM, refShape);
1991 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1992 // TO Do : change icon of all submeshes
1994 catch (const SALOME::SALOME_Exception& S_ex) {
1995 QtCatchCorbaException(S_ex);
2003 // Check whether the actor for the mesh exists at least in one view
2004 Standard_Boolean res;
2005 SMESH_Actor* ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2007 smeshGUI->InitActor( aM );
2009 // Check whether the actor belongs to the active view
2010 VTKViewer_RenderWindowInteractor* rwInter =
2011 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2013 // The actor belongs to inactive view -> create a copy and add it in the active view
2014 if (!rwInter->isInViewer(IObject)) {
2015 SMESH_Actor* acCopy = SMESH_Actor::New();
2016 acCopy->ShallowCopy(ac);
2018 smeshGUI->DisplayActor( acCopy, false );
2022 if ( smeshGUI->myAutomaticUpdate ) {
2023 SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
2024 if ( Mesh != NULL ) {
2028 smeshGUI->DisplayActor( Mesh, true );
2029 smeshGUI->DisplayEdges( Mesh, true );
2030 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
2034 QApplication::restoreOverrideCursor();
2035 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2036 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2038 QApplication::restoreOverrideCursor();
2042 case 702: // ADD SUB MESH
2044 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2045 smeshGUI->EmitSignalDeactivateDialog() ;
2046 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2047 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg( parent, "", Sel ) ;
2049 QApplication::restoreOverrideCursor();
2050 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2051 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2056 case 703: // INIT MESH
2058 smeshGUI->EmitSignalDeactivateDialog() ;
2059 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2060 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg( parent, "", Sel ) ;
2064 case 704: // EDIT Hypothesis
2066 smeshGUI->EmitSignalDeactivateDialog() ;
2067 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2068 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2072 case 705: // EDIT Global Hypothesis
2074 smeshGUI->EmitSignalDeactivateDialog() ;
2075 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2076 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2080 case 706: // EDIT Local Hypothesis
2082 smeshGUI->EmitSignalDeactivateDialog() ;
2083 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2084 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2088 case 806: // ORIENTATION ELEMENTS
2090 smeshGUI->EmitSignalDeactivateDialog() ;
2091 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2092 smeshGUI->myDesktop->SetSelectionMode(3, true);
2093 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg( parent, "", Sel ) ;
2097 case 807: // DIAGONAL INVERSION
2099 smeshGUI->EmitSignalDeactivateDialog() ;
2100 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2101 Sel->ClearIObjects();
2102 smeshGUI->myDesktop->SetSelectionMode(2, true);
2103 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg( parent, "", Sel ) ;
2107 case 900: // MESH INFOS
2109 smeshGUI->EmitSignalDeactivateDialog() ;
2110 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2111 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg( parent, "", Sel ) ;
2115 case 1001: // AUTOMATIC UPDATE PREFERENCES
2117 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001) );
2118 if ( parent->menuBar()->isItemChecked(1001) ) {
2119 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","true");
2120 smeshGUI->myAutomaticUpdate = true;
2122 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","false");
2123 smeshGUI->myAutomaticUpdate = false;
2128 case 1003: // MESH PREFERENCES
2130 smeshGUI->SetDisplaySettings();
2136 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2137 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2138 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2139 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2140 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2141 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2142 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2143 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2144 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2146 if ( Width == 0 ) Width = 0.17;
2147 if ( Height == 0 ) Height = 0.8;
2148 if ( NumberOfLabels == 0 ) NumberOfLabels = 5;
2149 if ( NumberOfColors == 0) NumberOfColors = 64;
2151 SMESHGUI_Preferences_ScalarBarDlg *aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, "", true) ;
2153 if ( Bold.compare("true") == 0 )
2154 aDlg->Bold->setChecked(true); else aDlg->Bold->setChecked(false);
2155 if ( Italic.compare("true") == 0 )
2156 aDlg->Italic->setChecked(true); else aDlg->Italic->setChecked(false);
2157 if ( Shadow.compare("true") == 0 )
2158 aDlg->Shadow->setChecked(true); else aDlg->Shadow->setChecked(false);
2160 if ( Orientation.compare("Horizontal") == 0 )
2161 aDlg->RadioHoriz->setChecked(true); else aDlg->RadioVert->setChecked(true);
2163 int NbItems = aDlg->ComboBox1->count();
2165 aDlg->ComboBox1->setCurrentItem( i );
2166 while ( i < NbItems ) {
2167 if ( FontFamily.compare( aDlg->ComboBox1->text( i ) ) == 0 )
2168 aDlg->ComboBox1->setCurrentItem( i );
2172 aDlg->LineEditWidth->setText( QString("%1").arg(Width) );
2173 aDlg->LineEditHeight->setText( QString("%1").arg(Height) );
2175 aDlg->SpinBoxLabels->setValue( NumberOfLabels );
2176 aDlg->SpinBoxColors->setValue( NumberOfColors );
2179 if ( aDlg->result() ) {
2180 if ( aDlg->RadioHoriz->isChecked() )
2181 Orientation = "Horizontal"; else Orientation = "Vertical";
2182 if ( aDlg->Bold->isChecked() )
2183 Bold = "true"; else Bold = "false";
2184 if ( aDlg->Italic->isChecked() )
2185 Italic = "true"; else Italic = "false";
2186 if ( aDlg->Shadow->isChecked() )
2187 Shadow = "true"; else Shadow = "false";
2189 FontFamily = aDlg->ComboBox1->currentText();
2190 Width = aDlg->LineEditWidth->text().toFloat();
2191 Height = aDlg->LineEditHeight->text().toFloat();
2192 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2193 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2196 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
2197 if ( aScalarBar != NULL ) {
2198 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2199 FontFamily, Orientation,
2200 Width, Height, NumberOfColors, NumberOfLabels);
2203 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2204 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2205 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2206 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2207 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2208 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2209 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2210 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2211 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2216 case 1100: // EDIT HYPOTHESIS
2218 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2219 int nbSel = Sel->IObjectCount() ;
2222 Standard_Boolean res;
2223 SMESH::SMESH_Hypothesis_var Hyp = smeshGUI->ConvertIOinSMESHHypothesis( Sel->firstIObject(), res );
2225 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2226 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2227 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2228 SALOMEDS::Study::ListOfSObject_var listSOmesh = smeshGUI->GetMeshesUsingAlgoOrHypothesis( Hyp) ;
2231 QString Name = Hyp->GetName();
2233 if ( Name.compare("LocalLength") == 0 ) {
2234 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
2235 double beforeLength = LL->GetLength() ;
2236 double Length = smeshGUI->Parameter( res,
2238 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2241 if ( res && Length != beforeLength ) {
2242 LL->SetLength( Length );
2243 for( int i=0; i<listSOmesh->length(); i++ ) {
2244 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2249 } else if ( Name.compare("NumberOfSegments") == 0 ) {
2250 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
2251 int beforeNbSeg = NOS->GetNumberOfSegments() ;
2252 int NbSeg = smeshGUI->Parameter( res,
2254 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2258 if ( res && NbSeg != beforeNbSeg ) {
2259 NOS->SetNumberOfSegments( NbSeg );
2260 for( int i=0; i<listSOmesh->length(); i++ ) {
2261 SALOMEDS::SObject_var SO = listSOmesh[i] ;
2262 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2267 } else if ( Name.compare("MaxElementArea") == 0 ) {
2268 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
2269 double beforeMaxArea = MEA->GetMaxElementArea() ;
2270 double MaxArea = smeshGUI->Parameter( res,
2272 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2275 if ( res && MaxArea != beforeMaxArea ) {
2276 MEA->SetMaxElementArea( MaxArea );
2277 for( int i=0; i<listSOmesh->length(); i++ ) {
2278 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2283 } else if ( Name.compare("MaxElementVolume") == 0 ) {
2284 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
2285 double beforeMaxVolume = MEV->GetMaxElementVolume() ;
2286 double MaxVolume = smeshGUI->Parameter( res,
2288 tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"),
2291 if ( res && MaxVolume != beforeMaxVolume ) {
2292 MEV->SetMaxElementVolume( MaxVolume );
2293 for( int i=0; i<listSOmesh->length(); i++ ) {
2294 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2299 } else if ( Name.compare("Regular_1D") == 0 ) {
2300 } else if ( Name.compare("MEFISTO_2D") == 0 ) {
2309 case 1101: // RENAME
2311 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2312 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2313 for ( ; It.More(); It.Next() ) {
2314 Handle(SALOME_InteractiveObject) IObject = It.Value();
2316 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2317 SALOMEDS::GenericAttribute_var anAttr;
2318 SALOMEDS::AttributeName_var aName;
2319 if ( !obj->_is_nil() ) {
2320 if (obj->FindAttribute(anAttr, "AttributeName")) {
2321 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2322 QString newName = QString( aName->Value() );
2323 newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName);
2324 if ( !newName.isEmpty() ) {
2325 QApplication::setOverrideCursor( Qt::waitCursor );
2326 smeshGUI->myActiveStudy->renameIObject( IObject, newName );
2328 QApplication::restoreOverrideCursor();
2335 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2337 QApplication::setOverrideCursor( Qt::waitCursor );
2338 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2339 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2340 for ( int i=0; It.More(); It.Next(), i++ ) {
2341 Handle(SALOME_InteractiveObject) IObject = It.Value();
2342 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh( IObject );
2344 Sel->ClearIObjects();
2345 smeshGUI->myActiveStudy->updateObjBrowser( true );
2346 QApplication::restoreOverrideCursor();
2350 case 401: // GEOM::EDGE
2352 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2353 smeshGUI->EmitSignalDeactivateDialog() ;
2354 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2355 Sel->ClearIObjects();
2356 smeshGUI->myDesktop->SetSelectionMode(1, true);
2357 parent->menuBar()->setItemChecked(9010, false );
2358 parent->menuBar()->setItemChecked(9011, false );
2359 smeshGUI->ViewNodes();
2360 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg( parent, "", Sel ) ;
2362 QApplication::restoreOverrideCursor();
2363 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2364 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2368 case 4021: // TRIANGLE
2370 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2371 smeshGUI->EmitSignalDeactivateDialog() ;
2372 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2373 Sel->ClearIObjects();
2374 smeshGUI->myDesktop->SetSelectionMode(1, true);
2375 parent->menuBar()->setItemChecked(9010, false );
2376 parent->menuBar()->setItemChecked(9011, false );
2377 smeshGUI->ViewNodes();
2378 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 3 ) ;
2380 QApplication::restoreOverrideCursor();
2381 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2382 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2388 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2389 smeshGUI->EmitSignalDeactivateDialog() ;
2390 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2391 Sel->ClearIObjects();
2392 smeshGUI->myDesktop->SetSelectionMode(1, true);
2393 parent->menuBar()->setItemChecked(9010, false );
2394 parent->menuBar()->setItemChecked(9011, false );
2395 smeshGUI->ViewNodes();
2396 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 4 ) ;
2398 QApplication::restoreOverrideCursor();
2399 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2400 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2406 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2407 smeshGUI->EmitSignalDeactivateDialog() ;
2408 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2409 Sel->ClearIObjects();
2410 smeshGUI->myDesktop->SetSelectionMode(1, true);
2411 parent->menuBar()->setItemChecked(9010, false );
2412 parent->menuBar()->setItemChecked(9011, false );
2413 smeshGUI->ViewNodes();
2414 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 4 ) ;
2416 QApplication::restoreOverrideCursor();
2417 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2418 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2424 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2425 smeshGUI->EmitSignalDeactivateDialog() ;
2426 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2427 Sel->ClearIObjects();
2428 smeshGUI->myDesktop->SetSelectionMode(1, true);
2429 parent->menuBar()->setItemChecked(9010, false );
2430 parent->menuBar()->setItemChecked(9011, false );
2431 smeshGUI->ViewNodes();
2432 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 8 ) ;
2434 QApplication::restoreOverrideCursor();
2435 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2436 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2441 case 4041: // REMOVES NODES
2443 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2444 smeshGUI->EmitSignalDeactivateDialog() ;
2445 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2446 Sel->ClearIObjects();
2447 smeshGUI->myDesktop->SetSelectionMode(1, true);
2448 parent->menuBar()->setItemChecked(9010, false );
2449 parent->menuBar()->setItemChecked(9011, false );
2450 smeshGUI->ViewNodes();
2451 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg( parent, "", Sel ) ;
2453 QApplication::restoreOverrideCursor();
2454 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2455 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2459 case 4042: // REMOVES ELEMENTS
2461 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2462 smeshGUI->EmitSignalDeactivateDialog() ;
2463 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2464 Sel->ClearIObjects();
2465 smeshGUI->myDesktop->SetSelectionMode(3, true);
2466 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg( parent, "", Sel ) ;
2468 QApplication::restoreOverrideCursor();
2469 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2470 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2475 case 5000: // HYPOTHESIS - ALGO
2477 smeshGUI->CreateAlgorithm("Regular_1D","Wire Discretisation");
2482 smeshGUI->CreateAlgorithm("MEFISTO_2D","Triangle (Mefisto)");
2487 smeshGUI->CreateAlgorithm("Quadrangle_2D","Quadrangle (Mapping)");
2492 smeshGUI->CreateAlgorithm("Hexa_3D","Hexahedral (i,j,k)");
2497 smeshGUI->CreateAlgorithm("Tetra_3D","Tetrahedral (Netgen)");
2501 case 5030: // HYPOTHESIS - LOCAL LENGTH
2503 smeshGUI->EmitSignalDeactivateDialog() ;
2504 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2505 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg( parent, "" ) ;
2508 case 5031: // HYPOTHESIS - NB SEGMENTS
2510 smeshGUI->EmitSignalDeactivateDialog() ;
2511 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2512 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg( parent, "" ) ;
2516 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
2518 smeshGUI->EmitSignalDeactivateDialog() ;
2519 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2520 SMESHGUI_MaxElementAreaDlg *aDlg = new SMESHGUI_MaxElementAreaDlg( parent, "" ) ;
2524 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
2526 smeshGUI->EmitSignalDeactivateDialog() ;
2527 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2528 SMESHGUI_MaxElementVolumeDlg *aDlg = new SMESHGUI_MaxElementVolumeDlg( parent, "" ) ;
2532 case 6016: // CONTROLS
2540 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2541 int nbSel = Sel->IObjectCount();
2544 smeshGUI->Control(theCommandID);
2550 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2551 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2552 SMESHGUI_EdgesConnectivityDlg *Dlg = new SMESHGUI_EdgesConnectivityDlg( parent, "", Sel ) ;
2554 QApplication::restoreOverrideCursor();
2555 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2556 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2563 if ( !parent->menuBar()->isItemChecked(9010) ) {
2564 QApplication::setOverrideCursor( Qt::waitCursor );
2565 parent->menuBar()->setItemChecked(9011, false );
2567 smeshGUI->EraseSimulationActors();
2568 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2570 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2571 int nbSel = Sel->IObjectCount() ;
2573 Standard_Boolean res;
2574 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2576 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2578 // It's necessary to display SMDS IDs instead of VTK ones, so
2579 // vtkIdFilter is unacceptable here. We have to do it manually :(
2580 vtkUnstructuredGrid* ptGrid = vtkUnstructuredGrid::New();
2581 ptGrid->CopyStructure(MeshActor->DataSource);
2583 int numPts = MeshActor->DataSource->GetNumberOfPoints();
2585 // Loop over points and generate ids
2586 vtkIntArray *ptIds = vtkIntArray::New();
2587 ptIds->SetNumberOfValues(numPts);
2589 for (int id=0; id < numPts; id++) {
2590 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
2591 ptIds->SetValue(id, idSMDS);
2594 // mpv porting vtk4.2.2
2595 // vtkScalars* newScalars = vtkScalars::New();
2596 // newScalars->SetData(ptIds);
2597 // ptGrid->GetPointData()->SetScalars(newScalars);
2598 ptGrid->GetPointData()->SetScalars(ptIds);
2599 // newScalars->Delete();
2603 vtkMaskPoints* mask = vtkMaskPoints::New();
2604 mask->SetInput(ptGrid);
2605 mask->SetOnRatio( 1 );
2606 // mask->SetMaximumNumberOfPoints( 50 );
2607 // mask->RandomModeOn();
2609 vtkSelectVisiblePoints* visPts = vtkSelectVisiblePoints::New();
2610 visPts->SetInput(mask->GetOutput());
2611 visPts->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2612 //visPts->SetSelectInvisible(1);
2613 visPts->SelectInvisibleOff();
2614 visPts->SetTolerance(0.1);
2616 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2617 ldm->SetInput(visPts->GetOutput());
2618 ldm->SetLabelFormat("%g");
2619 ldm->SetLabelModeToLabelScalars();
2620 //ldm->SetLabelModeToLabelFieldData();
2622 ldm->SetFontFamilyToTimes();
2623 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2628 vtkActor2D* pointLabels = vtkActor2D::New();
2629 pointLabels->SetMapper(ldm);
2630 pointLabels->GetProperty()->SetColor(0,1,0);
2634 smeshGUI->mySimulationActors2D->AddItem( pointLabels );
2635 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( pointLabels );
2639 QApplication::setOverrideCursor( Qt::waitCursor );
2640 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2641 smeshGUI->EraseSimulationActors();
2642 smeshGUI->ScalarVisibilityOff();
2644 QApplication::restoreOverrideCursor();
2649 if ( !parent->menuBar()->isItemChecked(9011) ) {
2650 QApplication::setOverrideCursor( Qt::waitCursor );
2651 parent->menuBar()->setItemChecked(9010, false );
2653 smeshGUI->EraseSimulationActors();
2654 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2656 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2657 int nbSel = Sel->IObjectCount() ;
2659 Standard_Boolean res;
2660 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2662 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2664 // It's necessary to display SMDS IDs instead of VTK ones, so
2665 // vtkIdFilter is unacceptable here. We have to do it manually :(
2666 vtkUnstructuredGrid* elGrid = vtkUnstructuredGrid::New();
2667 elGrid->CopyStructure(MeshActor->DataSource);
2669 int numCells = MeshActor->DataSource->GetNumberOfCells();
2671 // Loop over points and generate ids
2672 vtkIntArray *cellIds = vtkIntArray::New();
2673 cellIds->SetNumberOfValues(numCells);
2675 for (int id=0; id < numCells; id++) {
2676 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
2677 cellIds->SetValue(id, idSMDS);
2680 // mpv porting vk4.2.2
2681 // vtkScalars* newScalars = vtkScalars::New();
2682 // newScalars->SetData(cellIds);
2683 elGrid->GetCellData()->SetScalars(cellIds);
2684 // elGrid->GetCellData()->SetScalars(newScalars);
2685 // newScalars->Delete();
2690 vtkCellCenters* cc = vtkCellCenters::New();
2691 cc->SetInput(elGrid);
2693 vtkSelectVisiblePoints* visCells = vtkSelectVisiblePoints::New();
2694 visCells->SetInput(cc->GetOutput());
2695 visCells->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2696 visCells->SelectInvisibleOff();
2697 visCells->SetTolerance(0.1);
2698 // visCells->SetSelectInvisible(1);
2700 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2701 ldm->SetInput(visCells->GetOutput());
2702 ldm->SetLabelFormat("%g");
2703 ldm->SetLabelModeToLabelScalars();
2705 ldm->SetFontFamilyToTimes();
2706 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2711 vtkActor2D* cellLabels = vtkActor2D::New();
2712 cellLabels->SetMapper(ldm);
2713 cellLabels->GetProperty()->SetColor(1,0,0);
2718 smeshGUI->mySimulationActors2D->AddItem( cellLabels );
2719 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( cellLabels );
2723 QApplication::setOverrideCursor( Qt::waitCursor );
2724 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2725 smeshGUI->EraseSimulationActors();
2726 smeshGUI->ScalarVisibilityOff();
2728 QApplication::restoreOverrideCursor();
2732 case 10001: // DISPLAY MODE PREFERENCE
2734 parent->menuBar()->setItemChecked(10001, !parent->menuBar()->isItemChecked(10001) );
2735 parent->menuBar()->setItemChecked(10002, false );
2736 parent->menuBar()->setItemChecked(10003, false );
2737 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2742 parent->menuBar()->setItemChecked(10002, !parent->menuBar()->isItemChecked(10002) );
2743 parent->menuBar()->setItemChecked(10001, false );
2744 parent->menuBar()->setItemChecked(10003, false );
2745 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2750 parent->menuBar()->setItemChecked(10003, !parent->menuBar()->isItemChecked(10003) );
2751 parent->menuBar()->setItemChecked(10002, false );
2752 parent->menuBar()->setItemChecked(10001, false );
2753 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
2759 smeshGUI->myActiveStudy->updateObjBrowser(true);
2764 //=============================================================================
2765 /*! function : GetMeshesUsingAlgoOrHypothesis()
2766 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
2767 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
2769 //=============================================================================
2770 SALOMEDS::Study::ListOfSObject* SMESHGUI::GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp )
2772 SALOMEDS::Study::ListOfSObject_var listSOmesh = new SALOMEDS::Study::ListOfSObject ;
2773 listSOmesh->length(0) ;
2774 unsigned int index = 0 ;
2775 if( !AlgoOrHyp->_is_nil() ) {
2776 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms( AlgoOrHyp );
2777 if( !SO_Hypothesis->_is_nil() ) {
2778 SALOMEDS::Study::ListOfSObject_var listSO = smeshGUI->myStudy->FindDependances(SO_Hypothesis) ;
2779 for( unsigned int i=0; i<listSO->length(); i++ ) {
2780 SALOMEDS::SObject_var SO = listSO[i] ;
2781 if( !SO->_is_nil() ) {
2782 SALOMEDS::SObject_var SOfatherFather = SO->GetFather()->GetFather() ;
2783 if( !SOfatherFather->_is_nil() ) {
2785 listSOmesh->length(index) ;
2786 listSOmesh[index-1] = SOfatherFather ;
2792 return listSOmesh._retn() ;
2796 //=============================================================================
2800 //=============================================================================
2801 void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
2805 Mesh_Reader* myReader;
2807 if (theCommandID==113) {
2808 filter = tr("MED files (*.med)");
2809 myExtension = string("MED");
2810 myReader = new DriverMED_R_SMESHDS_Mesh;
2812 else if (theCommandID==112) {
2813 filter = tr("IDEAS files (*.unv)");
2814 myExtension = string("UNV");
2816 else if (theCommandID==111) {
2817 filter = tr("DAT files (*.dat)");
2818 myExtension = string("MED");
2819 myReader = new DriverDAT_R_SMESHDS_Mesh;
2822 QString filename = QAD_FileDlg::getFileName(parent,
2827 if ( !filename.isEmpty() ) {
2828 QApplication::setOverrideCursor( Qt::waitCursor );
2829 string myClass = string("SMESHDS_Mesh");
2830 // Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
2832 int myMeshId = (smeshGUI->myDocument)->NewMesh();
2833 SMDS_Mesh* myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
2835 myReader->SetFile(string(filename.latin1()));
2836 myReader->SetMesh(myMesh);
2837 myReader->SetMeshId(myMeshId);
2840 QApplication::restoreOverrideCursor();
2844 //=============================================================================
2848 //=============================================================================
2849 void SMESHGUI::Export_Mesh(QAD_Desktop* parent, int theCommandID)
2851 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2852 int nbSel = Sel->IObjectCount() ;
2854 Standard_Boolean res;
2855 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2856 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh( IObject, res );
2858 if (theCommandID==122) { // EXPORT MED
2859 QString filename = QAD_FileDlg::getFileName(parent,
2861 tr("MED files (*.med)"),
2864 if ( !filename.isEmpty() ) {
2865 QApplication::setOverrideCursor( Qt::waitCursor );
2866 aMesh->ExportMED( filename.latin1() );
2867 QApplication::restoreOverrideCursor();
2870 else if (theCommandID==121) { // EXPORT DAT
2871 QString filename = QAD_FileDlg::getFileName(parent,
2873 tr("DAT files (*.dat)"),
2876 if ( !filename.isEmpty() ) {
2877 QApplication::setOverrideCursor( Qt::waitCursor );
2878 aMesh->ExportDAT( filename.latin1() );
2879 QApplication::restoreOverrideCursor();
2882 else if (theCommandID==123) { // EXPORT UNV
2883 QString filename = QAD_FileDlg::getFileName(parent,
2885 tr("IDEAS files (*.unv)"),
2888 if ( !filename.isEmpty() ) {
2889 QApplication::setOverrideCursor( Qt::waitCursor );
2890 aMesh->ExportUNV( filename.latin1() );
2891 QApplication::restoreOverrideCursor();
2894 aMesh->ExportDAT( filename.latin1() );
2896 QApplication::restoreOverrideCursor();
2898 if ( IObject->hasEntry() )
2901 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2902 SALOMEDS::GenericAttribute_var anAttr;
2903 SALOMEDS::AttributeComment_var aFileName;
2904 SALOMEDS::StudyBuilder_var aStudyBuilder = smeshGUI->myStudy->NewBuilder();
2905 anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
2906 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
2907 aFileName->SetValue(filename.latin1());
2914 //=============================================================================
2918 //=============================================================================
2919 void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
2923 Document_Reader* myReader;
2925 if (theCommandID==113) {
2926 filter = tr("MED files (*.med)");
2927 myExtension = string("MED");
2928 myReader = new DriverMED_R_SMESHDS_Document;
2930 else if (theCommandID==112) {
2931 filter = tr("IDEAS files (*.unv)");
2932 myExtension = string("UNV");
2933 myReader = new DriverUNV_R_SMESHDS_Document;
2935 else if (theCommandID==111) {
2936 filter = tr("DAT files (*.dat)");
2937 myExtension = string("DAT");
2938 myReader = new DriverDAT_R_SMESHDS_Document;
2941 QString filename = QAD_FileDlg::getFileName(parent,
2944 tr("Import document"),
2946 if ( !filename.isEmpty() ) {
2947 QApplication::setOverrideCursor( Qt::waitCursor );
2948 string myClass = string("SMESHDS_Document");
2949 // Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
2950 SMESHDS_Document* newDocument = new SMESHDS_Document(1);
2952 myReader->SetFile(string(filename.latin1()));
2953 myReader->SetDocument(smeshGUI->myDocument);
2955 QApplication::restoreOverrideCursor();
2959 void SMESHGUI::Export_Document(QAD_Desktop* parent, int theCommandID)
2962 Document_Writer* myWriter;
2965 if (theCommandID==122) {
2966 filter = tr("MED files (*.med)");
2967 myExtension = string("MED");
2968 myWriter = new DriverMED_W_SMESHDS_Document;
2970 else if (theCommandID==121) {
2971 filter = tr("DAT files (*.dat)");
2972 myExtension = string("DAT");
2973 myWriter = new DriverDAT_W_SMESHDS_Document;
2974 } else if (theCommandID==123) {
2975 filter = tr("IDEAS files (*.unv)");
2976 myExtension = string("UNV");
2977 myWriter = new DriverUNV_W_SMESHDS_Document;
2980 QString filename = QAD_FileDlg::getFileName(parent,
2983 tr("Export document"),
2985 if ( !filename.isEmpty() ) {
2986 QApplication::setOverrideCursor( Qt::waitCursor );
2987 string myClass = string("SMESHDS_Document");
2988 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
2990 myWriter->SetFile(string(filename.latin1()));
2991 myWriter->SetDocument(smeshGUI->myDocument);
2993 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
2994 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
2995 //myWriter->SetDocument(myDocument);
2998 QApplication::restoreOverrideCursor();
3002 //=============================================================================
3006 //=============================================================================
3007 bool SMESHGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3009 SMESHGUI::GetOrCreateSMESHGUI(parent);
3014 //=============================================================================
3018 //=============================================================================
3019 bool SMESHGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3021 SMESHGUI::GetOrCreateSMESHGUI(parent);
3027 //=============================================================================
3031 //=============================================================================
3032 bool SMESHGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3034 SMESHGUI::GetOrCreateSMESHGUI(parent);
3040 //=============================================================================
3044 //=============================================================================
3045 bool SMESHGUI::SetSettings( QAD_Desktop* parent )
3047 SMESHGUI::GetOrCreateSMESHGUI(parent);
3050 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3051 if ( DisplayMode.compare("") == 0 ) {
3052 DisplayMode = "Shading";
3053 QAD_CONFIG->addSetting("SMESH:DisplayMode","Shading");
3056 if ( DisplayMode.compare("Wireframe") == 0 ){
3057 parent->menuBar()->setItemChecked(10003, false );
3058 parent->menuBar()->setItemChecked(10002, false );
3059 parent->menuBar()->setItemChecked(10001, true );
3060 } else if ( DisplayMode.compare("Shading") == 0 ){
3061 parent->menuBar()->setItemChecked(10003, false );
3062 parent->menuBar()->setItemChecked(10002, true );
3063 parent->menuBar()->setItemChecked(10001, false );
3064 } else if ( DisplayMode.compare("Shrink") == 0 ) {
3065 parent->menuBar()->setItemChecked(10003, true );
3066 parent->menuBar()->setItemChecked(10002, false );
3067 parent->menuBar()->setItemChecked(10001, false );
3070 /* Automatic Update */
3071 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3072 if ( AutoUpdate.compare("true") == 0 ) {
3073 parent->menuBar()->setItemChecked(1001, true );
3074 smeshGUI->myAutomaticUpdate = true;
3076 parent->menuBar()->setItemChecked(1001, false );
3077 smeshGUI->myAutomaticUpdate = false;
3081 parent->menuBar()->setItemEnabled( 11, false); // IMPORT
3087 //=============================================================================
3091 //=============================================================================
3092 void SMESHGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
3094 /* Create or retrieve an object SMESHGUI */
3095 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3097 // NRI : Temporary added
3098 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3099 // theObject = "NothingSelected";
3100 // theContext = "NothingSelected";
3104 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3105 int nbSel = Sel->IObjectCount();
3107 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3108 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
3109 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1) ) {
3110 theObject = "ScalarBar";
3113 theObject = "NothingSelected";
3114 theContext = "NothingSelected";
3117 theObject = "NothingSelected";
3118 theContext = "NothingSelected";
3120 } else if (nbSel == 1 ) {
3121 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3124 theObject = smeshGUI->CheckHomogeneousSelection();
3129 //=============================================================================
3133 //=============================================================================
3134 bool SMESHGUI::CustomPopup( QAD_Desktop* parent,
3136 const QString& theContext,
3137 const QString& theParent,
3138 const QString& theObject )
3140 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3141 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3143 /* Create or retrieve an object SMESHGUI */
3144 SMESHGUI::GetOrCreateSMESHGUI(parent);
3146 // NRI : Temporary added
3147 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3152 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3153 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3154 int nbSel = Sel->IObjectCount();
3157 if (studyFrame->getTypeView() != VIEW_VTK)
3160 } else if (nbSel == 1 ) {
3161 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3162 // First check type of active viewer (VTK required)
3163 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3165 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3167 int id = popup->idAt(0);
3168 if (id <= QAD_TopLabel_Popup_ID)
3169 popup->removeItemAt(0);
3173 if (theObject.compare("Component") == 0) {
3174 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3179 // Remove common popup items for Submesh, Hypothesis and Algorithm
3180 if (theObject.compare("SubMesh") == 0 ||
3181 theObject.compare("Hypothesis") == 0 ||
3182 theObject.compare("Algorithm") == 0 ) {
3183 popup->removeItem(QAD_Display_Popup_ID);
3184 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3185 popup->removeItem(QAD_Erase_Popup_ID);
3186 int id = popup->idAt(popup->count()-1); // last item
3187 if (id < 0 && id != -1) popup->removeItem(id); // separator
3190 if (theObject.compare("Component") == 0) {
3191 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3195 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3196 QFont f = QApplication::font();
3199 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3201 if ( theParent.compare("Viewer")==0 ) {
3202 if (popup->idAt(0) == id) {
3203 popup->removeItem(id);
3204 popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), id, 0 );
3207 Standard_Boolean res;
3208 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3209 if ( res && studyFrame->getTypeView() == VIEW_VTK) {
3210 VTKViewer_RenderWindowInteractor* myRenderInter=
3211 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3212 if ( myRenderInter->isVisible( IObject ) ) {
3213 popup->removeItem(QAD_Display_Popup_ID);
3215 popup->removeItem(QAD_Erase_Popup_ID);
3218 popup->removeItem(QAD_Erase_Popup_ID);
3219 if (!res) {// mesh not computed -> can't display it
3220 popup->removeItem(QAD_Display_Popup_ID);
3221 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3222 popup->removeItemAt(popup->count() - 1);//separator
3225 } else if ( theParent.compare("ObjectBrowser")==0 ) {
3226 if (theObject.compare("Mesh") == 0 ||
3227 theObject.compare("SubMesh") == 0 ||
3228 theObject.compare("Hypothesis") == 0 ||
3229 theObject.compare("Algorithm") == 0 ) {
3230 popup->removeItemAt(0);
3232 if (popup->idAt(0) == id) {
3233 popup->removeItem(id);
3234 popup->removeItemAt(0);//separator
3238 Standard_Boolean res;
3239 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3240 if ( res && studyFrame->getTypeView() == VIEW_VTK ) {
3241 VTKViewer_RenderWindowInteractor* myRenderInter=
3242 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3243 if ( myRenderInter->isVisible( IObject ) ) {
3244 popup->removeItem(QAD_Display_Popup_ID);
3246 popup->removeItem(QAD_Erase_Popup_ID);
3249 if (theObject.compare("Mesh") == 0 ||
3250 theObject.compare("SubMesh") == 0 ||
3251 theObject.compare("Hypothesis") == 0 ||
3252 theObject.compare("Algorithm") == 0 ) {
3254 popup->removeItem(QAD_Erase_Popup_ID);
3255 if (!res) {// mesh not computed -> can't display it
3256 popup->removeItem(QAD_Display_Popup_ID);
3257 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3258 popup->removeItemAt(popup->count() - 1);//separator
3264 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3265 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3266 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3268 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3270 int id = popup->idAt(0);
3271 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3272 popup->removeItemAt(0);
3276 if (parentComp.isNull()) { // objects from several components are selected
3277 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3278 popup->removeItem(QAD_Display_Popup_ID);
3279 popup->removeItem(QAD_Erase_Popup_ID);
3280 int id = popup->idAt(popup->count()-1); // last item
3281 if (id < 0 && id != -1) popup->removeItem(id); // separator
3286 QString type = smeshGUI->CheckHomogeneousSelection();
3287 if ( type.compare("Heterogeneous Selection") != 0 ) {
3288 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3289 QFont f = QApplication::font();
3291 popup->removeItem(id);
3292 popup->insertItem( new CustomItem ( QString("%1 ").arg(nbSel) + type + " (s) ", f), id, 0 );
3298 //=============================================================================
3299 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3300 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3302 //=============================================================================
3303 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3305 /* Create or retrieve an object SMESHGUI */
3306 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3308 QAD_StudyFrame* activeFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3309 if (activeFrame->getTypeView() == VIEW_VTK) {
3311 SALOMEDS::SObject_var fatherSF =
3312 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
3314 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3315 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3317 // for(;It.More();It.Next()) {
3318 // Handle(SALOME_InteractiveObject) IObject = It.Value();
3319 Handle(SALOME_InteractiveObject) IObject = theIO;
3320 if ( IObject->hasEntry() ) {
3321 // Look for the actor in all views
3322 Standard_Boolean res;
3323 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3325 // Actor not found at all -> mesh is not computed -> do nothing!!!
3327 /*SMESH::SMESH_Mesh_var aM;
3328 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3329 SALOMEDS::SObject_var father = aMorSM->GetFather();
3330 SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
3332 // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
3333 if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
3336 SALOMEDS::GenericAttribute_var anAttr;
3337 SALOMEDS::AttributeIOR_var anIOR;
3338 if ( !aMorSM->_is_nil() ) {
3339 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
3340 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3341 aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
3345 if (!aM->_is_nil()) {
3346 smeshGUI->InitActor(aM);
3347 ac = smeshGUI->ReadScript(aM);
3351 smeshGUI->DisplayActor( ac, true );
3352 smeshGUI->DisplayEdges( ac );
3353 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3356 } else { // The actor exists in some view
3357 // Check whether the actor belongs to the active view
3358 VTKViewer_RenderWindowInteractor* rwInter =
3359 ((VTKViewer_ViewFrame*)activeFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3361 // The actor belongs to inactive view -> create a copy and display it in the active view
3362 if (!rwInter->isInViewer(IObject)) {
3363 SMESH_Actor* acCopy = SMESH_Actor::New();
3364 acCopy->ShallowCopy(ac);
3367 smeshGUI->DisplayActor( ac, false );
3368 smeshGUI->DisplayEdges( ac );
3369 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3374 MESSAGE("BuildPresentation() must not be called while non-VTK view is active")
3378 //=============================================================================
3382 //=============================================================================
3383 void SMESHGUI::setOrb()
3386 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
3387 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
3388 _orb = init( 0 , 0 );
3390 INFOS("internal error : orb not found");
3393 ASSERT(! CORBA::is_nil(_orb));
3397 //=============================================================================
3401 //=============================================================================
3402 SMESH_Actor* SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
3404 SMESH_Actor* MeshActor;
3405 if ( !aMesh->_is_nil() ) {
3406 Standard_Boolean result;
3407 MeshActor = FindActor(aMesh, result, true);
3409 SMESH::log_array_var aSeq = aMesh->GetLog(true);
3411 if (aSeq->length() == 0) {
3412 MESSAGE("ReadScript(): log is empty")
3416 for (unsigned int ind = 0; ind < aSeq->length();ind++) {
3417 switch ( aSeq[ind].commandType )
3419 case SMESH::ADD_NODE :
3421 AddNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3424 case SMESH::ADD_EDGE :
3426 // AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3429 case SMESH::ADD_TRIANGLE :
3431 AddTriangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3434 case SMESH::ADD_QUADRANGLE :
3436 AddQuadrangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3439 case SMESH::ADD_TETRAHEDRON :
3441 AddTetras( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3444 case SMESH::ADD_PYRAMID :
3448 case SMESH::ADD_PRISM :
3452 case SMESH::ADD_HEXAHEDRON :
3454 AddHexaedres( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3457 case SMESH::REMOVE_NODE :
3459 RemoveNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3462 case SMESH::REMOVE_ELEMENT :
3464 RemoveElements( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3476 //=============================================================================
3480 //=============================================================================
3481 void SMESHGUI::Dump(SMESH_Actor* Mactor)
3483 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3484 vtkPoints *Pts = ugrid->GetPoints();
3485 int nbPts = Pts->GetNumberOfPoints();
3486 int nbCells = ugrid->GetNumberOfCells();
3490 In = fopen("/tmp/dumpMesh","w+");
3491 fprintf(In,"%d %d\n",nbPts,nbCells);
3492 for ( int i = 0; i < nbPts; i++ ) {
3493 float *p = ugrid->GetPoint(i);
3494 fprintf(In,"%d %e %e %e\n",i, p[0], p[1], p[2] );
3497 for ( int i = 0; i < nbCells; i++ ) {
3498 fprintf(In,"%d %d",i,ugrid->GetCell(i)->GetCellType());
3499 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3500 for (j=0; j<Id->GetNumberOfIds(); j++) {
3501 fprintf(In," %d",Id->GetId(j));
3509 //=============================================================================
3513 //=============================================================================
3514 void SMESHGUI::AddNodes( SMESH_Actor* Mactor, int number,
3515 const SMESH::double_array& coords,
3516 const SMESH::long_array& indexes)
3518 QApplication::setOverrideCursor( Qt::waitCursor );
3519 if ( Mactor->GetMapper() == NULL ) {
3520 vtkPoints *Pts = vtkPoints::New();
3521 SMESH_Grid *ugrid = SMESH_Grid::New();
3526 while ( i <= number ) {
3527 int idVTK = Pts->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3528 //Mactor->AddNode( indexes[i-1], idVTK );
3529 ugrid->AddNode( indexes[i-1], idVTK );
3533 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3534 ugrid->SetPoints(Pts);
3535 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3536 PtsMapper->SetInput( ugrid );
3537 Mactor->DataSource = PtsMapper->GetInput();
3538 Mactor->SetMapper(PtsMapper);
3540 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3541 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3544 while ( i <= number ) {
3545 int idVTK = ugrid->GetPoints()->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3546 ugrid->AddNode( indexes[i-1], idVTK );
3550 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3551 PtsMapper->SetInput( ugrid );
3552 Mactor->DataSource = PtsMapper->GetInput();
3553 Mactor->SetMapper(PtsMapper);
3555 QApplication::restoreOverrideCursor();
3558 //=============================================================================
3562 //=============================================================================
3563 void SMESHGUI::AddNode(SMESH_Actor* Mactor, int idnode, float x, float y, float z)
3565 QApplication::setOverrideCursor( Qt::waitCursor );
3566 MESSAGE ( "SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z )
3567 if ( Mactor->GetMapper() == NULL ) {
3568 vtkPoints *Pts = vtkPoints::New();
3569 int idVTK = Pts->InsertNextPoint( x, y, z );
3570 //Mactor->AddNode( idnode, idVTK );
3571 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3572 SMESH_Grid *ugrid = SMESH_Grid::New();
3574 ugrid->AddNode( idnode, idVTK );
3575 ugrid->SetPoints(Pts);
3576 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3577 PtsMapper->SetInput( ugrid );
3578 Mactor->DataSource = PtsMapper->GetInput();
3579 Mactor->SetMapper(PtsMapper);
3581 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3582 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3583 int idVTK = ugrid->GetPoints()->InsertNextPoint( x, y, z );
3584 //Mactor->AddNode( idnode, idVTK );
3585 ugrid->AddNode( idnode, idVTK );
3586 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3587 PtsMapper->SetInput( ugrid );
3588 Mactor->DataSource = PtsMapper->GetInput();
3589 Mactor->SetMapper(PtsMapper);
3591 QApplication::restoreOverrideCursor();
3594 //=============================================================================
3598 //=============================================================================
3599 void SMESHGUI::RemoveNode(SMESH_Actor* Mactor, int idnode)
3601 MESSAGE ( " OLD RemoveNode method " )
3602 // int id = Mactor->GetIdVTKNode( idnode );
3603 // MESSAGE ( " RemoveNode id VTK " << id )
3604 // if ( Mactor->GetMapper() != NULL ) {
3605 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3606 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3607 // vtkPoints *Pts = ugrid->GetPoints();
3608 // vtkPoints *newPts = vtkPoints::New();
3609 // int nbPts = Pts->GetNumberOfPoints();
3610 // bool findPt = false;
3611 // for ( int i = 0; i < nbPts; i++ ) {
3614 // newPts->InsertPoint(i, Pts->GetPoint(i) );
3616 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
3619 // Mactor->RemoveNode( idnode );
3623 // newUgrid->SetPoints(newPts);
3624 // int nbCells = ugrid->GetNumberOfCells();
3625 // for ( int i = 0; i < nbCells; i++ ) {
3626 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3627 // vtkIdList *newIds = vtkIdList::New();
3628 // int nbIds = Ids->GetNumberOfIds();
3629 // newIds->SetNumberOfIds(nbIds);
3630 // for ( int j = 0; j < nbIds; j++ ) {
3631 // int theid = Ids->GetId(j);
3632 // if ( theid > id ) {
3633 // newIds->SetId( j, theid-1 );
3635 // newIds->SetId( j, theid );
3637 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3638 // Mactor->RemoveElement( idSMDSel, false );
3639 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3640 // Mactor->AddElement( idSMDSel, idVTKel );
3644 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3645 // Mapper->SetInput( newUgrid );
3646 // Mactor->DataSource = Mapper->GetInput();
3647 // Mactor->SetMapper(Mapper);
3653 //=============================================================================
3657 //=============================================================================
3658 void SMESHGUI::RemoveNodes(SMESH_Actor* Mactor, int number,
3659 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3661 QApplication::setOverrideCursor( Qt::waitCursor );
3663 while ( i <= number ) {
3664 Mactor->RemoveNode( indexes[i-1] );
3668 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
3669 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
3670 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
3672 if ( Mactor->GetMapper() != NULL ) {
3673 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3674 SMESH_Grid *newUgrid = SMESH_Grid::New();
3675 newUgrid->CopyMaps(ugrid);
3677 vtkPoints *Pts = ugrid->GetPoints();
3678 vtkPoints *newPts = vtkPoints::New();
3679 int nbPts = Pts->GetNumberOfPoints();
3681 for ( int i = 0; i < nbPts; i++ ) {
3682 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
3683 if ( idSMESHDSNode != -1 ) {
3684 newPts->InsertPoint(j, Pts->GetPoint(i) );
3686 newMapVTKNodes.Bind(j, idSMESHDSNode);
3687 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
3689 MapOldNodesToNewNodes.Bind(i,j);
3694 newUgrid->SetIdsVTKNode(newMapVTKNodes);
3695 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
3696 newUgrid->SetPoints(newPts);
3698 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3699 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3701 int nbCells = ugrid->GetNumberOfCells();
3702 for ( int i = 0; i < nbCells; i++ ) {
3703 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3704 vtkIdList *newIds = vtkIdList::New();
3705 int nbIds = Ids->GetNumberOfIds();
3706 newIds->SetNumberOfIds(nbIds);
3708 for ( int j = 0; j < nbIds; j++ ) {
3709 int theid = Ids->GetId(j);
3710 if ( MapOldNodesToNewNodes.IsBound( theid ) ) {
3711 newIds->SetId( j, MapOldNodesToNewNodes.Find( theid ) );
3718 // Filtering out cells based on non-existing nodes
3720 int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3721 int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3723 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
3724 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
3728 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3729 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3731 // Copy new data to the old DatSource: keep the single DataSource for all actors
3732 ugrid->DeepCopy(newUgrid);
3734 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3735 Mapper->SetInput( ugrid );
3736 Mactor->SetMapper(Mapper);
3738 // Commented to avoid multiple viewer updates when called by ReadScript()
3742 QApplication::restoreOverrideCursor();
3745 //=============================================================================
3749 //=============================================================================
3750 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3752 QApplication::setOverrideCursor( Qt::waitCursor );
3753 Standard_Boolean result;
3754 SMESH_Actor* ac = FindActor( aMesh, result, true );
3756 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3757 anArrayOfIdeces->length(MapIndex.Extent());
3758 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3760 for ( ; ite.More(); ite.Next() ) {
3761 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
3762 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
3765 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3766 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3769 if ( myAutomaticUpdate ) {
3770 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3771 if ( Mesh != NULL ) {
3772 smeshGUI->DisplayActor( Mesh );
3773 smeshGUI->DisplayEdges( Mesh );
3774 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3775 AddActorInSelection( Mesh );
3778 QApplication::restoreOverrideCursor();
3781 //=============================================================================
3785 //=============================================================================
3786 void SMESHGUI::RemoveElement(SMESH_Actor* Mactor, int idelement)
3788 MESSAGE ( " OLD RemoveElement method " )
3789 // int id = Mactor->GetIdVTKElement( idelement );
3790 // MESSAGE ( " RemoveElement id VTK : " << id )
3791 // if ( Mactor->GetMapper() != NULL ) {
3792 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3793 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3795 // int nbCells = ugrid->GetNumberOfCells();
3796 // for ( int i = 0; i < nbCells; i++ ) {
3798 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3799 // ugrid->GetCell(i)->GetPointIds() );
3801 // Mactor->RemoveElement( idelement );
3803 // newUgrid->SetPoints(ugrid->GetPoints());
3805 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3806 // Mapper->SetInput( newUgrid );
3807 // Mactor->DataSource = Mapper->GetInput();
3808 // Mactor->SetMapper(Mapper);
3814 //=============================================================================
3818 //=============================================================================
3819 void SMESHGUI::RemoveElements(SMESH_Actor* Mactor, int number,
3820 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3822 QApplication::setOverrideCursor( Qt::waitCursor );
3824 while ( i <= number ) {
3825 Mactor->RemoveElement( indexes[i-1] );
3828 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3829 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3831 if ( Mactor->GetMapper() != NULL ) {
3832 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3833 SMESH_Grid* newUgrid = SMESH_Grid::New();
3834 newUgrid->CopyMaps(ugrid);
3836 int nbCells = ugrid->GetNumberOfCells();
3837 for ( int i = 0; i < nbCells; i++ ) {
3838 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
3839 if ( idSMESHDSElement != -1 ) {
3840 int newId = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3841 ugrid->GetCell(i)->GetPointIds() );
3842 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
3843 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
3847 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3848 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3850 newUgrid->SetPoints(ugrid->GetPoints());
3852 // Copy new data to the old DatSource: keep the single DataSource for all actors
3853 ugrid->DeepCopy(newUgrid);
3855 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3856 Mapper->SetInput( ugrid );
3857 Mactor->SetMapper(Mapper);
3859 // Commented to avoid multiple viewer updates when called by ReadScript()
3862 QApplication::restoreOverrideCursor();
3865 //=============================================================================
3869 //=============================================================================
3870 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3872 QApplication::setOverrideCursor( Qt::waitCursor );
3873 Standard_Boolean result;
3874 SMESH_Actor* ac = FindActor( aMesh, result, true );
3876 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3877 anArrayOfIdeces->length(MapIndex.Extent());
3878 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3880 for ( ; ite.More(); ite.Next() ) {
3881 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
3882 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
3886 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3887 aMeshEditor->RemoveElements(anArrayOfIdeces);
3890 if ( myAutomaticUpdate ) {
3891 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3892 if ( Mesh != NULL ) {
3893 smeshGUI->DisplayActor( Mesh );
3894 smeshGUI->DisplayEdges( Mesh );
3895 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3896 AddActorInSelection( Mesh );
3902 QApplication::restoreOverrideCursor();
3906 //=============================================================================
3910 //=============================================================================
3911 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3913 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3916 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3917 Standard_Boolean result;
3918 SMESH_Actor* ac = FindActor( aMesh, result, true );
3920 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3921 SMESH_Grid* UGrid = SMESH_Grid::New();
3922 SMESH_Grid* oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
3923 UGrid->CopyMaps(oldGrid);
3925 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3926 gf->SetInput( ac->DataSource );
3928 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3929 Mapper->SetInput( gf->GetOutput() );
3932 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3933 for ( ; ite.More(); ite.Next() ) {
3934 Mapper->GetInput()->ReverseCell( ite.Key() );
3937 UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
3938 int nbCells = Mapper->GetInput()->GetNumberOfCells();
3939 for ( int i = 0; i < nbCells; i++ ) {
3940 UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
3943 // Copy new data to the old DatSource: keep the single DataSource for all actors
3944 oldGrid->DeepCopy(UGrid);
3946 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
3947 //NewMapper->SetInput( UGrid );
3948 NewMapper->SetInput( oldGrid );
3949 NewMapper->Update();
3951 //ac->DataSource = NewMapper->GetInput();
3952 ac->SetMapper( NewMapper );
3954 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3956 QApplication::restoreOverrideCursor();
3960 //=============================================================================
3964 //=============================================================================
3965 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3967 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3970 QApplication::setOverrideCursor( Qt::waitCursor );
3971 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3972 Standard_Boolean result;
3974 SMESH_Actor* ac = FindActor( aMesh, result, true );
3976 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3977 SMESH_Grid* UGrid = SMESH_Grid::New();
3978 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3979 gf->SetInput( ac->DataSource );
3981 vtkExtractEdges *edges = vtkExtractEdges::New();
3982 edges->SetInput( ac->DataSource );
3984 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3985 Mapper->SetInput( edges->GetOutput() );
3988 int nb = Mapper->GetInput()->GetNumberOfCells();
3989 //MESSAGE ( "nb : " << nb )
3991 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3992 for ( ; ite.More(); ite.Next() ) {
3993 vtkCell* StartEdge = Mapper->GetInput()->GetCell(ite.Key());
3994 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
3995 int CellType = StartEdge->GetCellType();
3996 //MESSAGE( "DCQ : Cell Type = " << CellType)
3997 int nbPoints = StartEdge->GetNumberOfPoints();
3999 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4000 if ( nbPoints == 2 ) {
4001 vtkUnstructuredGrid* StartUGrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
4003 vtkIdList *IdCells = vtkIdList::New();
4004 vtkIdList *IdPoints = StartEdge->GetPointIds();
4008 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),p1);
4009 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),p2);
4011 int idp1 = StartUGrid->FindPoint(p1);
4012 int idp2 = StartUGrid->FindPoint(p2);
4014 StartUGrid->GetPointCells( idp1, IdCells );
4016 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4017 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4019 //MESSAGE ( " pt 0 : " << idp1 )
4020 //MESSAGE ( " pt 1 : " << idp2 )
4022 vtkIdList *IdPts = vtkIdList::New();
4023 if (IdCells->GetNumberOfIds() >= 2) {
4024 int nbCells = IdCells->GetNumberOfIds();
4025 //MESSAGE ( " nbCells : " << nbCells )
4026 for (int j=0; j<nbCells; j++) {
4027 StartUGrid->GetCellPoints( IdCells->GetId(j), IdPts );
4028 if ( IdPts->IsId( idp2 ) == -1 ) {
4029 IdCells->DeleteId( IdCells->GetId(j) );
4034 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4036 vtkIdList *IdPts0 = vtkIdList::New();
4037 vtkIdList *IdPts1 = vtkIdList::New();
4039 if (IdCells->GetNumberOfIds() == 2) {
4040 StartUGrid->GetCellPoints( IdCells->GetId(0), IdPts0 );
4041 StartUGrid->GetCellPoints( IdCells->GetId(1), IdPts1 );
4044 TColStd_MapOfInteger EndMapIndex;
4045 for (int j = 0; j < 3; j++ ) {
4046 if ( IdPts0->GetId(j) != idp1 && IdPts0->GetId(j) != idp2 ) {
4047 EndMapIndex.Add( IdPts0->GetId(j) );
4049 if ( IdPts1->GetId(j) != idp1 && IdPts1->GetId(j) != idp2 ) {
4050 EndMapIndex.Add( IdPts1->GetId(j) );
4054 bool MyAU = myAutomaticUpdate ;
4055 myAutomaticUpdate = false ;
4057 EndMapIndex.Add( idp1 );
4058 TColStd_MapIteratorOfMapOfInteger ite1( EndMapIndex );
4060 while ( ite1.More() ) {
4061 if ( ite1.Key() == idp1 )
4066 bool reverse1 = ( i == 2 );
4067 this->AddFace( aMesh, EndMapIndex, reverse1 );
4069 EndMapIndex.Remove( idp1 );
4070 EndMapIndex.Add( idp2 );
4071 TColStd_MapIteratorOfMapOfInteger ite2( EndMapIndex );
4073 while ( ite2.More() ) {
4074 if ( ite2.Key() == idp2 )
4079 bool reverse2 = ( i == 2 );
4080 this->AddFace( aMesh, EndMapIndex, !(reverse1 == reverse2) );
4082 myAutomaticUpdate = MyAU ;
4083 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4086 TColStd_MapOfInteger StartMapIndex;
4087 StartMapIndex.Add( IdCells->GetId(0) );
4088 StartMapIndex.Add( IdCells->GetId(1) );
4089 this->RemoveElements( aMesh, StartMapIndex );
4097 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4098 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4099 // for ( int i = 0; i < nbCells; i++ ) {
4100 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4103 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4104 // NewMapper->SetInput( UGrid );
4105 // NewMapper->Update();
4107 // ac->DataSource = NewMapper->GetInput();
4108 // ac->SetMapper( NewMapper );
4110 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4112 QApplication::restoreOverrideCursor();
4116 //=============================================================================
4120 //=============================================================================
4121 void SMESHGUI::AddEdges( SMESH_Actor* Mactor, int number,
4122 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4124 QApplication::setOverrideCursor( Qt::waitCursor );
4125 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4126 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4129 while ( i <= number ) {
4130 vtkIdList *Ids = vtkIdList::New();
4131 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4132 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4133 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4134 Mactor->AddElement( indexes[j-1], id );
4138 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4139 EdgeMapper->SetInput( ugrid );
4140 Mactor->DataSource = EdgeMapper->GetInput();
4141 Mactor->SetMapper(EdgeMapper);
4142 QApplication::restoreOverrideCursor();
4145 //=============================================================================
4149 //=============================================================================
4150 void SMESHGUI::AddEdge(SMESH_Actor* Mactor, int idedge, int idnode1, int idnode2)
4152 QApplication::setOverrideCursor( Qt::waitCursor );
4153 MESSAGE ( "SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" << idnode2 )
4154 vtkIdList *Ids = vtkIdList::New();
4155 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4156 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4158 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4159 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4160 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4161 Mactor->AddElement( idedge, id );
4163 MESSAGE ( " Edge VTK id " << id )
4165 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4166 EdgeMapper->SetInput( ugrid );
4167 Mactor->DataSource = EdgeMapper->GetInput();
4168 Mactor->SetMapper(EdgeMapper);
4169 QApplication::restoreOverrideCursor();
4172 //=============================================================================
4176 //=============================================================================
4177 void SMESHGUI::AddTriangles( SMESH_Actor* Mactor, int number,
4178 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4180 QApplication::setOverrideCursor( Qt::waitCursor );
4181 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4182 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4185 while ( i <= number ) {
4186 vtkIdList *Ids = vtkIdList::New();
4187 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4188 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4189 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4190 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4191 Mactor->AddElement( indexes[j-1], id );
4195 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4196 TriMapper->SetInput( ugrid );
4197 Mactor->DataSource = TriMapper->GetInput();
4198 Mactor->SetMapper(TriMapper);
4199 QApplication::restoreOverrideCursor();
4201 void SMESHGUI::AddTriangle(SMESH_Actor* Mactor, int idtri, int idnode1, int idnode2, int idnode3)
4203 QApplication::setOverrideCursor( Qt::waitCursor );
4204 vtkIdList *Ids = vtkIdList::New();
4205 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4206 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4207 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4209 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4210 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4211 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4212 Mactor->AddElement( idtri, id );
4214 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4215 TriMapper->SetInput( ugrid );
4216 Mactor->DataSource = TriMapper->GetInput();
4217 Mactor->SetMapper(TriMapper);
4218 QApplication::restoreOverrideCursor();
4221 //=============================================================================
4225 //=============================================================================
4226 void SMESHGUI::AddQuadrangles( SMESH_Actor* Mactor, int number,
4227 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4229 QApplication::setOverrideCursor( Qt::waitCursor );
4230 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4231 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4234 while ( i <= number ) {
4235 vtkIdList *Ids = vtkIdList::New();
4236 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4237 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4238 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4239 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4240 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4241 Mactor->AddElement( indexes[j-1], id );
4245 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4246 QuadMapper->SetInput( ugrid );
4247 Mactor->DataSource = QuadMapper->GetInput();
4248 Mactor->SetMapper(QuadMapper);
4249 QApplication::restoreOverrideCursor();
4253 //=============================================================================
4257 //=============================================================================
4258 void SMESHGUI::AddQuadrangle(SMESH_Actor* Mactor, int idquad, int idnode1, int idnode2,
4259 int idnode3, int idnode4)
4261 QApplication::setOverrideCursor( Qt::waitCursor );
4262 vtkIdList *Ids = vtkIdList::New();
4263 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4264 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4265 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4266 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4268 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4269 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4270 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4271 Mactor->AddElement( idquad, id );
4273 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4274 QuadMapper->SetInput( ugrid );
4275 Mactor->DataSource = QuadMapper->GetInput();
4276 Mactor->SetMapper(QuadMapper);
4277 QApplication::restoreOverrideCursor();
4281 //=============================================================================
4285 //=============================================================================
4286 void SMESHGUI::AddTetras( SMESH_Actor* Mactor, int number,
4287 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4289 QApplication::setOverrideCursor( Qt::waitCursor );
4290 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4291 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4294 while ( i <= number ) {
4295 vtkIdList *Ids = vtkIdList::New();
4296 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4297 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4298 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4299 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4300 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4301 Mactor->AddElement( indexes[j-1], id );
4305 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4306 TetraMapper->SetInput( ugrid );
4307 Mactor->DataSource = TetraMapper->GetInput();
4308 Mactor->SetMapper(TetraMapper);
4309 QApplication::restoreOverrideCursor();
4313 //=============================================================================
4317 //=============================================================================
4318 void SMESHGUI::AddTetra(SMESH_Actor* Mactor, int idtetra, int idnode1, int idnode2,
4319 int idnode3, int idnode4)
4321 QApplication::setOverrideCursor( Qt::waitCursor );
4322 MESSAGE ( "SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" << idnode2
4323 << ";" << idnode3 << ";" << idnode4 )
4324 vtkIdList *Ids = vtkIdList::New();
4325 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4326 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4327 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4328 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4330 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4331 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4332 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4333 Mactor->AddElement( idtetra, id );
4335 MESSAGE ( " Tetra VTK id " << id )
4337 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4338 TetraMapper->SetInput( ugrid );
4339 Mactor->DataSource = TetraMapper->GetInput();
4340 Mactor->SetMapper(TetraMapper);
4341 QApplication::restoreOverrideCursor();
4345 //=============================================================================
4349 //=============================================================================
4350 void SMESHGUI::AddHexaedres( SMESH_Actor* Mactor, int number,
4351 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4353 QApplication::setOverrideCursor( Qt::waitCursor );
4354 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4355 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4358 while ( i <= number ) {
4359 vtkIdList *Ids = vtkIdList::New();
4360 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4361 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4362 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4363 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4364 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+4] ) );
4365 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+5] ) );
4366 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+6] ) );
4367 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+7] ) );
4368 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4369 Mactor->AddElement( indexes[j-1], id );
4373 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4374 HexaMapper->SetInput( ugrid );
4375 Mactor->DataSource = HexaMapper->GetInput();
4376 Mactor->SetMapper(HexaMapper);
4377 QApplication::restoreOverrideCursor();
4381 //=============================================================================
4385 //=============================================================================
4386 void SMESHGUI::AddHexaedre(SMESH_Actor* Mactor, int idhexa, int idnode1, int idnode2,
4387 int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
4389 QApplication::setOverrideCursor( Qt::waitCursor );
4390 MESSAGE ( "SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" << idnode2
4391 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" << idnode6
4392 << ";" << idnode7 << ";" << idnode8)
4394 vtkIdList *Ids = vtkIdList::New();
4395 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4396 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4397 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4398 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4399 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode5 ) );
4400 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode6 ) );
4401 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode7 ) );
4402 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode8 ) );
4404 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4405 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4406 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4407 Mactor->AddElement( idhexa, id );
4409 MESSAGE ( " Hexa VTK id " << id )
4411 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4412 HexaMapper->SetInput( ugrid );
4413 Mactor->DataSource = HexaMapper->GetInput();
4414 Mactor->SetMapper(HexaMapper);
4415 QApplication::restoreOverrideCursor();
4418 //=====================================================================================
4420 //=====================================================================================
4423 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
4425 return SMESHGUI::OnGUIEvent(theCommandID, parent);
4428 bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4430 return SMESHGUI::OnKeyPress (pe, parent, studyFrame);
4433 bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4435 return SMESHGUI::OnMousePress (pe, parent, studyFrame);
4438 bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4440 return SMESHGUI::OnMouseMove (pe, parent, studyFrame);
4443 bool SetSettings ( QAD_Desktop* parent )
4445 return SMESHGUI::SetSettings( parent );
4448 bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
4449 const QString & theParent, const QString & theObject )
4451 return SMESHGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
4454 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
4456 SMESHGUI::DefinePopup( theContext, theParent, theObject );
4459 bool activeStudyChanged ( QAD_Desktop* parent )
4461 SMESHGUI::activeStudyChanged( parent );
4464 void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
4466 SMESHGUI::BuildPresentation(theIO);
4469 void supportedViewType(int* buffer, int bufferSize)
4471 if (!buffer || !bufferSize) return;
4472 buffer[0] = (int)VIEW_VTK;
4478 //=============================================================================
4482 //=============================================================================
4483 void SMESHGUI::ViewNodes()
4485 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4488 EraseSimulationActors();
4489 mySimulationActors = vtkActorCollection::New();
4490 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4491 vtkActorCollection* theActors = theRenderer->GetActors();
4492 theActors->InitTraversal();
4493 vtkActor *ac = theActors->GetNextActor();
4494 while(!(ac==NULL)) {
4495 if ( ac->IsA("SMESH_Actor") ) {
4496 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
4497 if ( anActor->GetVisibility() == 1 ) {
4498 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4499 gf->SetInput( anActor->DataSource );
4500 vtkMaskPoints *verts = vtkMaskPoints::New();
4501 verts->SetInput(gf->GetOutput());
4502 verts->GenerateVerticesOn();
4503 verts->SetOnRatio(1);
4505 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4506 vertMapper->SetInput(verts->GetOutput());
4507 vertMapper->ScalarVisibilityOff();
4509 vtkActor *vertActor = vtkActor::New();
4510 vertActor->SetMapper(vertMapper);
4513 anActor->GetNodeColor(r, g, b ) ;
4514 vertActor->GetProperty()->SetColor( r, g, b ) ;
4516 vertActor->GetProperty()->SetPointSize( anActor->GetNodeSize() );
4518 vertActor->PickableOff();
4520 mySimulationActors->AddItem( vertActor );
4521 theRenderer->AddActor( vertActor );
4524 ac = theActors->GetNextActor();
4527 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4532 //=============================================================================
4536 //=============================================================================
4537 void SMESHGUI::Control(int theCommandID)
4539 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4542 QApplication::setOverrideCursor( Qt::waitCursor );
4543 DisplayScalarBar( false );
4545 // mpv porting vtk 4.2.2
4546 // vtkScalars *scalars = vtkScalars::New();
4547 vtkIntArray *scalars = vtkIntArray::New();
4548 scalars->SetNumberOfComponents(1);
4550 vtkDataSetMapper* meshMapper = 0;
4551 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4552 int nbSel = Sel->IObjectCount();
4553 Standard_Boolean result;
4554 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
4555 SMESH_Actor* MeshActor = FindActorByEntry(IObject->getEntry(), result, true);
4557 // Mesh may be not updated after Compute
4558 if (!MeshActor->DataSource || !MeshActor->GetMapper()) {
4559 QApplication::restoreOverrideCursor();
4563 bool ValidateScalars = false;
4566 switch (theCommandID)
4568 case 6001: //Length Edges
4570 type = tr( "SMESH_CONTROL_LENGTH_EDGES");
4571 meshMapper = (vtkDataSetMapper*)MeshActor->EdgeDevice->GetMapper();
4572 vtkUnstructuredGrid* grid = (vtkUnstructuredGrid*)meshMapper->GetInput();
4573 MESSAGE ( " init minimum length " << grid->GetNumberOfCells() )
4574 for (int i=0; i<grid->GetNumberOfCells(); i++ ) {
4575 vtkCell* cell = grid->GetCell(i);
4576 float len = SMESHGUI_ComputeScalarValue::LengthEdges(cell);
4577 if (len == 0) continue;
4579 ValidateScalars = true;
4580 // mpv porting vtk 4.2.2
4581 // scalars->InsertScalar(i,len);
4582 scalars->InsertTuple1(i,len);
4585 if (ValidateScalars && (MeshActor->getDisplayMode()!=0))
4586 ChangeRepresentation( MeshActor, 1 );// limitation; in Wireframe, colored edges are not visible
4589 case 6011: // Area Elements
4591 type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
4592 for (int i=0; i< MeshActor->GetMapper()->GetInput()->GetNumberOfCells(); i++ ) {
4593 vtkCell* cell = MeshActor->GetMapper()->GetInput()->GetCell(i);
4594 float area = SMESHGUI_ComputeScalarValue::AreaElements(cell);
4595 if (area == 0) continue;
4597 ValidateScalars = true;
4598 // mpv porting vtk 4.2.2
4599 // scalars->InsertScalar(i,area);
4600 scalars->InsertTuple1(i,area);
4603 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4604 ChangeRepresentation( MeshActor, 1 );
4609 type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
4610 for (int i=0; i< MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4611 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4612 float taper = SMESHGUI_ComputeScalarValue::Taper(cell);
4613 if (taper == 0) continue;
4615 ValidateScalars = true;
4616 // mpv porting vtk 4.2.2
4617 // scalars->InsertScalar(i,taper);
4618 scalars->InsertTuple1(i,taper);
4623 case 6013: // Aspect ratio
4625 type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
4626 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4627 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4628 float aspect = SMESHGUI_ComputeScalarValue::AspectRatio(cell);
4629 if (aspect == 0) continue;
4631 ValidateScalars = true;
4632 // mpv porting vtk 4.2.2
4633 // scalars->InsertScalar(i,aspect);
4634 scalars->InsertTuple1(i,aspect);
4637 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4638 ChangeRepresentation( MeshActor, 1 );
4641 case 6014: // Minimum angle
4643 type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
4644 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4645 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4646 float angle = SMESHGUI_ComputeScalarValue::MinimumAngle(cell);
4647 if (angle == 0) continue;
4649 ValidateScalars = true;
4650 // mpv porting vtk 4.2.2
4651 // scalars->InsertScalar(i,angle);
4652 scalars->InsertTuple1(i,angle);
4655 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4656 ChangeRepresentation( MeshActor, 1 );
4661 type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
4662 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4663 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4664 float Warp = SMESHGUI_ComputeScalarValue::Warp(cell);
4665 if (Warp == 0) continue;
4667 ValidateScalars = true;
4668 // mpv porting vtk 4.2.2
4669 // scalars->InsertScalar(i,Warp);
4670 scalars->InsertTuple1(i,Warp);
4677 type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
4678 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4679 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4680 float angle = SMESHGUI_ComputeScalarValue::Skew(cell);
4681 if (angle == 0) continue;
4683 ValidateScalars = true;
4684 // mpv porting vtk 4.2.2
4685 // scalars->InsertScalar(i,angle);
4686 scalars->InsertTuple1(i,angle);
4693 if ( !ValidateScalars ) {
4694 QApplication::restoreOverrideCursor();
4699 scalars->GetRange(range);
4701 vtkLookupTable* wat = vtkLookupTable::New();
4702 wat->SetRange( range );
4705 scalars->SetLookupTable(wat);
4707 if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
4708 meshMapper->SetScalarModeToUseCellData();
4709 meshMapper->GetInput()->GetCellData()->SetScalars(scalars);
4710 meshMapper->SetScalarRange( range );
4711 meshMapper->ScalarVisibilityOn();
4713 vtkScalarBarActor* aScalarBar = GetScalarBar();
4714 if ( aScalarBar == NULL ) {
4715 aScalarBar = vtkScalarBarActor::New();
4716 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
4717 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
4718 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
4719 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
4720 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
4721 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
4722 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
4723 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
4724 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
4726 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily, Orientation,
4727 Width, Height, NumberOfColors, NumberOfLabels);
4728 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4729 theRenderer->AddActor2D(aScalarBar);
4731 aScalarBar->SetLookupTable( wat );
4732 aScalarBar->SetTitle( type.latin1() );
4736 DisplayScalarBar( true );
4738 QApplication::restoreOverrideCursor();
4742 //=============================================================================
4746 //=============================================================================
4747 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
4748 QString Bold, QString Italic,
4749 QString Shadow, QString FontFamily,
4750 QString Orientation, float Width, float Height,
4751 int NbColors, int NbLabels )
4753 if ( Bold.isNull() || Bold.isEmpty() || (Bold.compare( "true" ) == 0) )
4754 theScalarBar->BoldOn();
4756 theScalarBar->BoldOff();
4758 if ( Italic.isNull() || Italic.isEmpty() || (Italic.compare( "true" ) == 0) )
4759 theScalarBar->ItalicOn();
4761 theScalarBar->ItalicOff();
4763 if ( Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare( "true" ) == 0) )
4764 theScalarBar->ShadowOn();
4766 theScalarBar->ShadowOff();
4768 if ( FontFamily.compare( "Arial" ) == 0 )
4769 theScalarBar->SetFontFamilyToArial();
4770 else if ( FontFamily.compare( "Courier" ) == 0 )
4771 theScalarBar->SetFontFamilyToCourier();
4772 else if ( FontFamily.compare( "Times" ) == 0 )
4773 theScalarBar->SetFontFamilyToTimes();
4775 theScalarBar->SetFontFamilyToArial();
4777 if ( Orientation.isNull() || Orientation.isEmpty() || (Orientation.compare( "Vertical" ) == 0) )
4778 theScalarBar->SetOrientationToVertical();
4780 theScalarBar->SetOrientationToHorizontal();
4783 theScalarBar->SetWidth((Width == 0)? 0.17 : Width);
4784 theScalarBar->SetHeight((Height == 0)? 0.8 : Height);
4786 theScalarBar->SetNumberOfLabels((NbLabels == 0)? 5 : NbLabels);
4787 theScalarBar->SetMaximumNumberOfColors((NbColors == 0)? 64 : NbColors);
4791 //=============================================================================
4795 //=============================================================================
4796 void SMESHGUI::DisplayScalarBar(bool visibility)
4798 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4801 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4802 vtkScalarBarActor* aScalarBar = GetScalarBar();
4804 if ( aScalarBar == NULL ) {
4805 MESSAGE("myScalarBar is NULL");
4810 aScalarBar->VisibilityOn();
4812 aScalarBar->VisibilityOff();
4813 //Turn off mesh coloring (influences on all views)
4814 vtkActorCollection* actorList=theRenderer->GetActors();
4815 actorList->InitTraversal();
4816 vtkActor *ac = actorList->GetNextActor();
4818 if (ac->GetMapper() != NULL) {
4819 ac->GetMapper()->ScalarVisibilityOff();
4821 ac = actorList->GetNextActor();
4823 // Turn off ScalarBar in all views
4824 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
4825 for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
4826 if (aFrame->getTypeView() == VIEW_VTK) {
4827 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
4828 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
4829 actor2DList->InitTraversal();
4830 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
4831 while (aActor2d != NULL) {
4832 if (aActor2d->IsA("vtkScalarBarActor")) {
4833 aActor2d->VisibilityOff();
4836 actor2DList->GetNextActor2D();
4841 myActiveStudy->update3dViewers();
4845 //=============================================================================
4849 //=============================================================================
4850 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
4852 vtkScalarBarActor* aScalarBar = GetScalarBar();
4853 if ( aScalarBar == NULL ) {
4854 MESSAGE("myScalarBar is NULL");
4857 DisplayScalarBar(false);
4859 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
4860 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4861 vtkActorCollection* aActorList = aRenderer->GetActors();
4862 aActorList->InitTraversal();
4863 vtkActor *aActor = aActorList->GetNextActor();
4864 while(aActor != NULL) {
4865 if (aActor->IsA("SMESH_Actor")) {
4866 SMESH_Actor* aMeshActor = SMESH_Actor::SafeDownCast(aActor);
4867 vtkDataSetMapper* aMeshMapper = (vtkDataSetMapper*) (aMeshActor->getMapper());
4868 if ((aMeshMapper != NULL)) {
4869 aMeshMapper->SetScalarRange( MinRange, MaxRange );
4870 aMeshMapper->ScalarVisibilityOn();
4873 aActor = aActorList->GetNextActor();
4875 DisplayScalarBar(true);
4879 //=============================================================================
4883 //=============================================================================
4884 void SMESHGUI::SetDisplaySettings()
4886 EmitSignalDeactivateDialog() ;
4887 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "") ;
4889 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
4890 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
4891 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
4892 QColor color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4893 aDlg->SetColor(1,color);
4895 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
4896 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
4897 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4898 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4899 aDlg->SetColor(2,color);
4901 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4902 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4903 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4904 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4905 aDlg->SetColor(3,color);
4907 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4908 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4909 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4910 color = QColor (SBr.toInt(), SBg.toInt(), SBb.toInt());
4911 aDlg->SetColor(4,color);
4913 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4914 aDlg->SetIntValue(1,intValue.toInt());
4915 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4916 aDlg->SetIntValue(2,intValue.toInt());
4917 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4918 aDlg->SetIntValue(3,intValue.toInt());
4920 if ( aDlg->exec() ) {
4921 QColor colorFill = aDlg->GetColor( 1 );
4922 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4923 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4924 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4926 QColor colorOutline = aDlg->GetColor( 2 );
4927 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4928 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4929 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4931 QColor colorNode = aDlg->GetColor( 3 );
4932 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4933 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4934 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4936 QColor colorBackFace = aDlg->GetColor( 4 );
4937 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4938 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4939 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4941 int width = aDlg->GetIntValue( 1 );
4942 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4944 int nodes_size = aDlg->GetIntValue( 2 );
4945 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4947 int shrink_coeff = aDlg->GetIntValue( 3 );
4948 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4954 //=======================================================================
4955 // function : Parameter()
4956 // purpose : return a parameter (double) from a dialog box
4958 // aValue : is a double used as a default value displayed
4959 // aLabel : is the title for aValue1
4960 // aTitle : is the main title
4961 // bottom : maximum value to be entered
4962 // top : minimum value to be entered
4963 // decimals : number of decimals
4964 //=======================================================================
4965 double SMESHGUI::Parameter( Standard_Boolean& res,
4966 const double aValue,
4969 const double bottom,
4971 const int decimals )
4973 SMESHGUI_aParameterDlg* Dialog =
4974 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4977 bottom, top, decimals,
4979 Dialog->setValue( aValue );
4981 res = ( Dialog->exec() == QDialog::Accepted );
4983 X = Dialog->getDblValue();
4987 //=======================================================================
4988 // function : Parameter()
4989 // purpose : return a parameter (int) from a dialog box
4991 // aValue : is a int used as a default value displayed
4992 // aLabel : is the title for aValue1
4993 // aTitle : is the main title
4994 // bottom : maximum value to be entered
4995 // top : minimum value to be entered
4996 //=======================================================================
4997 int SMESHGUI::Parameter( Standard_Boolean& res,
5004 SMESHGUI_aParameterDlg* Dialog =
5005 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
5010 Dialog->setValue( aValue );
5012 res = ( Dialog->exec() == QDialog::Accepted );
5014 X = Dialog->getIntValue();
5018 //=============================================================================
5022 //=============================================================================
5023 void SMESHGUI::DisplayEdges(SMESH_Actor* ac, bool visibility)
5025 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5027 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5030 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5031 gf->SetInput(ac->DataSource);
5032 vtkFeatureEdges *edges = vtkFeatureEdges::New();
5033 edges->SetInput(gf->GetOutput());
5034 edges->BoundaryEdgesOn();
5035 edges->ManifoldEdgesOn();
5037 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5038 edgeMapper->SetInput(edges->GetOutput());
5039 edgeMapper->ScalarVisibilityOff();
5041 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5042 vtkActorCollection* actorList=theRenderer->GetActors();
5044 int test=actorList->IsItemPresent(ac->EdgeDevice);
5046 vtkProperty* prop = vtkProperty::New();
5047 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5048 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5049 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5050 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5051 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5052 ac->EdgeDevice->SetProperty(prop);
5053 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5054 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5055 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5056 ac->EdgeDevice->SetMapper(edgeMapper);
5058 theRenderer->AddActor(ac->EdgeDevice);
5060 ac->EdgeDevice->SetMapper(edgeMapper);
5061 edgeMapper->Update();
5064 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5065 shrink->SetInput(ac->DataSource);
5066 shrink->SetShrinkFactor(ac->GetShrinkFactor());
5067 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5068 Shrinkgf->SetInput( shrink->GetOutput() );
5069 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5070 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5071 ShrinkEdges->BoundaryEdgesOn();
5072 ShrinkEdges->ManifoldEdgesOn();
5074 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5075 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5076 ShrinkEdgeMapper->ScalarVisibilityOff();
5078 test=actorList->IsItemPresent(ac->EdgeShrinkDevice);
5080 vtkProperty* prop = vtkProperty::New();
5081 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5082 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5083 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5084 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5085 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5086 ac->EdgeShrinkDevice->SetProperty(prop);
5087 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5088 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5089 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5090 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5092 theRenderer->AddActor(ac->EdgeShrinkDevice);
5094 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5095 ShrinkEdgeMapper->Update();
5098 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5103 //=============================================================================
5107 //=============================================================================
5108 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5110 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh( aMesh );
5111 SALOMEDS::GenericAttribute_var anAttr;
5112 SALOMEDS::AttributeName_var aName;
5113 if ( !aSO_M->_is_nil() ) {
5114 if (aSO_M->FindAttribute(anAttr, "AttributeName") ) {
5115 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5116 Standard_Boolean result;
5117 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5119 SMESH_Actor* amesh = SMESH_Actor::New();
5120 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(aSO_M->GetID(),
5124 amesh->setName( aName->Value() );
5125 DisplayActor(amesh, false);
5132 //=============================================================================
5136 //=============================================================================
5137 void SMESHGUI::Update()
5139 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
5140 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5142 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5143 int nbSel = Sel->IObjectCount();
5145 vtkActorCollection* actorList=theRenderer->GetActors();
5146 actorList->InitTraversal();
5147 vtkActor *ac = actorList->GetNextActor();
5148 while(!(ac==NULL)) {
5149 if ( ac->IsA("SMESH_Actor") ) {
5150 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5151 if ( anActor->hasIO() ) {
5152 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5156 ac = actorList->GetNextActor();
5159 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5160 for ( ; It.More(); It.Next() ) {
5161 Handle(SALOME_InteractiveObject) IO = It.Value();
5165 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5168 QApplication::restoreOverrideCursor();
5172 //=============================================================================
5176 //=============================================================================
5177 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject)& IO)
5179 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5182 if ( IO->hasEntry() ) {
5183 Standard_Boolean res;
5184 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh( IO, res );
5186 SMESH_Actor* ac = FindActorByEntry( IO->getEntry(), res, false );
5188 // Check whether the actor belongs to the active view
5189 VTKViewer_RenderWindowInteractor* rwInter =
5190 ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5192 // The actor belongs to inactive view -> create a copy and display it in the active view
5193 if (!rwInter->isInViewer(IO)) {
5194 SMESH_Actor* acCopy = SMESH_Actor::New();
5195 acCopy->ShallowCopy(ac);
5197 smeshGUI->DisplayActor( acCopy, false );
5199 ac = ReadScript( aMesh );
5206 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
5214 //=============================================================================
5218 //=============================================================================
5219 vtkActor* SMESHGUI::SimulationMoveNode(SMESH_Actor* Mactor, int idnode)
5221 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5224 mySimulationActors = vtkActorCollection::New();
5225 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5227 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5228 vtkIdList *IdCells = vtkIdList::New();
5229 ugrid->GetPointCells( idnode, IdCells );
5231 vtkPoints *Pts = vtkPoints::New();
5232 Pts = ugrid->GetPoints();
5234 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
5235 ugridSimulation->SetPoints( Pts );
5236 vtkIdList *IdPts = vtkIdList::New();
5237 for (int j=0; j<IdCells->GetNumberOfIds(); j++) {
5238 ugrid->GetCellPoints( IdCells->GetId(j), IdPts );
5239 ugridSimulation->InsertNextCell( ugrid->GetCellType( IdCells->GetId(j) ), IdPts );
5242 vtkProperty* prop = vtkProperty::New();
5243 prop->SetColor( 1., 0., 0. );
5244 prop->SetRepresentationToWireframe();
5246 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
5247 if ( Edgewidth == 0 )
5249 prop->SetLineWidth( Edgewidth+1 );
5251 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5252 Mapper->SetInput( ugridSimulation );
5253 vtkActor* ac = vtkActor::New();
5254 ac->SetMapper( Mapper );
5255 ac->SetProperty( prop );
5257 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
5258 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
5260 mySimulationActors->AddItem( ac );
5261 theRenderer->AddActor( ac );
5263 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5270 //=============================================================================
5274 //=============================================================================
5275 void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5277 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5280 EraseSimulationActors();
5281 mySimulationActors = vtkActorCollection::New();
5282 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5283 Standard_Boolean result;
5284 SMESH_Actor* ac = FindActor( aMesh, result, true );
5287 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5288 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5290 vtkPoints *Pts = ugrid->GetPoints();
5291 vtkPoints *newPts = vtkPoints::New();
5292 int nbPts = Pts->GetNumberOfPoints();
5293 for ( int i = 0; i < nbPts; i++ ) {
5294 newPts->InsertPoint(i, Pts->GetPoint(i) );
5297 newugrid->SetPoints(newPts);
5298 newugrid->GetPoints()->InsertNextPoint( x, y, z );
5300 vtkMaskPoints* verts = vtkMaskPoints::New();
5301 verts->SetInput(newugrid);
5302 verts->SetGenerateVertices(1);
5303 verts->SetOnRatio(1);
5305 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
5306 vertMapper->SetInput( verts->GetOutput() );
5307 vertMapper->ScalarVisibilityOff();
5309 vtkActor* node = vtkActor::New();
5310 node->SetMapper( vertMapper );
5312 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5313 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5314 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5315 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5316 if ( !nodecolor.isValid() )
5317 nodecolor = QColor(0.,1.,0.);
5319 node->GetProperty()->SetColor( float(nodecolor.red())/255.,
5320 float(nodecolor.green())/255.,
5321 float(nodecolor.blue())/255.);
5323 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
5327 node->GetProperty()->SetPointSize( intValue );
5329 node->VisibilityOn();
5331 mySimulationActors->AddItem( node );
5332 theRenderer->AddActor(node);
5335 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5339 //=============================================================================
5343 //=============================================================================
5344 void SMESHGUI::DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z)
5346 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5349 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5350 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
5351 pt[0] = x; pt[1] = y; pt[2] = z;
5353 ac->GetMapper()->ImmediateModeRenderingOn();
5354 ac->GetProperty()->SetRepresentationToWireframe();
5356 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5362 //=============================================================================
5366 //=============================================================================
5367 void SMESHGUI::MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z)
5369 Standard_Boolean result;
5371 SMESH_Actor* MeshActor = FindActor(aMesh, result, true);
5377 //=============================================================================
5381 //=============================================================================
5382 void SMESHGUI::ScalarVisibilityOff()
5384 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5387 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5388 vtkActorCollection* actorList=theRenderer->GetActors();
5390 actorList->InitTraversal();
5391 vtkActor *ac = actorList->GetNextActor();
5392 while(!(ac==NULL)) {
5393 if ( ac->IsA("SMESH_Actor") ) {
5394 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5395 if ( anActor->GetVisibility() == 1 ) {
5396 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (anActor->getMapper());
5397 meshMapper->ScalarVisibilityOff();
5398 meshMapper->SetInput( anActor->DataSource );
5399 ChangeRepresentation( anActor, anActor->getDisplayMode() );
5402 ac = actorList->GetNextActor();
5405 theRenderer->Render();
5409 //=============================================================================
5413 //=============================================================================
5414 void SMESHGUI::DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5416 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5419 EraseSimulationActors();
5420 mySimulationActors = vtkActorCollection::New();
5421 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5422 Standard_Boolean result;
5423 SMESH_Actor* ac = FindActor( aMesh, result, true );
5425 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5429 vtkIdList *Ids = vtkIdList::New();
5430 for ( ; ite.More(); ite.Next() ) {
5431 idNodes[i] = ite.Key();
5435 Ids->InsertId( 0, idNodes[0] );
5436 pts[0] = idNodes[0];
5437 Ids->InsertId( 1, idNodes[1] );
5438 pts[1] = idNodes[1];
5440 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5441 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5442 newugrid->SetPoints( ugrid->GetPoints() ) ;
5443 newugrid->InsertNextCell(VTK_LINE, 2, pts);
5445 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5446 Mapper->SetInput( newugrid );
5449 vtkActor* edge = vtkActor::New();
5450 edge->SetMapper( Mapper );
5451 edge->SetProperty( ac->GetProperty() );
5452 edge->SetBackfaceProperty( ac->GetBackfaceProperty() );
5453 edge->VisibilityOn();
5454 mySimulationActors->AddItem( edge );
5455 theRenderer->AddActor(edge);
5458 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5463 //=============================================================================
5467 //=============================================================================
5468 void SMESHGUI::DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5470 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5473 EraseSimulationActors();
5474 mySimulationActors = vtkActorCollection::New();
5475 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5476 Standard_Boolean result;
5477 SMESH_Actor* ac = FindActor( aMesh, result, true );
5479 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5483 vtkIdList *Ids = vtkIdList::New();
5484 for ( ; ite.More(); ite.Next() ) {
5485 idNodes[i] = ite.Key();
5490 Ids->InsertId( 0, idNodes[2] );
5491 pts[0] = idNodes[2];
5492 Ids->InsertId( 1, idNodes[1] );
5493 pts[1] = idNodes[1];
5494 Ids->InsertId( 2, idNodes[0] );
5495 pts[2] = idNodes[0];
5497 Ids->InsertId( 0, idNodes[0] );
5498 pts[0] = idNodes[0];
5499 Ids->InsertId( 1, idNodes[1] );
5500 pts[1] = idNodes[1];
5501 Ids->InsertId( 2, idNodes[2] );
5502 pts[2] = idNodes[2];
5504 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5505 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5506 newugrid->SetPoints( ugrid->GetPoints() ) ;
5507 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
5509 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5510 Mapper->SetInput( newugrid );
5513 vtkActor* tri = vtkActor::New();
5514 tri->SetMapper( Mapper );
5515 tri->SetProperty( ac->GetProperty() );
5516 tri->SetBackfaceProperty( ac->GetBackfaceProperty() );
5517 tri->VisibilityOn();
5518 mySimulationActors->AddItem( tri );
5519 theRenderer->AddActor(tri);
5522 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5527 //=============================================================================
5531 //=============================================================================
5532 void SMESHGUI::DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5534 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5537 EraseSimulationActors();
5538 mySimulationActors = vtkActorCollection::New();
5539 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5540 Standard_Boolean result;
5541 SMESH_Actor* ac = FindActor( aMesh, result, true );
5543 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5546 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5549 vtkIdList *Ids = vtkIdList::New();
5550 for ( ; ite.More(); ite.Next() ) {
5551 idNodes[i] = ite.Key();
5555 float *p0 = ugrid->GetPoint(idNodes[0]);
5556 float *p1 = ugrid->GetPoint(idNodes[1]);
5557 float *p2 = ugrid->GetPoint(idNodes[2]);
5558 float *p3 = ugrid->GetPoint(idNodes[3]);
5560 gp_Pnt P0(p0[0],p0[1],p0[2]);
5562 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5563 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5564 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5566 gp_Vec Cross1 = V1 ^ V2;
5567 gp_Vec Cross2 = V2 ^ V3;
5570 if ( Cross1.Dot(Cross2) < 0 ) {
5571 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5572 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5576 if ( Cross1.Dot(Cross2) < 0 ) {
5578 idNodes[2] = idNodes[3];
5582 idNodes[1] = idNodes[2];
5588 Ids->InsertId( 0, idNodes[3] );
5589 Ids->InsertId( 1, idNodes[2] );
5590 Ids->InsertId( 2, idNodes[1] );
5591 Ids->InsertId( 3, idNodes[0] );
5593 Ids->InsertId( 0, idNodes[0] );
5594 Ids->InsertId( 1, idNodes[1] );
5595 Ids->InsertId( 2, idNodes[2] );
5596 Ids->InsertId( 3, idNodes[3] );
5599 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5600 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5601 newugrid->SetPoints( ugrid->GetPoints() ) ;
5602 newugrid->InsertNextCell(VTK_QUAD, Ids);
5604 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5605 Mapper->SetInput( newugrid );
5608 vtkActor* quad = vtkActor::New();
5609 quad->SetMapper( Mapper );
5610 quad->SetProperty( ac->GetProperty() );
5611 quad->SetBackfaceProperty( ac->GetBackfaceProperty() );
5612 quad->VisibilityOn();
5613 mySimulationActors->AddItem( quad );
5614 theRenderer->AddActor(quad);
5616 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5621 //=============================================================================
5625 //=============================================================================
5626 void SMESHGUI::DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5628 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5631 EraseSimulationActors();
5632 mySimulationActors = vtkActorCollection::New();
5633 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5634 Standard_Boolean result;
5635 SMESH_Actor* ac = FindActor( aMesh, result, true );
5637 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5640 vtkIdList *Ids = vtkIdList::New();
5641 for ( ; ite.More(); ite.Next() ) {
5642 idNodes[i] = ite.Key();
5646 Ids->InsertId( 0, idNodes[0] );
5647 Ids->InsertId( 1, idNodes[1] );
5648 Ids->InsertId( 2, idNodes[2] );
5649 Ids->InsertId( 3, idNodes[3] );
5651 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5652 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5653 newugrid->SetPoints( ugrid->GetPoints() ) ;
5654 newugrid->InsertNextCell(VTK_TETRA, Ids);
5656 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5657 Mapper->SetInput( newugrid );
5660 vtkActor* tetra = vtkActor::New();
5661 tetra->SetMapper( Mapper );
5662 tetra->SetProperty( ac->GetProperty() );
5663 tetra->SetBackfaceProperty( ac->GetBackfaceProperty() );
5664 tetra->VisibilityOn();
5665 mySimulationActors->AddItem( tetra );
5666 theRenderer->AddActor(tetra);
5668 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5673 //=============================================================================
5677 //=============================================================================
5678 void SMESHGUI::DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5680 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5683 EraseSimulationActors();
5684 mySimulationActors = vtkActorCollection::New();
5685 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5686 Standard_Boolean result;
5687 SMESH_Actor* ac = FindActor( aMesh, result, true );
5689 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5692 vtkIdList *Ids = vtkIdList::New();
5693 for ( ; ite.More(); ite.Next() ) {
5694 idNodes[i] = ite.Key();
5698 Ids->InsertId( 0, idNodes[0] );
5699 Ids->InsertId( 1, idNodes[1] );
5700 Ids->InsertId( 2, idNodes[2] );
5701 Ids->InsertId( 3, idNodes[3] );
5702 Ids->InsertId( 4, idNodes[4] );
5703 Ids->InsertId( 5, idNodes[5] );
5704 Ids->InsertId( 6, idNodes[6] );
5705 Ids->InsertId( 7, idNodes[7] );
5707 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5708 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5709 newugrid->SetPoints( ugrid->GetPoints() ) ;
5710 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5712 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5713 Mapper->SetInput( newugrid );
5716 vtkActor* hexa = vtkActor::New();
5717 hexa->SetMapper( Mapper );
5718 hexa->SetProperty( ac->GetProperty() );
5719 hexa->SetBackfaceProperty( ac->GetBackfaceProperty() );
5720 hexa->VisibilityOn();
5721 mySimulationActors->AddItem( hexa );
5722 theRenderer->AddActor(hexa);
5724 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5729 //=============================================================================
5733 //=============================================================================
5734 void SMESHGUI::AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5736 QApplication::setOverrideCursor( Qt::waitCursor );
5737 Standard_Boolean result;
5738 SMESH_Actor* ac = FindActor( aMesh, result, true );
5740 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5741 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5742 anArrayOfIdeces->length(MapIndex.Extent());
5745 for ( ; ite.More(); ite.Next() ) {
5746 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5751 if ( MapIndex.Extent() == 4 ) {
5754 TColStd_MapIteratorOfMapOfInteger ite1( MapIndex );
5755 for ( ; ite1.More(); ite1.Next() ) {
5756 idNodes[i] = ite1.Key();
5760 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5761 float *p0 = ugrid->GetPoint(idNodes[0]);
5762 float *p1 = ugrid->GetPoint(idNodes[1]);
5763 float *p2 = ugrid->GetPoint(idNodes[2]);
5764 float *p3 = ugrid->GetPoint(idNodes[3]);
5766 gp_Pnt P0(p0[0],p0[1],p0[2]);
5768 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5769 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5770 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5772 gp_Vec Cross1 = V1 ^ V2;
5773 gp_Vec Cross2 = V2 ^ V3;
5775 if ( Cross1.Dot(Cross2) < 0 ) {
5777 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5778 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5782 if ( Cross1.Dot(Cross2) < 0 ) {
5783 tmp = anArrayOfIdeces[2];
5784 anArrayOfIdeces[2] = anArrayOfIdeces[3];
5785 anArrayOfIdeces[3] = tmp;
5787 tmp = anArrayOfIdeces[1];
5788 anArrayOfIdeces[1] = anArrayOfIdeces[2];
5789 anArrayOfIdeces[2] = tmp;
5796 for (i=0; i < (MapIndex.Extent()/2); i++) {
5797 tmp = anArrayOfIdeces[i];
5798 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent()-i-1];
5799 anArrayOfIdeces[MapIndex.Extent()-i-1] = tmp;
5802 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5803 aMeshEditor->AddFace(anArrayOfIdeces);
5805 if ( myAutomaticUpdate ) {
5806 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5807 if ( Mesh != NULL ) {
5808 smeshGUI->DisplayActor( Mesh );
5809 smeshGUI->DisplayEdges( Mesh );
5810 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5811 AddActorInSelection( Mesh );
5814 QApplication::restoreOverrideCursor();
5818 //=============================================================================
5822 //=============================================================================
5823 void SMESHGUI::AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5825 QApplication::setOverrideCursor( Qt::waitCursor );
5826 Standard_Boolean result;
5827 SMESH_Actor* ac = FindActor( aMesh, result, true );
5829 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5830 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5831 anArrayOfIdeces->length(MapIndex.Extent());
5834 for ( ; ite.More(); ite.Next() ) {
5835 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5839 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5840 aMeshEditor->AddVolume(anArrayOfIdeces);
5842 if ( myAutomaticUpdate ) {
5843 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5844 if ( Mesh != NULL ) {
5845 smeshGUI->DisplayActor( Mesh );
5846 smeshGUI->DisplayEdges( Mesh );
5847 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5848 AddActorInSelection( Mesh );
5851 QApplication::restoreOverrideCursor();
5855 //=============================================================================
5859 //=============================================================================
5860 void SMESHGUI::AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5862 QApplication::setOverrideCursor( Qt::waitCursor );
5863 Standard_Boolean result;
5864 SMESH_Actor* ac = FindActor( aMesh, result, true );
5866 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5867 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5868 anArrayOfIdeces->length(MapIndex.Extent());
5871 for ( ; ite.More(); ite.Next() ) {
5872 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5876 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5877 aMeshEditor->AddEdge(anArrayOfIdeces);
5879 if ( myAutomaticUpdate ) {
5880 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5881 if ( Mesh != NULL ) {
5882 smeshGUI->DisplayActor( Mesh );
5883 smeshGUI->DisplayEdges( Mesh );
5884 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5885 AddActorInSelection( Mesh );
5888 QApplication::restoreOverrideCursor();
5891 //=============================================================================
5895 //=============================================================================
5896 void SMESHGUI::AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5898 QApplication::setOverrideCursor( Qt::waitCursor );
5899 Standard_Boolean result;
5900 SMESH_Actor* ac = FindActor( aMesh, result, true );
5902 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5903 aMeshEditor->AddNode(x,y,z);
5905 if ( myAutomaticUpdate ) {
5906 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5907 if ( Mesh != NULL ) {
5908 smeshGUI->DisplayActor( Mesh );
5909 smeshGUI->DisplayEdges( Mesh );
5910 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5911 AddActorInSelection( Mesh );
5915 QApplication::restoreOverrideCursor();
5918 //=============================================================================
5922 //=============================================================================
5923 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor *ac)
5925 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5928 EraseSimulationActors();
5929 mySimulationActors2D = vtkActor2DCollection::New();
5931 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5933 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
5934 gs2->SetGlyphTypeToTriangle();
5937 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
5938 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
5939 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
5941 legend->SetNumberOfEntries(4);
5942 legend->SetEntryString( 0, tr( "SMESH_BOUNDARYEDGES" ) );
5943 legend->SetEntrySymbol( 0, gs2->GetOutput() );
5944 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.) );
5945 legend->SetEntryString( 1, tr( "SMESH_MANIFOLDEDGES" ) );
5946 legend->SetEntrySymbol( 1, gs2->GetOutput() );
5947 legend->SetEntryColor(1, ac->GetMapper()->GetLookupTable()->GetColor(0.666667) );
5948 legend->SetEntryString( 2, tr( "SMESH_NONMANIFOLDEDGES" ) );
5949 legend->SetEntrySymbol( 2, gs2->GetOutput() );
5950 legend->SetEntryColor(2, ac->GetMapper()->GetLookupTable()->GetColor(0.222222) );
5951 legend->SetEntryString( 3, tr( "SMESH_FEATUREEDGES" ) );
5952 legend->SetEntrySymbol( 3, gs2->GetOutput() );
5953 legend->SetEntryColor(3, ac->GetMapper()->GetLookupTable()->GetColor(0.444444) );
5954 legend->SetPadding( 5 );
5955 // legend->GetProperty()->SetColor();
5957 mySimulationActors2D->AddItem( legend );
5958 theRenderer->AddActor2D( legend );
5961 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5964 //===============================================================================
5965 // function : OnEditDelete()
5967 //===============================================================================
5968 void SMESHGUI::OnEditDelete()
5970 if ( QAD_MessageBox::warn2
5971 ( QAD_Application::getDesktop(),
5972 tr ("SMESH_WRN_WARNING"),
5973 tr ("SMESH_REALLY_DELETE"),
5974 tr ("SMESH_BUT_YES"), tr ("SMESH_BUT_NO"), 1, 0, 0 ) != 1 )
5977 int nbSf = myActiveStudy->getStudyFramesCount();
5979 Standard_Boolean found;
5980 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5981 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
5982 SALOMEDS::GenericAttribute_var anAttr;
5983 SALOMEDS::AttributeIOR_var anIOR;
5985 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5986 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5987 for(;It.More();It.Next()) {
5988 Handle(SALOME_InteractiveObject) IObject = It.Value();
5989 if ( IObject->hasEntry() ) {
5990 SALOMEDS::SObject_var SO = myStudy->FindObjectID( IObject->getEntry() );
5992 /* Erase child graphical objects */
5993 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5994 for (; it->More();it->Next()) {
5995 SALOMEDS::SObject_var CSO= it->Value();
5996 if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
5997 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5999 for ( int i = 0; i < nbSf; i++ ) {
6000 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
6001 if ( sf->getTypeView() == VIEW_VTK ) {
6002 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6003 SMESH_Actor* ac = smeshGUI->FindActorByEntry( CSO->GetID(), found, false );
6005 Renderer->RemoveActor(ac->EdgeDevice);
6006 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6007 Renderer->RemoveActor(ac);
6014 /* Erase main graphical object */
6015 for ( int i = 0; i < nbSf; i++ ) {
6016 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
6017 if ( sf->getTypeView() == VIEW_VTK ) {
6018 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6019 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
6020 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), found, false );
6022 Renderer->RemoveActor(ac->EdgeDevice);
6023 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6025 myRenderInter->Remove( IObject );
6029 /* Erase objects in Study */
6030 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
6031 if ( !obj->_is_nil() ) {
6032 QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
6034 aStudyBuilder->RemoveObject(obj);
6038 } /* IObject->hasEntry() */
6041 /* Clear any previous selection */
6042 Sel->ClearIObjects() ;
6043 myActiveStudy->updateObjBrowser();