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 );
850 if ( !Hyp->_is_nil() ) {
851 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms( Hyp );
852 myStudyAPI.SetName( SHyp, NameAlgo);
855 catch (const SALOME::SALOME_Exception& S_ex) {
856 QtCatchCorbaException(S_ex);
858 myActiveStudy->updateObjBrowser(true);
862 //=============================================================================
866 //=============================================================================
867 void SMESHGUI::CreateLocalLength( QString TypeHypothesis, QString NameHypothesis, double Length )
869 QApplication::setOverrideCursor( Qt::waitCursor );
871 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
872 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
873 if ( !LL->_is_nil() )
874 LL->SetLength( Length );
876 catch (const SALOME::SALOME_Exception& S_ex) {
877 QtCatchCorbaException(S_ex);
879 myActiveStudy->updateObjBrowser(true);
880 QApplication::restoreOverrideCursor();
883 //=============================================================================
887 //=============================================================================
888 void SMESHGUI::CreateMaxElementArea( QString TypeHypothesis, QString NameHypothesis, double MaxArea )
890 QApplication::setOverrideCursor( Qt::waitCursor );
892 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
893 SMESH::SMESH_MaxElementArea_var MaxElArea = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
894 if ( !MaxElArea->_is_nil() )
895 MaxElArea->SetMaxElementArea( MaxArea );
897 catch (SALOME::SALOME_Exception& S_ex) {
898 QtCatchCorbaException(S_ex);
901 myActiveStudy->updateObjBrowser(true);
902 QApplication::restoreOverrideCursor();
905 //=============================================================================
909 //=============================================================================
910 void SMESHGUI::CreateMaxElementVolume( QString TypeHypothesis, QString NameHypothesis, double MaxVolume )
912 QApplication::setOverrideCursor( Qt::waitCursor );
914 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
915 SMESH::SMESH_MaxElementVolume_var MaxElVolume = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
916 if ( !MaxElVolume->_is_nil() )
917 MaxElVolume->SetMaxElementVolume( MaxVolume );
919 catch (const SALOME::SALOME_Exception& S_ex) {
920 QtCatchCorbaException(S_ex);
922 myActiveStudy->updateObjBrowser(true);
923 QApplication::restoreOverrideCursor();
926 //=============================================================================
930 //=============================================================================
931 void SMESHGUI::CreateNbSegments( QString TypeHypothesis, QString NameHypothesis, double nbSegments )
933 QApplication::setOverrideCursor( Qt::waitCursor );
935 SMESH::SMESH_Hypothesis_var Hyp = SMESH::SMESH_Hypothesis::_narrow( CreateHypothesis( TypeHypothesis, NameHypothesis ) );
936 SMESH::SMESH_NumberOfSegments_var NbS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
937 if ( !NbS->_is_nil() )
938 NbS->SetNumberOfSegments( nbSegments );
940 catch (const SALOME::SALOME_Exception& S_ex) {
941 QtCatchCorbaException(S_ex);
943 myActiveStudy->updateObjBrowser(true);
944 QApplication::restoreOverrideCursor();
947 //=============================================================================
951 //=============================================================================
952 int SMESHGUI::GetNameOfSelectedIObjects( SALOME_Selection* Sel, QString& aName )
954 int nbSel = Sel->IObjectCount() ;
956 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
957 aName = IObject->getName();
959 aName = tr( "SMESH_OBJECTS_SELECTED" ).arg( nbSel );
964 //=============================================================================
968 //=============================================================================
969 int SMESHGUI::GetNameOfSelectedNodes( SALOME_Selection* Sel, QString& aName )
972 int nbSel = Sel->IObjectCount() ;
974 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
975 if ( !IObject->hasEntry() )
978 Standard_Boolean res;
979 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
983 TColStd_MapOfInteger MapIndex;
984 Sel->GetIndex( IObject, MapIndex );
985 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
987 nbNodes = MapIndex.Extent();
988 for ( ; ite.More(); ite.Next() ) {
989 aName = aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) + " ";
997 //=============================================================================
1001 //=============================================================================
1002 int SMESHGUI::GetNameOfSelectedElements( SALOME_Selection* Sel, QString& aName )
1005 int nbSel = Sel->IObjectCount() ;
1007 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1008 if ( !IObject->hasEntry() )
1011 Standard_Boolean res;
1012 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1016 TColStd_MapOfInteger MapIndex;
1017 Sel->GetIndex( IObject, MapIndex );
1018 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1020 nbElements = MapIndex.Extent();
1021 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1022 for ( ; ite.More(); ite.Next() ) {
1023 int idVTK = ite.Key();
1024 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1025 aName = aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1034 //=============================================================================
1038 //=============================================================================
1039 int SMESHGUI::GetNameOfSelectedEdges( SALOME_Selection* Sel, QString& aName )
1042 int nbSel = Sel->IObjectCount() ;
1044 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1045 if ( !IObject->hasEntry() )
1048 Standard_Boolean res;
1049 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1053 TColStd_MapOfInteger MapIndex;
1054 Sel->GetIndex( IObject, MapIndex );
1055 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
1057 nbElements = MapIndex.Extent();
1058 for ( ; ite.More(); ite.Next() ) {
1059 aName = aName + QString("%1").arg(ite.Key()) + " ";
1068 //=============================================================================
1072 //=============================================================================
1073 SMESH_Actor* SMESHGUI::FindActorByEntry(QString entry,
1074 Standard_Boolean& testResult,
1075 bool onlyInActiveView)
1077 int nbSf = myActiveStudy->getStudyFramesCount();
1078 for ( int i = 0; i < nbSf; i++ ) {
1079 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
1080 if ( sf->getTypeView() == VIEW_VTK ) {
1081 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRenderer();
1082 vtkActorCollection* theActors = Renderer->GetActors();
1083 theActors->InitTraversal();
1084 vtkActor *ac = theActors->GetNextActor();
1085 while(!(ac==NULL)) {
1086 if ( ac->IsA("SMESH_Actor") ) {
1087 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1088 if ( anActor->hasIO() ) {
1089 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1090 if ( strcmp( IO->getEntry(), entry ) == 0 ) {
1091 if ( onlyInActiveView ) {
1092 if ( sf == myActiveStudy->getActiveStudyFrame() ) {
1103 ac = theActors->GetNextActor();
1108 MESSAGE ( " Actor Not Found " )
1110 return SMESH_Actor::New();
1113 //=============================================================================
1117 //=============================================================================
1118 SMESH_Actor* SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1119 Standard_Boolean& testResult,
1120 bool onlyInActiveView)
1122 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh( aMesh );
1123 if ( SM->_is_nil() ) {
1124 MESSAGE ( " Actor Not Found " )
1127 return SMESH_Actor::New();
1130 return FindActorByEntry( SM->GetID(), testResult, onlyInActiveView);
1133 //=============================================================================
1137 //=============================================================================
1138 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject)& IO,
1139 Standard_Boolean& testResult)
1141 SMESH::SMESH_Mesh_var aMesh;
1142 testResult = false ;
1145 if ( IO->hasEntry() ) {
1146 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1147 SALOMEDS::GenericAttribute_var anAttr;
1148 SALOMEDS::AttributeIOR_var anIOR;
1149 if ( !obj->_is_nil() ) {
1150 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1151 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1152 aMesh = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1153 if ( !aMesh->_is_nil() ) {
1155 return SMESH::SMESH_Mesh::_duplicate( aMesh );
1160 return SMESH::SMESH_Mesh::_nil();
1163 //=============================================================================
1167 //=============================================================================
1168 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject)& IO,
1169 Standard_Boolean& testResult)
1171 SMESH::SMESH_subMesh_var aSubMesh;
1172 testResult = false ;
1175 if ( IO->hasEntry() ) {
1176 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1177 SALOMEDS::GenericAttribute_var anAttr;
1178 SALOMEDS::AttributeIOR_var anIOR;
1179 if ( !obj->_is_nil() ) {
1180 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1181 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1182 aSubMesh = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1183 if ( !aSubMesh->_is_nil() ) {
1185 return SMESH::SMESH_subMesh::_duplicate( aSubMesh );
1190 return SMESH::SMESH_subMesh::_nil();
1193 //=============================================================================
1197 //=============================================================================
1198 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis( const Handle(SALOME_InteractiveObject)& IO,
1199 Standard_Boolean& testResult )
1201 SMESH::SMESH_Hypothesis_var aHyp ;
1202 testResult = false ;
1205 if ( IO->hasEntry() ) {
1206 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1207 SALOMEDS::GenericAttribute_var anAttr;
1208 SALOMEDS::AttributeIOR_var anIOR;
1209 if ( !obj->_is_nil() ) {
1210 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1211 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1212 aHyp = SMESH::SMESH_Hypothesis::_narrow( _orb->string_to_object(anIOR->Value()));
1213 if ( !aHyp->_is_nil() ) {
1215 return SMESH::SMESH_Hypothesis::_duplicate( aHyp );
1220 return SMESH::SMESH_Hypothesis::_nil();
1225 //=============================================================================
1229 //=============================================================================
1230 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape( const Handle(SALOME_InteractiveObject)& IO,
1231 Standard_Boolean& testResult )
1233 GEOM::GEOM_Shape_var aShape ;
1234 testResult = false ;
1237 if ( IO->hasEntry() ) {
1238 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IO->getEntry() );
1239 SALOMEDS::GenericAttribute_var anAttr;
1240 SALOMEDS::AttributeIOR_var anIOR;
1241 if ( !obj->_is_nil() ) {
1242 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1243 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1244 aShape = myComponentGeom->GetIORFromString(anIOR->Value()) ;
1245 if ( !aShape->_is_nil() ) {
1247 return GEOM::GEOM_Shape::_duplicate( aShape );
1252 return GEOM::GEOM_Shape::_nil();
1256 //=============================================================================
1260 //=============================================================================
1261 void SMESHGUI::SetViewMode(int commandId)
1263 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1264 int nbSel = Sel->IObjectCount();
1266 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1267 for ( ; It.More(); It.Next() ) {
1268 Handle(SALOME_InteractiveObject) IObject = It.Value();
1269 if ( IObject->hasEntry() ) {
1270 Standard_Boolean res;
1271 SMESH_Actor* ac = FindActorByEntry( IObject->getEntry(), res, true );
1273 switch (commandId) {
1275 ChangeRepresentation( ac, 0 );
1279 ChangeRepresentation( ac, 1 );
1283 ChangeRepresentation( ac, 2 );
1287 ChangeRepresentation( ac, 3 );
1294 if ( commandId == 1133 ) {
1295 ChangeRepresentation( SMESH_Actor::New(), 4 );
1300 //=============================================================================
1304 //=============================================================================
1305 void SMESHGUI::ChangeRepresentation( SMESH_Actor* ac, int type )
1307 if (ac->DataSource == NULL && type != 4 )
1311 if ( ac->getMapper() == NULL ) {
1317 QApplication::setOverrideCursor( Qt::waitCursor );
1318 if (ac->getDisplayMode()==2) {
1319 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1320 meshMapper->SetInput(ac->DataSource);
1322 ac->setDisplayMode(0);
1323 ac->GetProperty()->SetRepresentationToWireframe();
1324 // ac->SetActorProperty( ac->GetProperty() );
1325 QApplication::restoreOverrideCursor();
1329 QApplication::setOverrideCursor( Qt::waitCursor );
1330 if (ac->getDisplayMode()==2) {
1331 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1332 meshMapper->SetInput(ac->DataSource);
1334 ac->setDisplayMode(1);
1335 ac->GetProperty()->SetRepresentationToSurface();
1336 QApplication::restoreOverrideCursor();
1337 // ac->SetActorProperty( ac->GetProperty() );
1341 // if (!(ac->getDisplayMode()==2)) {
1342 // ChangeRepresentation(ac, 1);
1343 QApplication::setOverrideCursor( Qt::waitCursor );
1344 ac->setDisplayMode(2);
1345 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1346 meshMapper->SetInput(ac->DataSource);
1347 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1348 shrink->SetInput(meshMapper->GetInput());
1349 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1351 meshMapper->SetInput( shrink->GetOutput() );
1352 ac->SetMapper( meshMapper );
1353 QApplication::restoreOverrideCursor();
1361 float backfacecolor[3];
1363 ac->GetColor(color[0],color[1],color[2]);
1364 QColor c(color[0]*255,color[1]*255,color[2]*255);
1365 ac->GetEdgeColor(edgecolor[0],edgecolor[1],edgecolor[2]);
1366 QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1367 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1368 QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1369 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2] ) ;
1370 QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1372 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1373 if ( Edgewidth == 0 )
1375 int intValue = ac->GetNodeSize() ;
1376 float Shrink = ac->GetShrinkFactor();
1378 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "" ) ;
1379 aDlg->SetColor(1,c);
1380 aDlg->SetColor(2,e);
1381 aDlg->SetColor(3,n);
1382 aDlg->SetColor(4,b);
1383 aDlg->SetIntValue(1,Edgewidth);
1384 aDlg->SetIntValue(2,intValue);
1385 aDlg->SetIntValue(3,int(Shrink*100.));
1387 if ( aDlg->exec() ) {
1388 QApplication::setOverrideCursor( Qt::waitCursor );
1389 QColor color = aDlg->GetColor(1);
1390 QColor edgecolor = aDlg->GetColor(2);
1391 QColor nodecolor = aDlg->GetColor(3);
1392 QColor backfacecolor = aDlg->GetColor(4);
1393 /* actor color and backface color */
1394 ac->GetProperty()->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1395 ac->SetColor(float(color.red())/255.,float(color.green())/255.,float(color.blue())/255.);
1396 ac->GetBackfaceProperty()->SetColor(float(backfacecolor.red())/255.,float(backfacecolor.green())/255.,float(backfacecolor.blue())/255.);
1399 ac->EdgeDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1400 float(edgecolor.green())/255.,
1401 float(edgecolor.blue())/255.);
1402 ac->EdgeShrinkDevice->GetProperty()->SetColor(float(edgecolor.red())/255.,
1403 float(edgecolor.green())/255.,
1404 float(edgecolor.blue())/255.);
1405 ac->SetEdgeColor(float(edgecolor.red())/255.,
1406 float(edgecolor.green())/255.,
1407 float(edgecolor.blue())/255.);
1409 /* Shrink factor and size edges */
1410 ac->SetShrinkFactor( aDlg->GetIntValue(3)/100. );
1411 ac->EdgeDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1412 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth( aDlg->GetIntValue(1) );
1414 /* Nodes color and size */
1415 ac->SetNodeColor(float(nodecolor.red())/255.,
1416 float(nodecolor.green())/255.,
1417 float(nodecolor.blue())/255.);
1418 ac->SetNodeSize(aDlg->GetIntValue(2)) ;
1420 if (ac->getDisplayMode()==2) {
1421 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (ac->getMapper());
1422 meshMapper->SetInput(ac->DataSource);
1423 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1424 shrink->SetInput(meshMapper->GetInput());
1425 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1427 meshMapper->SetInput( shrink->GetOutput() );
1428 ac->SetMapper( meshMapper );
1432 QApplication::restoreOverrideCursor();
1437 EmitSignalDeactivateDialog() ;
1438 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1439 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg( QAD_Application::getDesktop(), "", Sel) ;
1443 QApplication::setOverrideCursor( Qt::waitCursor );
1444 ac->GetProperty()->SetRepresentationToPoints();
1445 QApplication::restoreOverrideCursor();
1450 QApplication::setOverrideCursor( Qt::waitCursor );
1451 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1452 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1453 theRenderer->Render();
1455 QApplication::restoreOverrideCursor();
1458 //=============================================================================
1462 //=============================================================================
1463 void SMESHGUI::UpdateView()
1465 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1468 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1469 theRenderer->Render();
1472 //=============================================================================
1476 //=============================================================================
1477 void SMESHGUI::DisplayActor(SMESH_Actor* ac, bool visibility)
1479 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1482 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1484 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1485 vtkActorCollection* theActors = theRenderer->GetActors();
1486 theActors->InitTraversal();
1487 if ( theActors->IsItemPresent(ac) == 0 ) {
1488 vtkProperty* prop = vtkProperty::New();
1489 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1490 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1491 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. ) ;
1493 prop->SetPointSize( QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
1494 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
1495 ac->SetProperty( prop );
1496 ac->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").toFloat()/255.,
1497 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat()/255.,
1498 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat()/255. );
1500 // prop->BackfaceCullingOn();
1501 vtkProperty* backprop = vtkProperty::New();
1502 backprop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed").toFloat()/255.,
1503 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").toFloat()/255.,
1504 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").toFloat()/255. ) ;
1505 ac->SetBackfaceProperty(backprop);
1507 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1510 ac->SetShrinkFactor( intValue/100. );
1512 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1513 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1515 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1516 if ( DisplayMode.compare("Wireframe") == 0 ){
1517 ac->setDisplayMode(0);
1518 ChangeRepresentation( ac, 0 );
1519 } else if ( DisplayMode.compare("Shading") == 0 ){
1520 ac->setDisplayMode(1);
1521 ChangeRepresentation( ac, 1 );
1522 } else if ( DisplayMode.compare("Shrink") == 0 ) {
1523 ac->setDisplayMode(2);
1524 ChangeRepresentation( ac, 2 );
1526 theRenderer->AddActor(ac);
1528 if (ac->GetMapper())
1529 ac->GetMapper()->Update();
1532 // if ( visibility )
1533 ac->SetVisibility(visibility);
1534 // ac->VisibilityOn();
1536 // ac->VisibilityOff();
1538 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1542 //=============================================================================
1546 //=============================================================================
1547 void SMESHGUI::EraseActor(SMESH_Actor* ac)
1549 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1552 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1554 //NRI- : 02/12/2002 : Fixed bugId 882
1555 // ac->EdgeDevice->VisibilityOff();
1556 // ac->EdgeShrinkDevice->VisibilityOff();
1557 // ac->VisibilityOff();
1558 ac->SetVisibility( false );
1560 theRenderer->Render();
1563 //=============================================================================
1567 //=============================================================================
1568 bool SMESHGUI::AddActorInSelection(SMESH_Actor* ac)
1570 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
1571 Sel->ClearIObjects();
1573 return Sel->AddIObject( ac->getIO() );
1578 //=============================================================================
1582 //=============================================================================
1583 QString SMESHGUI::CheckHomogeneousSelection()
1585 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1588 SALOME_ListIteratorOfListIO Itinit( Sel->StoredIObjects() );
1589 for (; Itinit.More(); Itinit.Next()) {
1590 List.Append(Itinit.Value());
1593 QString RefType = CheckTypeObject( Sel->firstIObject() );
1594 SALOME_ListIteratorOfListIO It( List );
1595 for (; It.More(); It.Next()) {
1596 Handle(SALOME_InteractiveObject) IObject = It.Value();
1597 QString Type = CheckTypeObject( IObject );
1598 if ( Type.compare( RefType ) != 0 )
1599 return "Heterogeneous Selection";
1602 Sel->ClearIObjects();
1603 SALOME_ListIteratorOfListIO It1( List );
1604 for(;It1.More();It1.Next()) {
1605 int res = Sel->AddIObject( It1.Value() );
1607 myActiveStudy->highlight( It1.Value(), false );
1609 myActiveStudy->highlight( It1.Value(), true );
1614 //=============================================================================
1618 //=============================================================================
1619 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject)& IO)
1621 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
1622 if (!sobj->_is_nil()) {
1623 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1624 if (strcmp(scomp->GetID(), IO->getEntry()) == 0) { // component is selected
1629 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1630 Sel->ClearIObjects();
1632 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter( HYPOTHESIS );
1633 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter( ALGORITHM );
1634 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter( MESH );
1635 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter( SUBMESH );
1636 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter( MESHorSUBMESH );
1637 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter( SUBMESH_VERTEX );
1638 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter( SUBMESH_EDGE );
1639 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter( SUBMESH_FACE );
1640 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter( SUBMESH_SOLID );
1641 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter( SUBMESH_COMPOUND );
1643 Sel->AddFilter(aHypFilter);
1644 if ( Sel->AddIObject( IO ) != -1 ) {
1645 Sel->ClearFilters();
1646 return "Hypothesis";
1649 Sel->ClearFilters();
1650 Sel->AddFilter(anAlgoFilter);
1651 if ( Sel->AddIObject( IO ) != -1 ) {
1652 Sel->ClearFilters();
1656 Sel->ClearFilters();
1657 Sel->AddFilter(aMeshFilter);
1658 if ( Sel->AddIObject( IO ) != -1 ) {
1659 Sel->ClearFilters();
1663 Sel->ClearFilters();
1664 Sel->AddFilter(aSubMeshFilter);
1665 if ( Sel->AddIObject( IO ) != -1 ) {
1666 Sel->ClearFilters();
1670 Sel->ClearFilters();
1671 Sel->AddFilter(aSubMeshVextexFilter);
1672 if ( Sel->AddIObject( IO ) != -1 ) {
1673 Sel->ClearFilters();
1674 return "SubMeshVertex";
1677 Sel->ClearFilters();
1678 Sel->AddFilter(aSubMeshEdgeFilter);
1679 if ( Sel->AddIObject( IO ) != -1 ){
1680 Sel->ClearFilters();
1681 return "SubMeshEdge";
1684 Sel->ClearFilters();
1685 Sel->AddFilter(aSubMeshFaceFilter);
1686 if ( Sel->AddIObject( IO ) != -1 ) {
1687 Sel->ClearFilters();
1688 return "SubMeshFace";
1691 Sel->ClearFilters();
1692 Sel->AddFilter(aSubMeshSolidFilter);
1693 if ( Sel->AddIObject( IO ) != -1 ) {
1694 Sel->ClearFilters();
1695 return "SubMeshSolid";
1698 Sel->ClearFilters();
1699 Sel->AddFilter(aSubMeshCompoundFilter);
1700 if ( Sel->AddIObject( IO ) != -1 ) {
1701 Sel->ClearFilters();
1702 return "SubMeshCompound";
1705 Sel->ClearFilters();
1706 Sel->AddIObject( IO );
1710 //=============================================================================
1714 //=============================================================================
1715 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop* parent)
1717 /* Create or retrieve an object SMESHGUI */
1718 SMESHGUI::GetOrCreateSMESHGUI(parent);
1720 // NRI : Temporary added
1721 if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
1726 // QAD_Viewer3d* v3d;
1727 OCCViewer_Viewer3d* v3d;
1729 Handle(AIS_InteractiveContext) ic;
1730 vtkRenderer* Renderer;
1731 vtkRenderWindow* RenWin;
1733 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC ) {
1734 v3d =((OCCViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
1735 ic = v3d->getAISContext();
1736 } else if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1737 Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
1738 RenWin = Renderer->GetRenderWindow();
1741 switch (theCommandID)
1744 smeshGUI->OnEditDelete();
1751 Import_Document(parent,theCommandID);//NBU
1752 //Import_Mesh(parent,theCommandID);
1756 case 122: // EXPORT MED
1760 Export_Mesh(parent, theCommandID);
1764 case 200: // SCALAR BAR
1766 smeshGUI->DisplayScalarBar(false);
1771 SMESHGUI_EditScalarBarDlg *aDlg = new SMESHGUI_EditScalarBarDlg( parent, "", false ) ;
1777 smeshGUI->DisplayScalarBar( true );
1781 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
1787 smeshGUI->SetViewMode(theCommandID);
1791 case 214 : // UPDATE
1799 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1800 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1802 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1803 for(;It.More();It.Next()) {
1804 Handle(SALOME_InteractiveObject) IOS = It.Value();
1805 if ( IOS->hasEntry() ) {
1806 Standard_Boolean res;
1807 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IOS->getEntry(), res, true );
1808 if ( res ) smeshGUI->EraseActor( ac );
1812 Sel->ClearIObjects();
1813 smeshGUI->myActiveStudy->updateObjBrowser( true );
1816 case 301 : // DISPLAY
1818 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
1820 QApplication::setOverrideCursor( Qt::waitCursor );
1821 SALOMEDS::SObject_var fatherSF =
1822 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1824 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1825 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1827 for(;It.More();It.Next()) {
1828 Handle(SALOME_InteractiveObject) IObject = It.Value();
1829 if ( IObject->hasEntry() ) {
1830 Standard_Boolean res;
1831 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1833 smeshGUI->DisplayActor( ac, true );
1834 smeshGUI->DisplayEdges( ac );
1835 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1839 QApplication::restoreOverrideCursor();
1844 case 302 : // DISPLAY ONLY
1846 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
1847 QApplication::setOverrideCursor( Qt::waitCursor );
1848 vtkActorCollection* theActors = Renderer->GetActors();
1849 theActors->InitTraversal();
1850 vtkActor *ac = theActors->GetNextActor();
1851 while(!(ac==NULL)) {
1852 if ( ac->IsA("SMESH_Actor") ) {
1853 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
1854 if(!anActor->isHighlighted()) {
1855 //anActor->VisibilityOff();
1856 //NRI- : 02/12/2002 : Fixed bugId 882
1857 // anActor->EdgeDevice->VisibilityOff();
1858 // anActor->EdgeShrinkDevice->VisibilityOff();
1859 anActor->SetVisibility( false );
1862 ac = theActors->GetNextActor();
1865 // Display selection
1866 SALOMEDS::SObject_var fatherSF = smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->getActiveStudyFrame()->entry());
1868 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1869 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
1871 for(;It.More();It.Next()) {
1872 Handle(SALOME_InteractiveObject) IObject = It.Value();
1873 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1875 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
1876 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
1878 if(myRenderInter->isInViewer(IObject)) {
1879 if ( IObject->hasEntry() ) {
1880 Standard_Boolean res;
1881 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, true );
1883 smeshGUI->DisplayActor( ac, true );
1884 smeshGUI->DisplayEdges( ac );
1885 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
1890 smeshGUI->myActiveStudy->updateObjBrowser( true );
1891 QApplication::restoreOverrideCursor();
1898 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1899 smeshGUI->EmitSignalDeactivateDialog() ;
1900 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1901 Sel->ClearIObjects();
1902 smeshGUI->myDesktop->SetSelectionMode(1, true);
1903 parent->menuBar()->setItemChecked(9010, false );
1904 parent->menuBar()->setItemChecked(9011, false );
1905 smeshGUI->ViewNodes();
1906 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg( parent, "", Sel ) ;
1908 QApplication::restoreOverrideCursor();
1909 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1910 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
1915 case 405: // MOVE NODE
1917 smeshGUI->myDesktop->SetSelectionMode(1, true);
1918 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1919 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg( parent, "", Sel ) ;
1923 case 701: // COMPUTE MESH
1925 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
1926 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
1927 int nbSel = Sel->IObjectCount();
1929 QApplication::restoreOverrideCursor();
1933 SMESH::SMESH_Mesh_var aM;
1934 SMESH::SMESH_subMesh_var aSubM;
1935 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1936 if ( IObject->hasEntry() ) {
1937 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
1938 SALOMEDS::GenericAttribute_var anAttr;
1939 SALOMEDS::AttributeIOR_var anIOR;
1940 if ( !aMorSM->_is_nil() ) {
1941 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
1942 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1943 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : IOR = " << anIOR->Value() )
1944 CORBA::Object_var cobj;
1946 cobj = _orb->string_to_object(anIOR->Value());
1947 if ( CORBA::is_nil(cobj) ) {
1948 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : nil object" )
1951 catch(CORBA::COMM_FAILURE& ex) {
1952 MESSAGE( "SMESHGUI::OnGUIEvent - Compute mesh : exception (1)" )
1954 aM = SMESH::SMESH_Mesh::_narrow(cobj);
1955 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1956 aSubM = SMESH::SMESH_subMesh::_narrow( _orb->string_to_object(anIOR->Value()) );
1957 if ( !aM->_is_nil() ) {
1958 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1959 if ( !refShape->_is_nil() ) {
1960 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1962 QApplication::restoreOverrideCursor();
1963 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1964 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1968 smeshGUI->myComponentMesh->Compute( aM, refShape);
1969 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1970 // TO Do : change icon of all submeshes
1972 catch (const SALOME::SALOME_Exception& S_ex) {
1973 QtCatchCorbaException(S_ex);
1976 } else if ( !aSubM->_is_nil() ) {
1977 aM = aSubM->GetFather();
1978 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMorSM);
1979 if ( !refShape->_is_nil() ) {
1980 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aM, refShape);
1982 QApplication::restoreOverrideCursor();
1983 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
1984 tr ("SMESH_WRN_MISSING_PARAMETERS"), tr ("SMESH_BUT_YES") );
1988 smeshGUI->myComponentMesh->Compute( aM, refShape);
1989 smeshGUI->myStudyAPI.ModifiedMesh( aMorSM, true );
1990 // TO Do : change icon of all submeshes
1992 catch (const SALOME::SALOME_Exception& S_ex) {
1993 QtCatchCorbaException(S_ex);
2001 // Check whether the actor for the mesh exists at least in one view
2002 Standard_Boolean res;
2003 SMESH_Actor* ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2005 smeshGUI->InitActor( aM );
2007 // Check whether the actor belongs to the active view
2008 VTKViewer_RenderWindowInteractor* rwInter =
2009 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
2011 // The actor belongs to inactive view -> create a copy and add it in the active view
2012 if (!rwInter->isInViewer(IObject)) {
2013 SMESH_Actor* acCopy = SMESH_Actor::New();
2014 acCopy->ShallowCopy(ac);
2016 smeshGUI->DisplayActor( acCopy, false );
2020 if ( smeshGUI->myAutomaticUpdate ) {
2021 SMESH_Actor* Mesh = smeshGUI->ReadScript(aM);
2022 if ( Mesh != NULL ) {
2026 smeshGUI->DisplayActor( Mesh, true );
2027 smeshGUI->DisplayEdges( Mesh, true );
2028 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
2032 QApplication::restoreOverrideCursor();
2033 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2034 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2036 QApplication::restoreOverrideCursor();
2040 case 702: // ADD SUB MESH
2042 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2043 smeshGUI->EmitSignalDeactivateDialog() ;
2044 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2045 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg( parent, "", Sel ) ;
2047 QApplication::restoreOverrideCursor();
2048 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2049 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2054 case 703: // INIT MESH
2056 smeshGUI->EmitSignalDeactivateDialog() ;
2057 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2058 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg( parent, "", Sel ) ;
2062 case 704: // EDIT Hypothesis
2064 smeshGUI->EmitSignalDeactivateDialog() ;
2065 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2066 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2070 case 705: // EDIT Global Hypothesis
2072 smeshGUI->EmitSignalDeactivateDialog() ;
2073 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2074 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2078 case 706: // EDIT Local Hypothesis
2080 smeshGUI->EmitSignalDeactivateDialog() ;
2081 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2082 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg( parent, "", Sel ) ;
2086 case 806: // ORIENTATION ELEMENTS
2088 smeshGUI->EmitSignalDeactivateDialog() ;
2089 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2090 smeshGUI->myDesktop->SetSelectionMode(3, true);
2091 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg( parent, "", Sel ) ;
2095 case 807: // DIAGONAL INVERSION
2097 smeshGUI->EmitSignalDeactivateDialog() ;
2098 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2099 Sel->ClearIObjects();
2100 smeshGUI->myDesktop->SetSelectionMode(2, true);
2101 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg( parent, "", Sel ) ;
2105 case 900: // MESH INFOS
2107 smeshGUI->EmitSignalDeactivateDialog() ;
2108 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2109 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg( parent, "", Sel ) ;
2113 case 1001: // AUTOMATIC UPDATE PREFERENCES
2115 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001) );
2116 if ( parent->menuBar()->isItemChecked(1001) ) {
2117 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","true");
2118 smeshGUI->myAutomaticUpdate = true;
2120 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate","false");
2121 smeshGUI->myAutomaticUpdate = false;
2126 case 1003: // MESH PREFERENCES
2128 smeshGUI->SetDisplaySettings();
2134 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2135 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2136 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2137 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2138 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2139 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2140 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2141 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2142 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2144 if ( Width == 0 ) Width = 0.17;
2145 if ( Height == 0 ) Height = 0.8;
2146 if ( NumberOfLabels == 0 ) NumberOfLabels = 5;
2147 if ( NumberOfColors == 0) NumberOfColors = 64;
2149 SMESHGUI_Preferences_ScalarBarDlg *aDlg = new SMESHGUI_Preferences_ScalarBarDlg( parent, "", true) ;
2151 if ( Bold.compare("true") == 0 )
2152 aDlg->Bold->setChecked(true); else aDlg->Bold->setChecked(false);
2153 if ( Italic.compare("true") == 0 )
2154 aDlg->Italic->setChecked(true); else aDlg->Italic->setChecked(false);
2155 if ( Shadow.compare("true") == 0 )
2156 aDlg->Shadow->setChecked(true); else aDlg->Shadow->setChecked(false);
2158 if ( Orientation.compare("Horizontal") == 0 )
2159 aDlg->RadioHoriz->setChecked(true); else aDlg->RadioVert->setChecked(true);
2161 int NbItems = aDlg->ComboBox1->count();
2163 aDlg->ComboBox1->setCurrentItem( i );
2164 while ( i < NbItems ) {
2165 if ( FontFamily.compare( aDlg->ComboBox1->text( i ) ) == 0 )
2166 aDlg->ComboBox1->setCurrentItem( i );
2170 aDlg->LineEditWidth->setText( QString("%1").arg(Width) );
2171 aDlg->LineEditHeight->setText( QString("%1").arg(Height) );
2173 aDlg->SpinBoxLabels->setValue( NumberOfLabels );
2174 aDlg->SpinBoxColors->setValue( NumberOfColors );
2177 if ( aDlg->result() ) {
2178 if ( aDlg->RadioHoriz->isChecked() )
2179 Orientation = "Horizontal"; else Orientation = "Vertical";
2180 if ( aDlg->Bold->isChecked() )
2181 Bold = "true"; else Bold = "false";
2182 if ( aDlg->Italic->isChecked() )
2183 Italic = "true"; else Italic = "false";
2184 if ( aDlg->Shadow->isChecked() )
2185 Shadow = "true"; else Shadow = "false";
2187 FontFamily = aDlg->ComboBox1->currentText();
2188 Width = aDlg->LineEditWidth->text().toFloat();
2189 Height = aDlg->LineEditHeight->text().toFloat();
2190 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2191 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2194 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
2195 if ( aScalarBar != NULL ) {
2196 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2197 FontFamily, Orientation,
2198 Width, Height, NumberOfColors, NumberOfLabels);
2201 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2202 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2203 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2204 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2205 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2206 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2207 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2208 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2209 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2214 case 1100: // EDIT HYPOTHESIS
2216 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2217 int nbSel = Sel->IObjectCount() ;
2220 Standard_Boolean res;
2221 SMESH::SMESH_Hypothesis_var Hyp = smeshGUI->ConvertIOinSMESHHypothesis( Sel->firstIObject(), res );
2223 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2224 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2225 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2226 SALOMEDS::Study::ListOfSObject_var listSOmesh = smeshGUI->GetMeshesUsingAlgoOrHypothesis( Hyp) ;
2229 QString Name = Hyp->GetName();
2231 if ( Name.compare("LocalLength") == 0 ) {
2232 SMESH::SMESH_LocalLength_var LL = SMESH::SMESH_LocalLength::_narrow( Hyp );
2233 double beforeLength = LL->GetLength() ;
2234 double Length = smeshGUI->Parameter( res,
2236 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2239 if ( res && Length != beforeLength ) {
2240 LL->SetLength( Length );
2241 for( int i=0; i<listSOmesh->length(); i++ ) {
2242 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2247 } else if ( Name.compare("NumberOfSegments") == 0 ) {
2248 SMESH::SMESH_NumberOfSegments_var NOS = SMESH::SMESH_NumberOfSegments::_narrow( Hyp );
2249 int beforeNbSeg = NOS->GetNumberOfSegments() ;
2250 int NbSeg = smeshGUI->Parameter( res,
2252 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2256 if ( res && NbSeg != beforeNbSeg ) {
2257 NOS->SetNumberOfSegments( NbSeg );
2258 for( int i=0; i<listSOmesh->length(); i++ ) {
2259 SALOMEDS::SObject_var SO = listSOmesh[i] ;
2260 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2265 } else if ( Name.compare("MaxElementArea") == 0 ) {
2266 SMESH::SMESH_MaxElementArea_var MEA = SMESH::SMESH_MaxElementArea::_narrow( Hyp );
2267 double beforeMaxArea = MEA->GetMaxElementArea() ;
2268 double MaxArea = smeshGUI->Parameter( res,
2270 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2273 if ( res && MaxArea != beforeMaxArea ) {
2274 MEA->SetMaxElementArea( MaxArea );
2275 for( int i=0; i<listSOmesh->length(); i++ ) {
2276 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2281 } else if ( Name.compare("MaxElementVolume") == 0 ) {
2282 SMESH::SMESH_MaxElementVolume_var MEV = SMESH::SMESH_MaxElementVolume::_narrow( Hyp );
2283 double beforeMaxVolume = MEV->GetMaxElementVolume() ;
2284 double MaxVolume = smeshGUI->Parameter( res,
2286 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2289 if ( res && MaxVolume != beforeMaxVolume ) {
2290 MEV->SetMaxElementVolume( MaxVolume );
2291 for( int i=0; i<listSOmesh->length(); i++ ) {
2292 smeshGUI->GetStudyAPI().ModifiedMesh( listSOmesh[i], false ) ;
2297 } else if ( Name.compare("Regular_1D") == 0 ) {
2298 } else if ( Name.compare("MEFISTO_2D") == 0 ) {
2307 case 1101: // RENAME
2309 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2310 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2311 for ( ; It.More(); It.Next() ) {
2312 Handle(SALOME_InteractiveObject) IObject = It.Value();
2314 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2315 SALOMEDS::GenericAttribute_var anAttr;
2316 SALOMEDS::AttributeName_var aName;
2317 if ( !obj->_is_nil() ) {
2318 if (obj->FindAttribute(anAttr, "AttributeName")) {
2319 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2320 QString newName = QString( aName->Value() );
2321 newName = SALOMEGUI_NameDlg::getName( QAD_Application::getDesktop(), newName);
2322 if ( !newName.isEmpty() ) {
2323 QApplication::setOverrideCursor( Qt::waitCursor );
2324 smeshGUI->myActiveStudy->renameIObject( IObject, newName );
2326 QApplication::restoreOverrideCursor();
2333 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2335 QApplication::setOverrideCursor( Qt::waitCursor );
2336 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2337 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
2338 for ( int i=0; It.More(); It.Next(), i++ ) {
2339 Handle(SALOME_InteractiveObject) IObject = It.Value();
2340 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh( IObject );
2342 Sel->ClearIObjects();
2343 smeshGUI->myActiveStudy->updateObjBrowser( true );
2344 QApplication::restoreOverrideCursor();
2348 case 401: // GEOM::EDGE
2350 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2351 smeshGUI->EmitSignalDeactivateDialog() ;
2352 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2353 Sel->ClearIObjects();
2354 smeshGUI->myDesktop->SetSelectionMode(1, true);
2355 parent->menuBar()->setItemChecked(9010, false );
2356 parent->menuBar()->setItemChecked(9011, false );
2357 smeshGUI->ViewNodes();
2358 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg( parent, "", Sel ) ;
2360 QApplication::restoreOverrideCursor();
2361 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2362 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2366 case 4021: // TRIANGLE
2368 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2369 smeshGUI->EmitSignalDeactivateDialog() ;
2370 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2371 Sel->ClearIObjects();
2372 smeshGUI->myDesktop->SetSelectionMode(1, true);
2373 parent->menuBar()->setItemChecked(9010, false );
2374 parent->menuBar()->setItemChecked(9011, false );
2375 smeshGUI->ViewNodes();
2376 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 3 ) ;
2378 QApplication::restoreOverrideCursor();
2379 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2380 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2386 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2387 smeshGUI->EmitSignalDeactivateDialog() ;
2388 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2389 Sel->ClearIObjects();
2390 smeshGUI->myDesktop->SetSelectionMode(1, true);
2391 parent->menuBar()->setItemChecked(9010, false );
2392 parent->menuBar()->setItemChecked(9011, false );
2393 smeshGUI->ViewNodes();
2394 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg( parent, "", Sel, 4 ) ;
2396 QApplication::restoreOverrideCursor();
2397 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2398 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2404 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2405 smeshGUI->EmitSignalDeactivateDialog() ;
2406 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2407 Sel->ClearIObjects();
2408 smeshGUI->myDesktop->SetSelectionMode(1, true);
2409 parent->menuBar()->setItemChecked(9010, false );
2410 parent->menuBar()->setItemChecked(9011, false );
2411 smeshGUI->ViewNodes();
2412 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 4 ) ;
2414 QApplication::restoreOverrideCursor();
2415 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2416 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2422 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2423 smeshGUI->EmitSignalDeactivateDialog() ;
2424 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2425 Sel->ClearIObjects();
2426 smeshGUI->myDesktop->SetSelectionMode(1, true);
2427 parent->menuBar()->setItemChecked(9010, false );
2428 parent->menuBar()->setItemChecked(9011, false );
2429 smeshGUI->ViewNodes();
2430 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg( parent, "", Sel, 8 ) ;
2432 QApplication::restoreOverrideCursor();
2433 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2434 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2439 case 4041: // REMOVES NODES
2441 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2442 smeshGUI->EmitSignalDeactivateDialog() ;
2443 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2444 Sel->ClearIObjects();
2445 smeshGUI->myDesktop->SetSelectionMode(1, true);
2446 parent->menuBar()->setItemChecked(9010, false );
2447 parent->menuBar()->setItemChecked(9011, false );
2448 smeshGUI->ViewNodes();
2449 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg( parent, "", Sel ) ;
2451 QApplication::restoreOverrideCursor();
2452 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2453 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2457 case 4042: // REMOVES ELEMENTS
2459 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2460 smeshGUI->EmitSignalDeactivateDialog() ;
2461 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2462 Sel->ClearIObjects();
2463 smeshGUI->myDesktop->SetSelectionMode(3, true);
2464 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg( parent, "", Sel ) ;
2466 QApplication::restoreOverrideCursor();
2467 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2468 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2473 case 5000: // HYPOTHESIS - ALGO
2475 smeshGUI->CreateAlgorithm("Regular_1D","Wire Discretisation");
2480 smeshGUI->CreateAlgorithm("MEFISTO_2D","Triangle (Mefisto)");
2485 smeshGUI->CreateAlgorithm("Quadrangle_2D","Quadrangle (Mapping)");
2490 smeshGUI->CreateAlgorithm("Hexa_3D","Hexaedral (i,j,k)");
2494 case 5030: // HYPOTHESIS - LOCAL LENGTH
2496 smeshGUI->EmitSignalDeactivateDialog() ;
2497 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2498 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg( parent, "" ) ;
2501 case 5031: // HYPOTHESIS - NB SEGMENTS
2503 smeshGUI->EmitSignalDeactivateDialog() ;
2504 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2505 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg( parent, "" ) ;
2509 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
2511 smeshGUI->EmitSignalDeactivateDialog() ;
2512 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2513 SMESHGUI_MaxElementAreaDlg *aDlg = new SMESHGUI_MaxElementAreaDlg( parent, "" ) ;
2517 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
2519 smeshGUI->EmitSignalDeactivateDialog() ;
2520 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2521 SMESHGUI_MaxElementVolumeDlg *aDlg = new SMESHGUI_MaxElementVolumeDlg( parent, "" ) ;
2525 case 6016: // CONTROLS
2533 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2534 int nbSel = Sel->IObjectCount();
2537 smeshGUI->Control(theCommandID);
2543 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
2544 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2545 SMESHGUI_EdgesConnectivityDlg *Dlg = new SMESHGUI_EdgesConnectivityDlg( parent, "", Sel ) ;
2547 QApplication::restoreOverrideCursor();
2548 QAD_MessageBox::warn1 ( QAD_Application::getDesktop(), tr ("SMESH_WRN_WARNING"),
2549 tr ("SMESH_WRN_VIEWER_VTK"), tr ("SMESH_BUT_YES") );
2556 if ( !parent->menuBar()->isItemChecked(9010) ) {
2557 QApplication::setOverrideCursor( Qt::waitCursor );
2558 parent->menuBar()->setItemChecked(9011, false );
2560 smeshGUI->EraseSimulationActors();
2561 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2563 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2564 int nbSel = Sel->IObjectCount() ;
2566 Standard_Boolean res;
2567 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2569 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2571 // It's necessary to display SMDS IDs instead of VTK ones, so
2572 // vtkIdFilter is unacceptable here. We have to do it manually :(
2573 vtkUnstructuredGrid* ptGrid = vtkUnstructuredGrid::New();
2574 ptGrid->CopyStructure(MeshActor->DataSource);
2576 int numPts = MeshActor->DataSource->GetNumberOfPoints();
2578 // Loop over points and generate ids
2579 vtkIntArray *ptIds = vtkIntArray::New();
2580 ptIds->SetNumberOfValues(numPts);
2582 for (int id=0; id < numPts; id++) {
2583 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
2584 ptIds->SetValue(id, idSMDS);
2587 // mpv porting vtk4.2.2
2588 // vtkScalars* newScalars = vtkScalars::New();
2589 // newScalars->SetData(ptIds);
2590 // ptGrid->GetPointData()->SetScalars(newScalars);
2591 ptGrid->GetPointData()->SetScalars(ptIds);
2592 // newScalars->Delete();
2596 vtkMaskPoints* mask = vtkMaskPoints::New();
2597 mask->SetInput(ptGrid);
2598 mask->SetOnRatio( 1 );
2599 // mask->SetMaximumNumberOfPoints( 50 );
2600 // mask->RandomModeOn();
2602 vtkSelectVisiblePoints* visPts = vtkSelectVisiblePoints::New();
2603 visPts->SetInput(mask->GetOutput());
2604 visPts->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2605 //visPts->SetSelectInvisible(1);
2606 visPts->SelectInvisibleOff();
2607 visPts->SetTolerance(0.1);
2609 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2610 ldm->SetInput(visPts->GetOutput());
2611 ldm->SetLabelFormat("%g");
2612 ldm->SetLabelModeToLabelScalars();
2613 //ldm->SetLabelModeToLabelFieldData();
2615 ldm->SetFontFamilyToTimes();
2616 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2621 vtkActor2D* pointLabels = vtkActor2D::New();
2622 pointLabels->SetMapper(ldm);
2623 pointLabels->GetProperty()->SetColor(0,1,0);
2627 smeshGUI->mySimulationActors2D->AddItem( pointLabels );
2628 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( pointLabels );
2632 QApplication::setOverrideCursor( Qt::waitCursor );
2633 parent->menuBar()->setItemChecked(9010, !parent->menuBar()->isItemChecked(9010) );
2634 smeshGUI->EraseSimulationActors();
2635 smeshGUI->ScalarVisibilityOff();
2637 QApplication::restoreOverrideCursor();
2642 if ( !parent->menuBar()->isItemChecked(9011) ) {
2643 QApplication::setOverrideCursor( Qt::waitCursor );
2644 parent->menuBar()->setItemChecked(9010, false );
2646 smeshGUI->EraseSimulationActors();
2647 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
2649 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2650 int nbSel = Sel->IObjectCount() ;
2652 Standard_Boolean res;
2653 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(), res, true);
2655 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2657 // It's necessary to display SMDS IDs instead of VTK ones, so
2658 // vtkIdFilter is unacceptable here. We have to do it manually :(
2659 vtkUnstructuredGrid* elGrid = vtkUnstructuredGrid::New();
2660 elGrid->CopyStructure(MeshActor->DataSource);
2662 int numCells = MeshActor->DataSource->GetNumberOfCells();
2664 // Loop over points and generate ids
2665 vtkIntArray *cellIds = vtkIntArray::New();
2666 cellIds->SetNumberOfValues(numCells);
2668 for (int id=0; id < numCells; id++) {
2669 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
2670 cellIds->SetValue(id, idSMDS);
2673 // mpv porting vk4.2.2
2674 // vtkScalars* newScalars = vtkScalars::New();
2675 // newScalars->SetData(cellIds);
2676 elGrid->GetCellData()->SetScalars(cellIds);
2677 // elGrid->GetCellData()->SetScalars(newScalars);
2678 // newScalars->Delete();
2683 vtkCellCenters* cc = vtkCellCenters::New();
2684 cc->SetInput(elGrid);
2686 vtkSelectVisiblePoints* visCells = vtkSelectVisiblePoints::New();
2687 visCells->SetInput(cc->GetOutput());
2688 visCells->SetRenderer(((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer());
2689 visCells->SelectInvisibleOff();
2690 visCells->SetTolerance(0.1);
2691 // visCells->SetSelectInvisible(1);
2693 vtkLabeledDataMapper* ldm = vtkLabeledDataMapper::New();
2694 ldm->SetInput(visCells->GetOutput());
2695 ldm->SetLabelFormat("%g");
2696 ldm->SetLabelModeToLabelScalars();
2698 ldm->SetFontFamilyToTimes();
2699 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
2704 vtkActor2D* cellLabels = vtkActor2D::New();
2705 cellLabels->SetMapper(ldm);
2706 cellLabels->GetProperty()->SetColor(1,0,0);
2711 smeshGUI->mySimulationActors2D->AddItem( cellLabels );
2712 ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer()->AddActor2D( cellLabels );
2716 QApplication::setOverrideCursor( Qt::waitCursor );
2717 parent->menuBar()->setItemChecked(9011, !parent->menuBar()->isItemChecked(9011) );
2718 smeshGUI->EraseSimulationActors();
2719 smeshGUI->ScalarVisibilityOff();
2721 QApplication::restoreOverrideCursor();
2725 case 10001: // DISPLAY MODE PREFERENCE
2727 parent->menuBar()->setItemChecked(10001, !parent->menuBar()->isItemChecked(10001) );
2728 parent->menuBar()->setItemChecked(10002, false );
2729 parent->menuBar()->setItemChecked(10003, false );
2730 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
2735 parent->menuBar()->setItemChecked(10002, !parent->menuBar()->isItemChecked(10002) );
2736 parent->menuBar()->setItemChecked(10001, false );
2737 parent->menuBar()->setItemChecked(10003, false );
2738 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
2743 parent->menuBar()->setItemChecked(10003, !parent->menuBar()->isItemChecked(10003) );
2744 parent->menuBar()->setItemChecked(10002, false );
2745 parent->menuBar()->setItemChecked(10001, false );
2746 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
2752 smeshGUI->myActiveStudy->updateObjBrowser(true);
2757 //=============================================================================
2758 /*! function : GetMeshesUsingAlgoOrHypothesis()
2759 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
2760 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
2762 //=============================================================================
2763 SALOMEDS::Study::ListOfSObject* SMESHGUI::GetMeshesUsingAlgoOrHypothesis( SMESH::SMESH_Hypothesis_ptr AlgoOrHyp )
2765 SALOMEDS::Study::ListOfSObject_var listSOmesh = new SALOMEDS::Study::ListOfSObject ;
2766 listSOmesh->length(0) ;
2767 unsigned int index = 0 ;
2768 if( !AlgoOrHyp->_is_nil() ) {
2769 SALOMEDS::SObject_var SO_Hypothesis = smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms( AlgoOrHyp );
2770 if( !SO_Hypothesis->_is_nil() ) {
2771 SALOMEDS::Study::ListOfSObject_var listSO = smeshGUI->myStudy->FindDependances(SO_Hypothesis) ;
2772 for( unsigned int i=0; i<listSO->length(); i++ ) {
2773 SALOMEDS::SObject_var SO = listSO[i] ;
2774 if( !SO->_is_nil() ) {
2775 SALOMEDS::SObject_var SOfatherFather = SO->GetFather()->GetFather() ;
2776 if( !SOfatherFather->_is_nil() ) {
2778 listSOmesh->length(index) ;
2779 listSOmesh[index-1] = SOfatherFather ;
2785 return listSOmesh._retn() ;
2789 //=============================================================================
2793 //=============================================================================
2794 void SMESHGUI::Import_Mesh(QAD_Desktop* parent, int theCommandID)
2798 Mesh_Reader* myReader;
2800 if (theCommandID==113) {
2801 filter = tr("MED files (*.med)");
2802 myExtension = string("MED");
2803 myReader = new DriverMED_R_SMESHDS_Mesh;
2805 else if (theCommandID==112) {
2806 filter = tr("IDEAS files (*.unv)");
2807 myExtension = string("UNV");
2809 else if (theCommandID==111) {
2810 filter = tr("DAT files (*.dat)");
2811 myExtension = string("MED");
2812 myReader = new DriverDAT_R_SMESHDS_Mesh;
2815 QString filename = QAD_FileDlg::getFileName(parent,
2820 if ( !filename.isEmpty() ) {
2821 QApplication::setOverrideCursor( Qt::waitCursor );
2822 string myClass = string("SMESHDS_Mesh");
2823 // Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
2825 int myMeshId = (smeshGUI->myDocument)->NewMesh();
2826 SMDS_Mesh* myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
2828 myReader->SetFile(string(filename.latin1()));
2829 myReader->SetMesh(myMesh);
2830 myReader->SetMeshId(myMeshId);
2833 QApplication::restoreOverrideCursor();
2837 //=============================================================================
2841 //=============================================================================
2842 void SMESHGUI::Export_Mesh(QAD_Desktop* parent, int theCommandID)
2844 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2845 int nbSel = Sel->IObjectCount() ;
2847 Standard_Boolean res;
2848 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2849 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh( IObject, res );
2851 if (theCommandID==122) { // EXPORT MED
2852 QString filename = QAD_FileDlg::getFileName(parent,
2854 tr("MED files (*.med)"),
2857 if ( !filename.isEmpty() ) {
2858 QApplication::setOverrideCursor( Qt::waitCursor );
2859 aMesh->ExportMED( filename.latin1() );
2860 QApplication::restoreOverrideCursor();
2863 else if (theCommandID==121) { // EXPORT DAT
2864 QString filename = QAD_FileDlg::getFileName(parent,
2866 tr("DAT files (*.dat)"),
2869 if ( !filename.isEmpty() ) {
2870 QApplication::setOverrideCursor( Qt::waitCursor );
2871 aMesh->ExportDAT( filename.latin1() );
2872 QApplication::restoreOverrideCursor();
2875 else if (theCommandID==123) { // EXPORT UNV
2876 QString filename = QAD_FileDlg::getFileName(parent,
2878 tr("IDEAS files (*.unv)"),
2881 if ( !filename.isEmpty() ) {
2882 QApplication::setOverrideCursor( Qt::waitCursor );
2883 aMesh->ExportUNV( filename.latin1() );
2884 QApplication::restoreOverrideCursor();
2887 aMesh->ExportDAT( filename.latin1() );
2889 QApplication::restoreOverrideCursor();
2891 if ( IObject->hasEntry() )
2894 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
2895 SALOMEDS::GenericAttribute_var anAttr;
2896 SALOMEDS::AttributeComment_var aFileName;
2897 SALOMEDS::StudyBuilder_var aStudyBuilder = smeshGUI->myStudy->NewBuilder();
2898 anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
2899 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
2900 aFileName->SetValue(filename.latin1());
2907 //=============================================================================
2911 //=============================================================================
2912 void SMESHGUI::Import_Document(QAD_Desktop* parent, int theCommandID)
2916 Document_Reader* myReader;
2918 if (theCommandID==113) {
2919 filter = tr("MED files (*.med)");
2920 myExtension = string("MED");
2921 myReader = new DriverMED_R_SMESHDS_Document;
2923 else if (theCommandID==112) {
2924 filter = tr("IDEAS files (*.unv)");
2925 myExtension = string("UNV");
2926 myReader = new DriverUNV_R_SMESHDS_Document;
2928 else if (theCommandID==111) {
2929 filter = tr("DAT files (*.dat)");
2930 myExtension = string("DAT");
2931 myReader = new DriverDAT_R_SMESHDS_Document;
2934 QString filename = QAD_FileDlg::getFileName(parent,
2937 tr("Import document"),
2939 if ( !filename.isEmpty() ) {
2940 QApplication::setOverrideCursor( Qt::waitCursor );
2941 string myClass = string("SMESHDS_Document");
2942 // Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
2943 SMESHDS_Document* newDocument = new SMESHDS_Document(1);
2945 myReader->SetFile(string(filename.latin1()));
2946 myReader->SetDocument(smeshGUI->myDocument);
2948 QApplication::restoreOverrideCursor();
2952 void SMESHGUI::Export_Document(QAD_Desktop* parent, int theCommandID)
2955 Document_Writer* myWriter;
2958 if (theCommandID==122) {
2959 filter = tr("MED files (*.med)");
2960 myExtension = string("MED");
2961 myWriter = new DriverMED_W_SMESHDS_Document;
2963 else if (theCommandID==121) {
2964 filter = tr("DAT files (*.dat)");
2965 myExtension = string("DAT");
2966 myWriter = new DriverDAT_W_SMESHDS_Document;
2967 } else if (theCommandID==123) {
2968 filter = tr("IDEAS files (*.unv)");
2969 myExtension = string("UNV");
2970 myWriter = new DriverUNV_W_SMESHDS_Document;
2973 QString filename = QAD_FileDlg::getFileName(parent,
2976 tr("Export document"),
2978 if ( !filename.isEmpty() ) {
2979 QApplication::setOverrideCursor( Qt::waitCursor );
2980 string myClass = string("SMESHDS_Document");
2981 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
2983 myWriter->SetFile(string(filename.latin1()));
2984 myWriter->SetDocument(smeshGUI->myDocument);
2986 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
2987 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
2988 //myWriter->SetDocument(myDocument);
2991 QApplication::restoreOverrideCursor();
2995 //=============================================================================
2999 //=============================================================================
3000 bool SMESHGUI::OnMousePress(QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3002 SMESHGUI::GetOrCreateSMESHGUI(parent);
3007 //=============================================================================
3011 //=============================================================================
3012 bool SMESHGUI::OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3014 SMESHGUI::GetOrCreateSMESHGUI(parent);
3020 //=============================================================================
3024 //=============================================================================
3025 bool SMESHGUI::OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
3027 SMESHGUI::GetOrCreateSMESHGUI(parent);
3033 //=============================================================================
3037 //=============================================================================
3038 bool SMESHGUI::SetSettings( QAD_Desktop* parent )
3040 SMESHGUI::GetOrCreateSMESHGUI(parent);
3043 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3044 if ( DisplayMode.compare("") == 0 ) {
3045 DisplayMode = "Shading";
3046 QAD_CONFIG->addSetting("SMESH:DisplayMode","Shading");
3049 if ( DisplayMode.compare("Wireframe") == 0 ){
3050 parent->menuBar()->setItemChecked(10003, false );
3051 parent->menuBar()->setItemChecked(10002, false );
3052 parent->menuBar()->setItemChecked(10001, true );
3053 } else if ( DisplayMode.compare("Shading") == 0 ){
3054 parent->menuBar()->setItemChecked(10003, false );
3055 parent->menuBar()->setItemChecked(10002, true );
3056 parent->menuBar()->setItemChecked(10001, false );
3057 } else if ( DisplayMode.compare("Shrink") == 0 ) {
3058 parent->menuBar()->setItemChecked(10003, true );
3059 parent->menuBar()->setItemChecked(10002, false );
3060 parent->menuBar()->setItemChecked(10001, false );
3063 /* Automatic Update */
3064 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3065 if ( AutoUpdate.compare("true") == 0 ) {
3066 parent->menuBar()->setItemChecked(1001, true );
3067 smeshGUI->myAutomaticUpdate = true;
3069 parent->menuBar()->setItemChecked(1001, false );
3070 smeshGUI->myAutomaticUpdate = false;
3074 parent->menuBar()->setItemEnabled( 11, false); // IMPORT
3080 //=============================================================================
3084 //=============================================================================
3085 void SMESHGUI::DefinePopup( QString & theContext, QString & theParent, QString & theObject )
3087 /* Create or retrieve an object SMESHGUI */
3088 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3090 // NRI : Temporary added
3091 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3092 // theObject = "NothingSelected";
3093 // theContext = "NothingSelected";
3097 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3098 int nbSel = Sel->IObjectCount();
3100 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
3101 vtkScalarBarActor* aScalarBar = smeshGUI->GetScalarBar();
3102 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1) ) {
3103 theObject = "ScalarBar";
3106 theObject = "NothingSelected";
3107 theContext = "NothingSelected";
3110 theObject = "NothingSelected";
3111 theContext = "NothingSelected";
3113 } else if (nbSel == 1 ) {
3114 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3117 theObject = smeshGUI->CheckHomogeneousSelection();
3122 //=============================================================================
3126 //=============================================================================
3127 bool SMESHGUI::CustomPopup( QAD_Desktop* parent,
3129 const QString& theContext,
3130 const QString& theParent,
3131 const QString& theObject )
3133 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3134 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3136 /* Create or retrieve an object SMESHGUI */
3137 SMESHGUI::GetOrCreateSMESHGUI(parent);
3139 // NRI : Temporary added
3140 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3145 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3146 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3147 int nbSel = Sel->IObjectCount();
3150 if (studyFrame->getTypeView() != VIEW_VTK)
3153 } else if (nbSel == 1 ) {
3154 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3155 // First check type of active viewer (VTK required)
3156 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3158 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3160 int id = popup->idAt(0);
3161 if (id <= QAD_TopLabel_Popup_ID)
3162 popup->removeItemAt(0);
3166 if (theObject.compare("Component") == 0) {
3167 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3172 // Remove common popup items for Submesh, Hypothesis and Algorithm
3173 if (theObject.compare("SubMesh") == 0 ||
3174 theObject.compare("Hypothesis") == 0 ||
3175 theObject.compare("Algorithm") == 0 ) {
3176 popup->removeItem(QAD_Display_Popup_ID);
3177 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3178 popup->removeItem(QAD_Erase_Popup_ID);
3179 int id = popup->idAt(popup->count()-1); // last item
3180 if (id < 0 && id != -1) popup->removeItem(id); // separator
3183 if (theObject.compare("Component") == 0) {
3184 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3188 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3189 QFont f = QApplication::font();
3192 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3194 if ( theParent.compare("Viewer")==0 ) {
3195 if (popup->idAt(0) == id) {
3196 popup->removeItem(id);
3197 popup->insertItem( new CustomItem ( QString(IObject->getName()), f ), id, 0 );
3200 Standard_Boolean res;
3201 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3202 if ( res && studyFrame->getTypeView() == VIEW_VTK) {
3203 VTKViewer_RenderWindowInteractor* myRenderInter=
3204 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3205 if ( myRenderInter->isVisible( IObject ) ) {
3206 popup->removeItem(QAD_Display_Popup_ID);
3208 popup->removeItem(QAD_Erase_Popup_ID);
3211 popup->removeItem(QAD_Erase_Popup_ID);
3212 if (!res) {// mesh not computed -> can't display it
3213 popup->removeItem(QAD_Display_Popup_ID);
3214 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3215 popup->removeItemAt(popup->count() - 1);//separator
3218 } else if ( theParent.compare("ObjectBrowser")==0 ) {
3219 if (theObject.compare("Mesh") == 0 ||
3220 theObject.compare("SubMesh") == 0 ||
3221 theObject.compare("Hypothesis") == 0 ||
3222 theObject.compare("Algorithm") == 0 ) {
3223 popup->removeItemAt(0);
3225 if (popup->idAt(0) == id) {
3226 popup->removeItem(id);
3227 popup->removeItemAt(0);//separator
3231 Standard_Boolean res;
3232 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), res, false );
3233 if ( res && studyFrame->getTypeView() == VIEW_VTK ) {
3234 VTKViewer_RenderWindowInteractor* myRenderInter=
3235 ((VTKViewer_ViewFrame*)studyFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3236 if ( myRenderInter->isVisible( IObject ) ) {
3237 popup->removeItem(QAD_Display_Popup_ID);
3239 popup->removeItem(QAD_Erase_Popup_ID);
3242 if (theObject.compare("Mesh") == 0 ||
3243 theObject.compare("SubMesh") == 0 ||
3244 theObject.compare("Hypothesis") == 0 ||
3245 theObject.compare("Algorithm") == 0 ) {
3247 popup->removeItem(QAD_Erase_Popup_ID);
3248 if (!res) {// mesh not computed -> can't display it
3249 popup->removeItem(QAD_Display_Popup_ID);
3250 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3251 popup->removeItemAt(popup->count() - 1);//separator
3257 QString parentComp = ((SALOMEGUI_Desktop*)parent)->getComponentFromSelection();
3258 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3259 if (/*studyFrame->getTypeView() != VIEW_VTK ||*/ parentComp != parent->getActiveComponent())
3261 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3263 int id = popup->idAt(0);
3264 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3265 popup->removeItemAt(0);
3269 if (parentComp.isNull()) { // objects from several components are selected
3270 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3271 popup->removeItem(QAD_Display_Popup_ID);
3272 popup->removeItem(QAD_Erase_Popup_ID);
3273 int id = popup->idAt(popup->count()-1); // last item
3274 if (id < 0 && id != -1) popup->removeItem(id); // separator
3279 QString type = smeshGUI->CheckHomogeneousSelection();
3280 if ( type.compare("Heterogeneous Selection") != 0 ) {
3281 int id = QAD_TopLabel_Popup_ID;//popup->idAt(0);
3282 QFont f = QApplication::font();
3284 popup->removeItem(id);
3285 popup->insertItem( new CustomItem ( QString("%1 ").arg(nbSel) + type + " (s) ", f), id, 0 );
3291 //=============================================================================
3292 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3293 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3295 //=============================================================================
3296 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3298 /* Create or retrieve an object SMESHGUI */
3299 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3301 QAD_StudyFrame* activeFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3302 if (activeFrame->getTypeView() == VIEW_VTK) {
3304 SALOMEDS::SObject_var fatherSF =
3305 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
3307 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3308 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
3310 // for(;It.More();It.Next()) {
3311 // Handle(SALOME_InteractiveObject) IObject = It.Value();
3312 Handle(SALOME_InteractiveObject) IObject = theIO;
3313 if ( IObject->hasEntry() ) {
3314 // Look for the actor in all views
3315 Standard_Boolean res;
3316 SMESH_Actor *ac = smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3318 // Actor not found at all -> mesh is not computed -> do nothing!!!
3320 /*SMESH::SMESH_Mesh_var aM;
3321 SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3322 SALOMEDS::SObject_var father = aMorSM->GetFather();
3323 SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
3325 // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
3326 if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
3329 SALOMEDS::GenericAttribute_var anAttr;
3330 SALOMEDS::AttributeIOR_var anIOR;
3331 if ( !aMorSM->_is_nil() ) {
3332 if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
3333 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
3334 aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
3338 if (!aM->_is_nil()) {
3339 smeshGUI->InitActor(aM);
3340 ac = smeshGUI->ReadScript(aM);
3344 smeshGUI->DisplayActor( ac, true );
3345 smeshGUI->DisplayEdges( ac );
3346 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3349 } else { // The actor exists in some view
3350 // Check whether the actor belongs to the active view
3351 VTKViewer_RenderWindowInteractor* rwInter =
3352 ((VTKViewer_ViewFrame*)activeFrame->getRightFrame()->getViewFrame())->getRWInteractor();
3354 // The actor belongs to inactive view -> create a copy and display it in the active view
3355 if (!rwInter->isInViewer(IObject)) {
3356 SMESH_Actor* acCopy = SMESH_Actor::New();
3357 acCopy->ShallowCopy(ac);
3360 smeshGUI->DisplayActor( ac, false );
3361 smeshGUI->DisplayEdges( ac );
3362 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
3367 MESSAGE("BuildPresentation() must not be called while non-VTK view is active")
3371 //=============================================================================
3375 //=============================================================================
3376 void SMESHGUI::setOrb()
3379 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance();
3380 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
3381 _orb = init( 0 , 0 );
3383 INFOS("internal error : orb not found");
3386 ASSERT(! CORBA::is_nil(_orb));
3390 //=============================================================================
3394 //=============================================================================
3395 SMESH_Actor* SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
3397 SMESH_Actor* MeshActor;
3398 if ( !aMesh->_is_nil() ) {
3399 Standard_Boolean result;
3400 MeshActor = FindActor(aMesh, result, true);
3402 SMESH::log_array_var aSeq = aMesh->GetLog(true);
3404 if (aSeq->length() == 0) {
3405 MESSAGE("ReadScript(): log is empty")
3409 for (unsigned int ind = 0; ind < aSeq->length();ind++) {
3410 switch ( aSeq[ind].commandType )
3412 case SMESH::ADD_NODE :
3414 AddNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3417 case SMESH::ADD_EDGE :
3419 // AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3422 case SMESH::ADD_TRIANGLE :
3424 AddTriangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3427 case SMESH::ADD_QUADRANGLE :
3429 AddQuadrangles( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3432 case SMESH::ADD_TETRAHEDRON :
3434 AddTetras( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3437 case SMESH::ADD_PYRAMID :
3441 case SMESH::ADD_PRISM :
3445 case SMESH::ADD_HEXAHEDRON :
3447 AddHexaedres( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3450 case SMESH::REMOVE_NODE :
3452 RemoveNodes( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3455 case SMESH::REMOVE_ELEMENT :
3457 RemoveElements( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
3469 //=============================================================================
3473 //=============================================================================
3474 void SMESHGUI::Dump(SMESH_Actor* Mactor)
3476 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3477 vtkPoints *Pts = ugrid->GetPoints();
3478 int nbPts = Pts->GetNumberOfPoints();
3479 int nbCells = ugrid->GetNumberOfCells();
3483 In = fopen("/tmp/dumpMesh","w+");
3484 fprintf(In,"%d %d\n",nbPts,nbCells);
3485 for ( int i = 0; i < nbPts; i++ ) {
3486 float *p = ugrid->GetPoint(i);
3487 fprintf(In,"%d %e %e %e\n",i, p[0], p[1], p[2] );
3490 for ( int i = 0; i < nbCells; i++ ) {
3491 fprintf(In,"%d %d",i,ugrid->GetCell(i)->GetCellType());
3492 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3493 for (j=0; j<Id->GetNumberOfIds(); j++) {
3494 fprintf(In," %d",Id->GetId(j));
3502 //=============================================================================
3506 //=============================================================================
3507 void SMESHGUI::AddNodes( SMESH_Actor* Mactor, int number,
3508 const SMESH::double_array& coords,
3509 const SMESH::long_array& indexes)
3511 QApplication::setOverrideCursor( Qt::waitCursor );
3512 if ( Mactor->GetMapper() == NULL ) {
3513 vtkPoints *Pts = vtkPoints::New();
3514 SMESH_Grid *ugrid = SMESH_Grid::New();
3519 while ( i <= number ) {
3520 int idVTK = Pts->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3521 //Mactor->AddNode( indexes[i-1], idVTK );
3522 ugrid->AddNode( indexes[i-1], idVTK );
3526 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3527 ugrid->SetPoints(Pts);
3528 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3529 PtsMapper->SetInput( ugrid );
3530 Mactor->DataSource = PtsMapper->GetInput();
3531 Mactor->SetMapper(PtsMapper);
3533 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3534 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3537 while ( i <= number ) {
3538 int idVTK = ugrid->GetPoints()->InsertNextPoint( coords[j-1], coords[j], coords[j+1] );
3539 ugrid->AddNode( indexes[i-1], idVTK );
3543 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3544 PtsMapper->SetInput( ugrid );
3545 Mactor->DataSource = PtsMapper->GetInput();
3546 Mactor->SetMapper(PtsMapper);
3548 QApplication::restoreOverrideCursor();
3551 //=============================================================================
3555 //=============================================================================
3556 void SMESHGUI::AddNode(SMESH_Actor* Mactor, int idnode, float x, float y, float z)
3558 QApplication::setOverrideCursor( Qt::waitCursor );
3559 MESSAGE ( "SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z )
3560 if ( Mactor->GetMapper() == NULL ) {
3561 vtkPoints *Pts = vtkPoints::New();
3562 int idVTK = Pts->InsertNextPoint( x, y, z );
3563 //Mactor->AddNode( idnode, idVTK );
3564 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
3565 SMESH_Grid *ugrid = SMESH_Grid::New();
3567 ugrid->AddNode( idnode, idVTK );
3568 ugrid->SetPoints(Pts);
3569 vtkDataSetMapper * PtsMapper = vtkDataSetMapper::New();
3570 PtsMapper->SetInput( ugrid );
3571 Mactor->DataSource = PtsMapper->GetInput();
3572 Mactor->SetMapper(PtsMapper);
3574 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3575 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3576 int idVTK = ugrid->GetPoints()->InsertNextPoint( x, y, z );
3577 //Mactor->AddNode( idnode, idVTK );
3578 ugrid->AddNode( idnode, idVTK );
3579 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
3580 PtsMapper->SetInput( ugrid );
3581 Mactor->DataSource = PtsMapper->GetInput();
3582 Mactor->SetMapper(PtsMapper);
3584 QApplication::restoreOverrideCursor();
3587 //=============================================================================
3591 //=============================================================================
3592 void SMESHGUI::RemoveNode(SMESH_Actor* Mactor, int idnode)
3594 MESSAGE ( " OLD RemoveNode method " )
3595 // int id = Mactor->GetIdVTKNode( idnode );
3596 // MESSAGE ( " RemoveNode id VTK " << id )
3597 // if ( Mactor->GetMapper() != NULL ) {
3598 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3599 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3600 // vtkPoints *Pts = ugrid->GetPoints();
3601 // vtkPoints *newPts = vtkPoints::New();
3602 // int nbPts = Pts->GetNumberOfPoints();
3603 // bool findPt = false;
3604 // for ( int i = 0; i < nbPts; i++ ) {
3607 // newPts->InsertPoint(i, Pts->GetPoint(i) );
3609 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
3612 // Mactor->RemoveNode( idnode );
3616 // newUgrid->SetPoints(newPts);
3617 // int nbCells = ugrid->GetNumberOfCells();
3618 // for ( int i = 0; i < nbCells; i++ ) {
3619 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3620 // vtkIdList *newIds = vtkIdList::New();
3621 // int nbIds = Ids->GetNumberOfIds();
3622 // newIds->SetNumberOfIds(nbIds);
3623 // for ( int j = 0; j < nbIds; j++ ) {
3624 // int theid = Ids->GetId(j);
3625 // if ( theid > id ) {
3626 // newIds->SetId( j, theid-1 );
3628 // newIds->SetId( j, theid );
3630 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3631 // Mactor->RemoveElement( idSMDSel, false );
3632 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3633 // Mactor->AddElement( idSMDSel, idVTKel );
3637 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3638 // Mapper->SetInput( newUgrid );
3639 // Mactor->DataSource = Mapper->GetInput();
3640 // Mactor->SetMapper(Mapper);
3646 //=============================================================================
3650 //=============================================================================
3651 void SMESHGUI::RemoveNodes(SMESH_Actor* Mactor, int number,
3652 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3654 QApplication::setOverrideCursor( Qt::waitCursor );
3656 while ( i <= number ) {
3657 Mactor->RemoveNode( indexes[i-1] );
3661 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
3662 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
3663 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
3665 if ( Mactor->GetMapper() != NULL ) {
3666 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3667 SMESH_Grid *newUgrid = SMESH_Grid::New();
3668 newUgrid->CopyMaps(ugrid);
3670 vtkPoints *Pts = ugrid->GetPoints();
3671 vtkPoints *newPts = vtkPoints::New();
3672 int nbPts = Pts->GetNumberOfPoints();
3674 for ( int i = 0; i < nbPts; i++ ) {
3675 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
3676 if ( idSMESHDSNode != -1 ) {
3677 newPts->InsertPoint(j, Pts->GetPoint(i) );
3679 newMapVTKNodes.Bind(j, idSMESHDSNode);
3680 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
3682 MapOldNodesToNewNodes.Bind(i,j);
3687 newUgrid->SetIdsVTKNode(newMapVTKNodes);
3688 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
3689 newUgrid->SetPoints(newPts);
3691 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3692 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3694 int nbCells = ugrid->GetNumberOfCells();
3695 for ( int i = 0; i < nbCells; i++ ) {
3696 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
3697 vtkIdList *newIds = vtkIdList::New();
3698 int nbIds = Ids->GetNumberOfIds();
3699 newIds->SetNumberOfIds(nbIds);
3701 for ( int j = 0; j < nbIds; j++ ) {
3702 int theid = Ids->GetId(j);
3703 if ( MapOldNodesToNewNodes.IsBound( theid ) ) {
3704 newIds->SetId( j, MapOldNodesToNewNodes.Find( theid ) );
3711 // Filtering out cells based on non-existing nodes
3713 int idSMDSel = Mactor->GetIdSMESHDSElement( i );
3714 int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
3716 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
3717 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
3721 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3722 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3724 // Copy new data to the old DatSource: keep the single DataSource for all actors
3725 ugrid->DeepCopy(newUgrid);
3727 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3728 Mapper->SetInput( ugrid );
3729 Mactor->SetMapper(Mapper);
3731 // Commented to avoid multiple viewer updates when called by ReadScript()
3735 QApplication::restoreOverrideCursor();
3738 //=============================================================================
3742 //=============================================================================
3743 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3745 QApplication::setOverrideCursor( Qt::waitCursor );
3746 Standard_Boolean result;
3747 SMESH_Actor* ac = FindActor( aMesh, result, true );
3749 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3750 anArrayOfIdeces->length(MapIndex.Extent());
3751 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3753 for ( ; ite.More(); ite.Next() ) {
3754 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
3755 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
3758 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3759 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3762 if ( myAutomaticUpdate ) {
3763 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3764 if ( Mesh != NULL ) {
3765 smeshGUI->DisplayActor( Mesh );
3766 smeshGUI->DisplayEdges( Mesh );
3767 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3768 AddActorInSelection( Mesh );
3771 QApplication::restoreOverrideCursor();
3774 //=============================================================================
3778 //=============================================================================
3779 void SMESHGUI::RemoveElement(SMESH_Actor* Mactor, int idelement)
3781 MESSAGE ( " OLD RemoveElement method " )
3782 // int id = Mactor->GetIdVTKElement( idelement );
3783 // MESSAGE ( " RemoveElement id VTK : " << id )
3784 // if ( Mactor->GetMapper() != NULL ) {
3785 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
3786 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
3788 // int nbCells = ugrid->GetNumberOfCells();
3789 // for ( int i = 0; i < nbCells; i++ ) {
3791 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3792 // ugrid->GetCell(i)->GetPointIds() );
3794 // Mactor->RemoveElement( idelement );
3796 // newUgrid->SetPoints(ugrid->GetPoints());
3798 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3799 // Mapper->SetInput( newUgrid );
3800 // Mactor->DataSource = Mapper->GetInput();
3801 // Mactor->SetMapper(Mapper);
3807 //=============================================================================
3811 //=============================================================================
3812 void SMESHGUI::RemoveElements(SMESH_Actor* Mactor, int number,
3813 const SMESH::double_array& coords, const SMESH::long_array& indexes)
3815 QApplication::setOverrideCursor( Qt::waitCursor );
3817 while ( i <= number ) {
3818 Mactor->RemoveElement( indexes[i-1] );
3821 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
3822 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
3824 if ( Mactor->GetMapper() != NULL ) {
3825 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
3826 SMESH_Grid* newUgrid = SMESH_Grid::New();
3827 newUgrid->CopyMaps(ugrid);
3829 int nbCells = ugrid->GetNumberOfCells();
3830 for ( int i = 0; i < nbCells; i++ ) {
3831 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
3832 if ( idSMESHDSElement != -1 ) {
3833 int newId = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
3834 ugrid->GetCell(i)->GetPointIds() );
3835 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
3836 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
3840 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
3841 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
3843 newUgrid->SetPoints(ugrid->GetPoints());
3845 // Copy new data to the old DatSource: keep the single DataSource for all actors
3846 ugrid->DeepCopy(newUgrid);
3848 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
3849 Mapper->SetInput( ugrid );
3850 Mactor->SetMapper(Mapper);
3852 // Commented to avoid multiple viewer updates when called by ReadScript()
3855 QApplication::restoreOverrideCursor();
3858 //=============================================================================
3862 //=============================================================================
3863 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3865 QApplication::setOverrideCursor( Qt::waitCursor );
3866 Standard_Boolean result;
3867 SMESH_Actor* ac = FindActor( aMesh, result, true );
3869 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3870 anArrayOfIdeces->length(MapIndex.Extent());
3871 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3873 for ( ; ite.More(); ite.Next() ) {
3874 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
3875 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
3879 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
3880 aMeshEditor->RemoveElements(anArrayOfIdeces);
3883 if ( myAutomaticUpdate ) {
3884 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
3885 if ( Mesh != NULL ) {
3886 smeshGUI->DisplayActor( Mesh );
3887 smeshGUI->DisplayEdges( Mesh );
3888 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
3889 AddActorInSelection( Mesh );
3895 QApplication::restoreOverrideCursor();
3899 //=============================================================================
3903 //=============================================================================
3904 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3906 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3909 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3910 Standard_Boolean result;
3911 SMESH_Actor* ac = FindActor( aMesh, result, true );
3913 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3914 SMESH_Grid* UGrid = SMESH_Grid::New();
3915 SMESH_Grid* oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
3916 UGrid->CopyMaps(oldGrid);
3918 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3919 gf->SetInput( ac->DataSource );
3921 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3922 Mapper->SetInput( gf->GetOutput() );
3925 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3926 for ( ; ite.More(); ite.Next() ) {
3927 Mapper->GetInput()->ReverseCell( ite.Key() );
3930 UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
3931 int nbCells = Mapper->GetInput()->GetNumberOfCells();
3932 for ( int i = 0; i < nbCells; i++ ) {
3933 UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
3936 // Copy new data to the old DatSource: keep the single DataSource for all actors
3937 oldGrid->DeepCopy(UGrid);
3939 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
3940 //NewMapper->SetInput( UGrid );
3941 NewMapper->SetInput( oldGrid );
3942 NewMapper->Update();
3944 //ac->DataSource = NewMapper->GetInput();
3945 ac->SetMapper( NewMapper );
3947 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
3949 QApplication::restoreOverrideCursor();
3953 //=============================================================================
3957 //=============================================================================
3958 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex)
3960 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
3963 QApplication::setOverrideCursor( Qt::waitCursor );
3964 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
3965 Standard_Boolean result;
3967 SMESH_Actor* ac = FindActor( aMesh, result, true );
3969 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
3970 SMESH_Grid* UGrid = SMESH_Grid::New();
3971 vtkGeometryFilter *gf = vtkGeometryFilter::New();
3972 gf->SetInput( ac->DataSource );
3974 vtkExtractEdges *edges = vtkExtractEdges::New();
3975 edges->SetInput( ac->DataSource );
3977 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
3978 Mapper->SetInput( edges->GetOutput() );
3981 int nb = Mapper->GetInput()->GetNumberOfCells();
3982 //MESSAGE ( "nb : " << nb )
3984 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
3985 for ( ; ite.More(); ite.Next() ) {
3986 vtkCell* StartEdge = Mapper->GetInput()->GetCell(ite.Key());
3987 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
3988 int CellType = StartEdge->GetCellType();
3989 //MESSAGE( "DCQ : Cell Type = " << CellType)
3990 int nbPoints = StartEdge->GetNumberOfPoints();
3992 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
3993 if ( nbPoints == 2 ) {
3994 vtkUnstructuredGrid* StartUGrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
3996 vtkIdList *IdCells = vtkIdList::New();
3997 vtkIdList *IdPoints = StartEdge->GetPointIds();
4001 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),p1);
4002 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),p2);
4004 int idp1 = StartUGrid->FindPoint(p1);
4005 int idp2 = StartUGrid->FindPoint(p2);
4007 StartUGrid->GetPointCells( idp1, IdCells );
4009 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4010 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4012 //MESSAGE ( " pt 0 : " << idp1 )
4013 //MESSAGE ( " pt 1 : " << idp2 )
4015 vtkIdList *IdPts = vtkIdList::New();
4016 if (IdCells->GetNumberOfIds() >= 2) {
4017 int nbCells = IdCells->GetNumberOfIds();
4018 //MESSAGE ( " nbCells : " << nbCells )
4019 for (int j=0; j<nbCells; j++) {
4020 StartUGrid->GetCellPoints( IdCells->GetId(j), IdPts );
4021 if ( IdPts->IsId( idp2 ) == -1 ) {
4022 IdCells->DeleteId( IdCells->GetId(j) );
4027 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4029 vtkIdList *IdPts0 = vtkIdList::New();
4030 vtkIdList *IdPts1 = vtkIdList::New();
4032 if (IdCells->GetNumberOfIds() == 2) {
4033 StartUGrid->GetCellPoints( IdCells->GetId(0), IdPts0 );
4034 StartUGrid->GetCellPoints( IdCells->GetId(1), IdPts1 );
4037 TColStd_MapOfInteger EndMapIndex;
4038 for (int j = 0; j < 3; j++ ) {
4039 if ( IdPts0->GetId(j) != idp1 && IdPts0->GetId(j) != idp2 ) {
4040 EndMapIndex.Add( IdPts0->GetId(j) );
4042 if ( IdPts1->GetId(j) != idp1 && IdPts1->GetId(j) != idp2 ) {
4043 EndMapIndex.Add( IdPts1->GetId(j) );
4047 bool MyAU = myAutomaticUpdate ;
4048 myAutomaticUpdate = false ;
4050 EndMapIndex.Add( idp1 );
4051 TColStd_MapIteratorOfMapOfInteger ite1( EndMapIndex );
4053 while ( ite1.More() ) {
4054 if ( ite1.Key() == idp1 )
4059 bool reverse1 = ( i == 2 );
4060 this->AddFace( aMesh, EndMapIndex, reverse1 );
4062 EndMapIndex.Remove( idp1 );
4063 EndMapIndex.Add( idp2 );
4064 TColStd_MapIteratorOfMapOfInteger ite2( EndMapIndex );
4066 while ( ite2.More() ) {
4067 if ( ite2.Key() == idp2 )
4072 bool reverse2 = ( i == 2 );
4073 this->AddFace( aMesh, EndMapIndex, !(reverse1 == reverse2) );
4075 myAutomaticUpdate = MyAU ;
4076 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4079 TColStd_MapOfInteger StartMapIndex;
4080 StartMapIndex.Add( IdCells->GetId(0) );
4081 StartMapIndex.Add( IdCells->GetId(1) );
4082 this->RemoveElements( aMesh, StartMapIndex );
4090 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4091 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4092 // for ( int i = 0; i < nbCells; i++ ) {
4093 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4096 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4097 // NewMapper->SetInput( UGrid );
4098 // NewMapper->Update();
4100 // ac->DataSource = NewMapper->GetInput();
4101 // ac->SetMapper( NewMapper );
4103 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4105 QApplication::restoreOverrideCursor();
4109 //=============================================================================
4113 //=============================================================================
4114 void SMESHGUI::AddEdges( SMESH_Actor* Mactor, int number,
4115 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4117 QApplication::setOverrideCursor( Qt::waitCursor );
4118 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4119 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4122 while ( i <= number ) {
4123 vtkIdList *Ids = vtkIdList::New();
4124 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4125 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4126 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4127 Mactor->AddElement( indexes[j-1], id );
4131 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4132 EdgeMapper->SetInput( ugrid );
4133 Mactor->DataSource = EdgeMapper->GetInput();
4134 Mactor->SetMapper(EdgeMapper);
4135 QApplication::restoreOverrideCursor();
4138 //=============================================================================
4142 //=============================================================================
4143 void SMESHGUI::AddEdge(SMESH_Actor* Mactor, int idedge, int idnode1, int idnode2)
4145 QApplication::setOverrideCursor( Qt::waitCursor );
4146 MESSAGE ( "SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" << idnode2 )
4147 vtkIdList *Ids = vtkIdList::New();
4148 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4149 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4151 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4152 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4153 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4154 Mactor->AddElement( idedge, id );
4156 MESSAGE ( " Edge VTK id " << id )
4158 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4159 EdgeMapper->SetInput( ugrid );
4160 Mactor->DataSource = EdgeMapper->GetInput();
4161 Mactor->SetMapper(EdgeMapper);
4162 QApplication::restoreOverrideCursor();
4165 //=============================================================================
4169 //=============================================================================
4170 void SMESHGUI::AddTriangles( SMESH_Actor* Mactor, int number,
4171 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4173 QApplication::setOverrideCursor( Qt::waitCursor );
4174 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4175 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4178 while ( i <= number ) {
4179 vtkIdList *Ids = vtkIdList::New();
4180 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4181 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4182 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4183 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4184 Mactor->AddElement( indexes[j-1], id );
4188 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4189 TriMapper->SetInput( ugrid );
4190 Mactor->DataSource = TriMapper->GetInput();
4191 Mactor->SetMapper(TriMapper);
4192 QApplication::restoreOverrideCursor();
4194 void SMESHGUI::AddTriangle(SMESH_Actor* Mactor, int idtri, int idnode1, int idnode2, int idnode3)
4196 QApplication::setOverrideCursor( Qt::waitCursor );
4197 vtkIdList *Ids = vtkIdList::New();
4198 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4199 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4200 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4202 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4203 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4204 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4205 Mactor->AddElement( idtri, id );
4207 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4208 TriMapper->SetInput( ugrid );
4209 Mactor->DataSource = TriMapper->GetInput();
4210 Mactor->SetMapper(TriMapper);
4211 QApplication::restoreOverrideCursor();
4214 //=============================================================================
4218 //=============================================================================
4219 void SMESHGUI::AddQuadrangles( SMESH_Actor* Mactor, int number,
4220 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4222 QApplication::setOverrideCursor( Qt::waitCursor );
4223 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4224 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4227 while ( i <= number ) {
4228 vtkIdList *Ids = vtkIdList::New();
4229 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4230 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4231 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4232 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4233 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4234 Mactor->AddElement( indexes[j-1], id );
4238 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4239 QuadMapper->SetInput( ugrid );
4240 Mactor->DataSource = QuadMapper->GetInput();
4241 Mactor->SetMapper(QuadMapper);
4242 QApplication::restoreOverrideCursor();
4246 //=============================================================================
4250 //=============================================================================
4251 void SMESHGUI::AddQuadrangle(SMESH_Actor* Mactor, int idquad, int idnode1, int idnode2,
4252 int idnode3, int idnode4)
4254 QApplication::setOverrideCursor( Qt::waitCursor );
4255 vtkIdList *Ids = vtkIdList::New();
4256 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4257 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4258 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4259 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4261 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4262 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4263 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
4264 Mactor->AddElement( idquad, id );
4266 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
4267 QuadMapper->SetInput( ugrid );
4268 Mactor->DataSource = QuadMapper->GetInput();
4269 Mactor->SetMapper(QuadMapper);
4270 QApplication::restoreOverrideCursor();
4274 //=============================================================================
4278 //=============================================================================
4279 void SMESHGUI::AddTetras( SMESH_Actor* Mactor, int number,
4280 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4282 QApplication::setOverrideCursor( Qt::waitCursor );
4283 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4284 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4287 while ( i <= number ) {
4288 vtkIdList *Ids = vtkIdList::New();
4289 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4290 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4291 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4292 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4293 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4294 Mactor->AddElement( indexes[j-1], id );
4298 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4299 TetraMapper->SetInput( ugrid );
4300 Mactor->DataSource = TetraMapper->GetInput();
4301 Mactor->SetMapper(TetraMapper);
4302 QApplication::restoreOverrideCursor();
4306 //=============================================================================
4310 //=============================================================================
4311 void SMESHGUI::AddTetra(SMESH_Actor* Mactor, int idtetra, int idnode1, int idnode2,
4312 int idnode3, int idnode4)
4314 QApplication::setOverrideCursor( Qt::waitCursor );
4315 MESSAGE ( "SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" << idnode2
4316 << ";" << idnode3 << ";" << idnode4 )
4317 vtkIdList *Ids = vtkIdList::New();
4318 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4319 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4320 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4321 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4323 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4324 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4325 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
4326 Mactor->AddElement( idtetra, id );
4328 MESSAGE ( " Tetra VTK id " << id )
4330 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
4331 TetraMapper->SetInput( ugrid );
4332 Mactor->DataSource = TetraMapper->GetInput();
4333 Mactor->SetMapper(TetraMapper);
4334 QApplication::restoreOverrideCursor();
4338 //=============================================================================
4342 //=============================================================================
4343 void SMESHGUI::AddHexaedres( SMESH_Actor* Mactor, int number,
4344 const SMESH::double_array& coords, const SMESH::long_array& indexes)
4346 QApplication::setOverrideCursor( Qt::waitCursor );
4347 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4348 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4351 while ( i <= number ) {
4352 vtkIdList *Ids = vtkIdList::New();
4353 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j] ) );
4354 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+1] ) );
4355 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+2] ) );
4356 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+3] ) );
4357 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+4] ) );
4358 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+5] ) );
4359 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+6] ) );
4360 Ids->InsertNextId( Mactor->GetIdVTKNode( indexes[j+7] ) );
4361 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4362 Mactor->AddElement( indexes[j-1], id );
4366 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4367 HexaMapper->SetInput( ugrid );
4368 Mactor->DataSource = HexaMapper->GetInput();
4369 Mactor->SetMapper(HexaMapper);
4370 QApplication::restoreOverrideCursor();
4374 //=============================================================================
4378 //=============================================================================
4379 void SMESHGUI::AddHexaedre(SMESH_Actor* Mactor, int idhexa, int idnode1, int idnode2,
4380 int idnode3, int idnode4, int idnode5, int idnode6, int idnode7, int idnode8)
4382 QApplication::setOverrideCursor( Qt::waitCursor );
4383 MESSAGE ( "SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" << idnode2
4384 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" << idnode6
4385 << ";" << idnode7 << ";" << idnode8)
4387 vtkIdList *Ids = vtkIdList::New();
4388 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode1 ) );
4389 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode2 ) );
4390 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode3 ) );
4391 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode4 ) );
4392 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode5 ) );
4393 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode6 ) );
4394 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode7 ) );
4395 Ids->InsertNextId( Mactor->GetIdVTKNode( idnode8 ) );
4397 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4398 SMESH_Grid* ugrid = SMESH_Grid::SafeDownCast( Mactor->DataSource );
4399 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4400 Mactor->AddElement( idhexa, id );
4402 MESSAGE ( " Hexa VTK id " << id )
4404 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
4405 HexaMapper->SetInput( ugrid );
4406 Mactor->DataSource = HexaMapper->GetInput();
4407 Mactor->SetMapper(HexaMapper);
4408 QApplication::restoreOverrideCursor();
4411 //=====================================================================================
4413 //=====================================================================================
4416 bool OnGUIEvent(int theCommandID, QAD_Desktop* parent)
4418 return SMESHGUI::OnGUIEvent(theCommandID, parent);
4421 bool OnKeyPress (QKeyEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4423 return SMESHGUI::OnKeyPress (pe, parent, studyFrame);
4426 bool OnMousePress (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4428 return SMESHGUI::OnMousePress (pe, parent, studyFrame);
4431 bool OnMouseMove (QMouseEvent* pe, QAD_Desktop* parent, QAD_StudyFrame* studyFrame)
4433 return SMESHGUI::OnMouseMove (pe, parent, studyFrame);
4436 bool SetSettings ( QAD_Desktop* parent )
4438 return SMESHGUI::SetSettings( parent );
4441 bool customPopup ( QAD_Desktop* parent, QPopupMenu* popup, const QString & theContext,
4442 const QString & theParent, const QString & theObject )
4444 return SMESHGUI::CustomPopup( parent, popup, theContext, theParent, theObject );
4447 void definePopup ( QString & theContext, QString & theParent, QString & theObject )
4449 SMESHGUI::DefinePopup( theContext, theParent, theObject );
4452 bool activeStudyChanged ( QAD_Desktop* parent )
4454 SMESHGUI::activeStudyChanged( parent );
4457 void buildPresentation ( const Handle(SALOME_InteractiveObject)& theIO )
4459 SMESHGUI::BuildPresentation(theIO);
4462 void supportedViewType(int* buffer, int bufferSize)
4464 if (!buffer || !bufferSize) return;
4465 buffer[0] = (int)VIEW_VTK;
4471 //=============================================================================
4475 //=============================================================================
4476 void SMESHGUI::ViewNodes()
4478 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4481 EraseSimulationActors();
4482 mySimulationActors = vtkActorCollection::New();
4483 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4484 vtkActorCollection* theActors = theRenderer->GetActors();
4485 theActors->InitTraversal();
4486 vtkActor *ac = theActors->GetNextActor();
4487 while(!(ac==NULL)) {
4488 if ( ac->IsA("SMESH_Actor") ) {
4489 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
4490 if ( anActor->GetVisibility() == 1 ) {
4491 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4492 gf->SetInput( anActor->DataSource );
4493 vtkMaskPoints *verts = vtkMaskPoints::New();
4494 verts->SetInput(gf->GetOutput());
4495 verts->GenerateVerticesOn();
4496 verts->SetOnRatio(1);
4498 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4499 vertMapper->SetInput(verts->GetOutput());
4500 vertMapper->ScalarVisibilityOff();
4502 vtkActor *vertActor = vtkActor::New();
4503 vertActor->SetMapper(vertMapper);
4506 anActor->GetNodeColor(r, g, b ) ;
4507 vertActor->GetProperty()->SetColor( r, g, b ) ;
4509 vertActor->GetProperty()->SetPointSize( anActor->GetNodeSize() );
4511 vertActor->PickableOff();
4513 mySimulationActors->AddItem( vertActor );
4514 theRenderer->AddActor( vertActor );
4517 ac = theActors->GetNextActor();
4520 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4525 //=============================================================================
4529 //=============================================================================
4530 void SMESHGUI::Control(int theCommandID)
4532 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4535 QApplication::setOverrideCursor( Qt::waitCursor );
4536 DisplayScalarBar( false );
4538 // mpv porting vtk 4.2.2
4539 // vtkScalars *scalars = vtkScalars::New();
4540 vtkIntArray *scalars = vtkIntArray::New();
4541 scalars->SetNumberOfComponents(1);
4543 vtkDataSetMapper* meshMapper = 0;
4544 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
4545 int nbSel = Sel->IObjectCount();
4546 Standard_Boolean result;
4547 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
4548 SMESH_Actor* MeshActor = FindActorByEntry(IObject->getEntry(), result, true);
4550 // Mesh may be not updated after Compute
4551 if (!MeshActor->DataSource || !MeshActor->GetMapper()) {
4552 QApplication::restoreOverrideCursor();
4556 bool ValidateScalars = false;
4559 switch (theCommandID)
4561 case 6001: //Length Edges
4563 type = tr( "SMESH_CONTROL_LENGTH_EDGES");
4564 meshMapper = (vtkDataSetMapper*)MeshActor->EdgeDevice->GetMapper();
4565 vtkUnstructuredGrid* grid = (vtkUnstructuredGrid*)meshMapper->GetInput();
4566 MESSAGE ( " init minimum length " << grid->GetNumberOfCells() )
4567 for (int i=0; i<grid->GetNumberOfCells(); i++ ) {
4568 vtkCell* cell = grid->GetCell(i);
4569 float len = SMESHGUI_ComputeScalarValue::LengthEdges(cell);
4570 if (len == 0) continue;
4572 ValidateScalars = true;
4573 // mpv porting vtk 4.2.2
4574 // scalars->InsertScalar(i,len);
4575 scalars->InsertTuple1(i,len);
4578 if (ValidateScalars && (MeshActor->getDisplayMode()!=0))
4579 ChangeRepresentation( MeshActor, 1 );// limitation; in Wireframe, colored edges are not visible
4582 case 6011: // Area Elements
4584 type = tr( "SMESH_CONTROL_AREA_ELEMENTS");
4585 for (int i=0; i< MeshActor->GetMapper()->GetInput()->GetNumberOfCells(); i++ ) {
4586 vtkCell* cell = MeshActor->GetMapper()->GetInput()->GetCell(i);
4587 float area = SMESHGUI_ComputeScalarValue::AreaElements(cell);
4588 if (area == 0) continue;
4590 ValidateScalars = true;
4591 // mpv porting vtk 4.2.2
4592 // scalars->InsertScalar(i,area);
4593 scalars->InsertTuple1(i,area);
4596 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4597 ChangeRepresentation( MeshActor, 1 );
4602 type = tr( "SMESH_CONTROL_TAPER_ELEMENTS");
4603 for (int i=0; i< MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4604 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4605 float taper = SMESHGUI_ComputeScalarValue::Taper(cell);
4606 if (taper == 0) continue;
4608 ValidateScalars = true;
4609 // mpv porting vtk 4.2.2
4610 // scalars->InsertScalar(i,taper);
4611 scalars->InsertTuple1(i,taper);
4616 case 6013: // Aspect ratio
4618 type = tr( "SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
4619 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4620 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4621 float aspect = SMESHGUI_ComputeScalarValue::AspectRatio(cell);
4622 if (aspect == 0) continue;
4624 ValidateScalars = true;
4625 // mpv porting vtk 4.2.2
4626 // scalars->InsertScalar(i,aspect);
4627 scalars->InsertTuple1(i,aspect);
4630 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4631 ChangeRepresentation( MeshActor, 1 );
4634 case 6014: // Minimum angle
4636 type = tr( "SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
4637 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4638 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4639 float angle = SMESHGUI_ComputeScalarValue::MinimumAngle(cell);
4640 if (angle == 0) continue;
4642 ValidateScalars = true;
4643 // mpv porting vtk 4.2.2
4644 // scalars->InsertScalar(i,angle);
4645 scalars->InsertTuple1(i,angle);
4648 if (ValidateScalars && (MeshActor->getDisplayMode()!=1))
4649 ChangeRepresentation( MeshActor, 1 );
4654 type = tr( "SMESH_CONTROL_WARP_ELEMENTS");
4655 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4656 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4657 float Warp = SMESHGUI_ComputeScalarValue::Warp(cell);
4658 if (Warp == 0) continue;
4660 ValidateScalars = true;
4661 // mpv porting vtk 4.2.2
4662 // scalars->InsertScalar(i,Warp);
4663 scalars->InsertTuple1(i,Warp);
4670 type = tr( "SMESH_CONTROL_SKEW_ELEMENTS");
4671 for (int i=0; i<MeshActor->DataSource->GetNumberOfCells(); i++ ) {
4672 vtkCell* cell = MeshActor->DataSource->GetCell(i);
4673 float angle = SMESHGUI_ComputeScalarValue::Skew(cell);
4674 if (angle == 0) continue;
4676 ValidateScalars = true;
4677 // mpv porting vtk 4.2.2
4678 // scalars->InsertScalar(i,angle);
4679 scalars->InsertTuple1(i,angle);
4686 if ( !ValidateScalars ) {
4687 QApplication::restoreOverrideCursor();
4692 scalars->GetRange(range);
4694 vtkLookupTable* wat = vtkLookupTable::New();
4695 wat->SetRange( range );
4698 scalars->SetLookupTable(wat);
4700 if (!meshMapper) meshMapper = (vtkDataSetMapper*) (MeshActor->getMapper());
4701 meshMapper->SetScalarModeToUseCellData();
4702 meshMapper->GetInput()->GetCellData()->SetScalars(scalars);
4703 meshMapper->SetScalarRange( range );
4704 meshMapper->ScalarVisibilityOn();
4706 vtkScalarBarActor* aScalarBar = GetScalarBar();
4707 if ( aScalarBar == NULL ) {
4708 aScalarBar = vtkScalarBarActor::New();
4709 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
4710 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
4711 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
4712 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
4713 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
4714 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
4715 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
4716 int NumberOfLabels = QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
4717 int NumberOfColors = QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
4719 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily, Orientation,
4720 Width, Height, NumberOfColors, NumberOfLabels);
4721 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4722 theRenderer->AddActor2D(aScalarBar);
4724 aScalarBar->SetLookupTable( wat );
4725 aScalarBar->SetTitle( type.latin1() );
4729 DisplayScalarBar( true );
4731 QApplication::restoreOverrideCursor();
4735 //=============================================================================
4739 //=============================================================================
4740 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor* theScalarBar,
4741 QString Bold, QString Italic,
4742 QString Shadow, QString FontFamily,
4743 QString Orientation, float Width, float Height,
4744 int NbColors, int NbLabels )
4746 if ( Bold.isNull() || Bold.isEmpty() || (Bold.compare( "true" ) == 0) )
4747 theScalarBar->BoldOn();
4749 theScalarBar->BoldOff();
4751 if ( Italic.isNull() || Italic.isEmpty() || (Italic.compare( "true" ) == 0) )
4752 theScalarBar->ItalicOn();
4754 theScalarBar->ItalicOff();
4756 if ( Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare( "true" ) == 0) )
4757 theScalarBar->ShadowOn();
4759 theScalarBar->ShadowOff();
4761 if ( FontFamily.compare( "Arial" ) == 0 )
4762 theScalarBar->SetFontFamilyToArial();
4763 else if ( FontFamily.compare( "Courier" ) == 0 )
4764 theScalarBar->SetFontFamilyToCourier();
4765 else if ( FontFamily.compare( "Times" ) == 0 )
4766 theScalarBar->SetFontFamilyToTimes();
4768 theScalarBar->SetFontFamilyToArial();
4770 if ( Orientation.isNull() || Orientation.isEmpty() || (Orientation.compare( "Vertical" ) == 0) )
4771 theScalarBar->SetOrientationToVertical();
4773 theScalarBar->SetOrientationToHorizontal();
4776 theScalarBar->SetWidth((Width == 0)? 0.17 : Width);
4777 theScalarBar->SetHeight((Height == 0)? 0.8 : Height);
4779 theScalarBar->SetNumberOfLabels((NbLabels == 0)? 5 : NbLabels);
4780 theScalarBar->SetMaximumNumberOfColors((NbColors == 0)? 64 : NbColors);
4784 //=============================================================================
4788 //=============================================================================
4789 void SMESHGUI::DisplayScalarBar(bool visibility)
4791 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4794 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4795 vtkScalarBarActor* aScalarBar = GetScalarBar();
4797 if ( aScalarBar == NULL ) {
4798 MESSAGE("myScalarBar is NULL");
4803 aScalarBar->VisibilityOn();
4805 aScalarBar->VisibilityOff();
4806 //Turn off mesh coloring (influences on all views)
4807 vtkActorCollection* actorList=theRenderer->GetActors();
4808 actorList->InitTraversal();
4809 vtkActor *ac = actorList->GetNextActor();
4811 if (ac->GetMapper() != NULL) {
4812 ac->GetMapper()->ScalarVisibilityOff();
4814 ac = actorList->GetNextActor();
4816 // Turn off ScalarBar in all views
4817 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
4818 for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
4819 if (aFrame->getTypeView() == VIEW_VTK) {
4820 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
4821 vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
4822 actor2DList->InitTraversal();
4823 vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
4824 while (aActor2d != NULL) {
4825 if (aActor2d->IsA("vtkScalarBarActor")) {
4826 aActor2d->VisibilityOff();
4829 actor2DList->GetNextActor2D();
4834 myActiveStudy->update3dViewers();
4838 //=============================================================================
4842 //=============================================================================
4843 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
4845 vtkScalarBarActor* aScalarBar = GetScalarBar();
4846 if ( aScalarBar == NULL ) {
4847 MESSAGE("myScalarBar is NULL");
4850 DisplayScalarBar(false);
4852 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
4853 vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
4854 vtkActorCollection* aActorList = aRenderer->GetActors();
4855 aActorList->InitTraversal();
4856 vtkActor *aActor = aActorList->GetNextActor();
4857 while(aActor != NULL) {
4858 if (aActor->IsA("SMESH_Actor")) {
4859 SMESH_Actor* aMeshActor = SMESH_Actor::SafeDownCast(aActor);
4860 vtkDataSetMapper* aMeshMapper = (vtkDataSetMapper*) (aMeshActor->getMapper());
4861 if ((aMeshMapper != NULL)) {
4862 aMeshMapper->SetScalarRange( MinRange, MaxRange );
4863 aMeshMapper->ScalarVisibilityOn();
4866 aActor = aActorList->GetNextActor();
4868 DisplayScalarBar(true);
4872 //=============================================================================
4876 //=============================================================================
4877 void SMESHGUI::SetDisplaySettings()
4879 EmitSignalDeactivateDialog() ;
4880 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg( QAD_Application::getDesktop(), "") ;
4882 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
4883 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
4884 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
4885 QColor color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4886 aDlg->SetColor(1,color);
4888 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
4889 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
4890 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4891 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4892 aDlg->SetColor(2,color);
4894 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4895 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4896 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4897 color = QColor (SCr.toInt(), SCg.toInt(), SCb.toInt());
4898 aDlg->SetColor(3,color);
4900 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4901 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4902 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4903 color = QColor (SBr.toInt(), SBg.toInt(), SBb.toInt());
4904 aDlg->SetColor(4,color);
4906 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4907 aDlg->SetIntValue(1,intValue.toInt());
4908 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4909 aDlg->SetIntValue(2,intValue.toInt());
4910 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4911 aDlg->SetIntValue(3,intValue.toInt());
4913 if ( aDlg->exec() ) {
4914 QColor colorFill = aDlg->GetColor( 1 );
4915 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4916 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4917 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4919 QColor colorOutline = aDlg->GetColor( 2 );
4920 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4921 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4922 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4924 QColor colorNode = aDlg->GetColor( 3 );
4925 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4926 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4927 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4929 QColor colorBackFace = aDlg->GetColor( 4 );
4930 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4931 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4932 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4934 int width = aDlg->GetIntValue( 1 );
4935 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4937 int nodes_size = aDlg->GetIntValue( 2 );
4938 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4940 int shrink_coeff = aDlg->GetIntValue( 3 );
4941 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4947 //=======================================================================
4948 // function : Parameter()
4949 // purpose : return a parameter (double) from a dialog box
4951 // aValue : is a double used as a default value displayed
4952 // aLabel : is the title for aValue1
4953 // aTitle : is the main title
4954 // bottom : maximum value to be entered
4955 // top : minimum value to be entered
4956 // decimals : number of decimals
4957 //=======================================================================
4958 double SMESHGUI::Parameter( Standard_Boolean& res,
4959 const double aValue,
4962 const double bottom,
4964 const int decimals )
4966 SMESHGUI_aParameterDlg* Dialog =
4967 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
4970 bottom, top, decimals,
4972 Dialog->setValue( aValue );
4974 res = ( Dialog->exec() == QDialog::Accepted );
4976 X = Dialog->getDblValue();
4980 //=======================================================================
4981 // function : Parameter()
4982 // purpose : return a parameter (int) from a dialog box
4984 // aValue : is a int used as a default value displayed
4985 // aLabel : is the title for aValue1
4986 // aTitle : is the main title
4987 // bottom : maximum value to be entered
4988 // top : minimum value to be entered
4989 //=======================================================================
4990 int SMESHGUI::Parameter( Standard_Boolean& res,
4997 SMESHGUI_aParameterDlg* Dialog =
4998 new SMESHGUI_aParameterDlg( QAD_Application::getDesktop(),
5003 Dialog->setValue( aValue );
5005 res = ( Dialog->exec() == QDialog::Accepted );
5007 X = Dialog->getIntValue();
5011 //=============================================================================
5015 //=============================================================================
5016 void SMESHGUI::DisplayEdges(SMESH_Actor* ac, bool visibility)
5018 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5020 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5023 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5024 gf->SetInput(ac->DataSource);
5025 vtkFeatureEdges *edges = vtkFeatureEdges::New();
5026 edges->SetInput(gf->GetOutput());
5027 edges->BoundaryEdgesOn();
5028 edges->ManifoldEdgesOn();
5030 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5031 edgeMapper->SetInput(edges->GetOutput());
5032 edgeMapper->ScalarVisibilityOff();
5034 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5035 vtkActorCollection* actorList=theRenderer->GetActors();
5037 int test=actorList->IsItemPresent(ac->EdgeDevice);
5039 vtkProperty* prop = vtkProperty::New();
5040 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5041 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5042 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5043 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5044 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5045 ac->EdgeDevice->SetProperty(prop);
5046 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5047 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5048 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5049 ac->EdgeDevice->SetMapper(edgeMapper);
5051 theRenderer->AddActor(ac->EdgeDevice);
5053 ac->EdgeDevice->SetMapper(edgeMapper);
5054 edgeMapper->Update();
5057 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5058 shrink->SetInput(ac->DataSource);
5059 shrink->SetShrinkFactor(ac->GetShrinkFactor());
5060 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5061 Shrinkgf->SetInput( shrink->GetOutput() );
5062 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5063 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5064 ShrinkEdges->BoundaryEdgesOn();
5065 ShrinkEdges->ManifoldEdgesOn();
5067 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5068 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5069 ShrinkEdgeMapper->ScalarVisibilityOff();
5071 test=actorList->IsItemPresent(ac->EdgeShrinkDevice);
5073 vtkProperty* prop = vtkProperty::New();
5074 prop->SetColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5075 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5076 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. ) ;
5077 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt());
5078 prop->SetLineWidth( QAD_CONFIG->getSetting("SMESH:SettingsWidth").toInt() );
5079 ac->EdgeShrinkDevice->SetProperty(prop);
5080 ac->SetEdgeColor( QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").toFloat()/255.,
5081 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").toFloat()/255.,
5082 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat()/255. );
5083 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5085 theRenderer->AddActor(ac->EdgeShrinkDevice);
5087 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5088 ShrinkEdgeMapper->Update();
5091 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5096 //=============================================================================
5100 //=============================================================================
5101 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5103 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh( aMesh );
5104 SALOMEDS::GenericAttribute_var anAttr;
5105 SALOMEDS::AttributeName_var aName;
5106 if ( !aSO_M->_is_nil() ) {
5107 if (aSO_M->FindAttribute(anAttr, "AttributeName") ) {
5108 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5109 Standard_Boolean result;
5110 SMESH_Actor* MeshActor = smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5112 SMESH_Actor* amesh = SMESH_Actor::New();
5113 Handle(SALOME_InteractiveObject) IO = new SALOME_InteractiveObject(aSO_M->GetID(),
5117 amesh->setName( aName->Value() );
5118 DisplayActor(amesh, false);
5125 //=============================================================================
5129 //=============================================================================
5130 void SMESHGUI::Update()
5132 if ( myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) { //VTK
5133 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5135 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5136 int nbSel = Sel->IObjectCount();
5138 vtkActorCollection* actorList=theRenderer->GetActors();
5139 actorList->InitTraversal();
5140 vtkActor *ac = actorList->GetNextActor();
5141 while(!(ac==NULL)) {
5142 if ( ac->IsA("SMESH_Actor") ) {
5143 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5144 if ( anActor->hasIO() ) {
5145 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5149 ac = actorList->GetNextActor();
5152 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5153 for ( ; It.More(); It.Next() ) {
5154 Handle(SALOME_InteractiveObject) IO = It.Value();
5158 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5161 QApplication::restoreOverrideCursor();
5165 //=============================================================================
5169 //=============================================================================
5170 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject)& IO)
5172 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5175 if ( IO->hasEntry() ) {
5176 Standard_Boolean res;
5177 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh( IO, res );
5179 SMESH_Actor* ac = FindActorByEntry( IO->getEntry(), res, false );
5181 // Check whether the actor belongs to the active view
5182 VTKViewer_RenderWindowInteractor* rwInter =
5183 ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRWInteractor();
5185 // The actor belongs to inactive view -> create a copy and display it in the active view
5186 if (!rwInter->isInViewer(IO)) {
5187 SMESH_Actor* acCopy = SMESH_Actor::New();
5188 acCopy->ShallowCopy(ac);
5190 smeshGUI->DisplayActor( acCopy, false );
5192 ac = ReadScript( aMesh );
5199 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
5207 //=============================================================================
5211 //=============================================================================
5212 vtkActor* SMESHGUI::SimulationMoveNode(SMESH_Actor* Mactor, int idnode)
5214 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5217 mySimulationActors = vtkActorCollection::New();
5218 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5220 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5221 vtkIdList *IdCells = vtkIdList::New();
5222 ugrid->GetPointCells( idnode, IdCells );
5224 vtkPoints *Pts = vtkPoints::New();
5225 Pts = ugrid->GetPoints();
5227 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
5228 ugridSimulation->SetPoints( Pts );
5229 vtkIdList *IdPts = vtkIdList::New();
5230 for (int j=0; j<IdCells->GetNumberOfIds(); j++) {
5231 ugrid->GetCellPoints( IdCells->GetId(j), IdPts );
5232 ugridSimulation->InsertNextCell( ugrid->GetCellType( IdCells->GetId(j) ), IdPts );
5235 vtkProperty* prop = vtkProperty::New();
5236 prop->SetColor( 1., 0., 0. );
5237 prop->SetRepresentationToWireframe();
5239 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
5240 if ( Edgewidth == 0 )
5242 prop->SetLineWidth( Edgewidth+1 );
5244 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5245 Mapper->SetInput( ugridSimulation );
5246 vtkActor* ac = vtkActor::New();
5247 ac->SetMapper( Mapper );
5248 ac->SetProperty( prop );
5250 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
5251 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
5253 mySimulationActors->AddItem( ac );
5254 theRenderer->AddActor( ac );
5256 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5263 //=============================================================================
5267 //=============================================================================
5268 void SMESHGUI::DisplaySimulationNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5270 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5273 EraseSimulationActors();
5274 mySimulationActors = vtkActorCollection::New();
5275 vtkRenderer* theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5276 Standard_Boolean result;
5277 SMESH_Actor* ac = FindActor( aMesh, result, true );
5280 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5281 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5283 vtkPoints *Pts = ugrid->GetPoints();
5284 vtkPoints *newPts = vtkPoints::New();
5285 int nbPts = Pts->GetNumberOfPoints();
5286 for ( int i = 0; i < nbPts; i++ ) {
5287 newPts->InsertPoint(i, Pts->GetPoint(i) );
5290 newugrid->SetPoints(newPts);
5291 newugrid->GetPoints()->InsertNextPoint( x, y, z );
5293 vtkMaskPoints* verts = vtkMaskPoints::New();
5294 verts->SetInput(newugrid);
5295 verts->SetGenerateVertices(1);
5296 verts->SetOnRatio(1);
5298 vtkPolyDataMapper* vertMapper = vtkPolyDataMapper::New();
5299 vertMapper->SetInput( verts->GetOutput() );
5300 vertMapper->ScalarVisibilityOff();
5302 vtkActor* node = vtkActor::New();
5303 node->SetMapper( vertMapper );
5305 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5306 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5307 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5308 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5309 if ( !nodecolor.isValid() )
5310 nodecolor = QColor(0.,1.,0.);
5312 node->GetProperty()->SetColor( float(nodecolor.red())/255.,
5313 float(nodecolor.green())/255.,
5314 float(nodecolor.blue())/255.);
5316 int intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
5320 node->GetProperty()->SetPointSize( intValue );
5322 node->VisibilityOn();
5324 mySimulationActors->AddItem( node );
5325 theRenderer->AddActor(node);
5328 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5332 //=============================================================================
5336 //=============================================================================
5337 void SMESHGUI::DisplaySimulationMoveNode( vtkActor* ac, int idnode, float x, float y, float z)
5339 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5342 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5343 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
5344 pt[0] = x; pt[1] = y; pt[2] = z;
5346 ac->GetMapper()->ImmediateModeRenderingOn();
5347 ac->GetProperty()->SetRepresentationToWireframe();
5349 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5355 //=============================================================================
5359 //=============================================================================
5360 void SMESHGUI::MoveNode( SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x, float y, float z)
5362 Standard_Boolean result;
5364 SMESH_Actor* MeshActor = FindActor(aMesh, result, true);
5370 //=============================================================================
5374 //=============================================================================
5375 void SMESHGUI::ScalarVisibilityOff()
5377 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5380 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5381 vtkActorCollection* actorList=theRenderer->GetActors();
5383 actorList->InitTraversal();
5384 vtkActor *ac = actorList->GetNextActor();
5385 while(!(ac==NULL)) {
5386 if ( ac->IsA("SMESH_Actor") ) {
5387 SMESH_Actor* anActor = SMESH_Actor::SafeDownCast( ac );
5388 if ( anActor->GetVisibility() == 1 ) {
5389 vtkDataSetMapper* meshMapper = (vtkDataSetMapper*) (anActor->getMapper());
5390 meshMapper->ScalarVisibilityOff();
5391 meshMapper->SetInput( anActor->DataSource );
5392 ChangeRepresentation( anActor, anActor->getDisplayMode() );
5395 ac = actorList->GetNextActor();
5398 theRenderer->Render();
5402 //=============================================================================
5406 //=============================================================================
5407 void SMESHGUI::DisplaySimulationEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5409 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5412 EraseSimulationActors();
5413 mySimulationActors = vtkActorCollection::New();
5414 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5415 Standard_Boolean result;
5416 SMESH_Actor* ac = FindActor( aMesh, result, true );
5418 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5422 vtkIdList *Ids = vtkIdList::New();
5423 for ( ; ite.More(); ite.Next() ) {
5424 idNodes[i] = ite.Key();
5428 Ids->InsertId( 0, idNodes[0] );
5429 pts[0] = idNodes[0];
5430 Ids->InsertId( 1, idNodes[1] );
5431 pts[1] = idNodes[1];
5433 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5434 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5435 newugrid->SetPoints( ugrid->GetPoints() ) ;
5436 newugrid->InsertNextCell(VTK_LINE, 2, pts);
5438 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5439 Mapper->SetInput( newugrid );
5442 vtkActor* edge = vtkActor::New();
5443 edge->SetMapper( Mapper );
5444 edge->SetProperty( ac->GetProperty() );
5445 edge->SetBackfaceProperty( ac->GetBackfaceProperty() );
5446 edge->VisibilityOn();
5447 mySimulationActors->AddItem( edge );
5448 theRenderer->AddActor(edge);
5451 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5456 //=============================================================================
5460 //=============================================================================
5461 void SMESHGUI::DisplaySimulationTriangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5463 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5466 EraseSimulationActors();
5467 mySimulationActors = vtkActorCollection::New();
5468 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5469 Standard_Boolean result;
5470 SMESH_Actor* ac = FindActor( aMesh, result, true );
5472 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5476 vtkIdList *Ids = vtkIdList::New();
5477 for ( ; ite.More(); ite.Next() ) {
5478 idNodes[i] = ite.Key();
5483 Ids->InsertId( 0, idNodes[2] );
5484 pts[0] = idNodes[2];
5485 Ids->InsertId( 1, idNodes[1] );
5486 pts[1] = idNodes[1];
5487 Ids->InsertId( 2, idNodes[0] );
5488 pts[2] = idNodes[0];
5490 Ids->InsertId( 0, idNodes[0] );
5491 pts[0] = idNodes[0];
5492 Ids->InsertId( 1, idNodes[1] );
5493 pts[1] = idNodes[1];
5494 Ids->InsertId( 2, idNodes[2] );
5495 pts[2] = idNodes[2];
5497 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5498 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5499 newugrid->SetPoints( ugrid->GetPoints() ) ;
5500 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
5502 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5503 Mapper->SetInput( newugrid );
5506 vtkActor* tri = vtkActor::New();
5507 tri->SetMapper( Mapper );
5508 tri->SetProperty( ac->GetProperty() );
5509 tri->SetBackfaceProperty( ac->GetBackfaceProperty() );
5510 tri->VisibilityOn();
5511 mySimulationActors->AddItem( tri );
5512 theRenderer->AddActor(tri);
5515 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5520 //=============================================================================
5524 //=============================================================================
5525 void SMESHGUI::DisplaySimulationQuadrangle( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5527 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5530 EraseSimulationActors();
5531 mySimulationActors = vtkActorCollection::New();
5532 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5533 Standard_Boolean result;
5534 SMESH_Actor* ac = FindActor( aMesh, result, true );
5536 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5539 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5542 vtkIdList *Ids = vtkIdList::New();
5543 for ( ; ite.More(); ite.Next() ) {
5544 idNodes[i] = ite.Key();
5548 float *p0 = ugrid->GetPoint(idNodes[0]);
5549 float *p1 = ugrid->GetPoint(idNodes[1]);
5550 float *p2 = ugrid->GetPoint(idNodes[2]);
5551 float *p3 = ugrid->GetPoint(idNodes[3]);
5553 gp_Pnt P0(p0[0],p0[1],p0[2]);
5555 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5556 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5557 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5559 gp_Vec Cross1 = V1 ^ V2;
5560 gp_Vec Cross2 = V2 ^ V3;
5563 if ( Cross1.Dot(Cross2) < 0 ) {
5564 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5565 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5569 if ( Cross1.Dot(Cross2) < 0 ) {
5571 idNodes[2] = idNodes[3];
5575 idNodes[1] = idNodes[2];
5581 Ids->InsertId( 0, idNodes[3] );
5582 Ids->InsertId( 1, idNodes[2] );
5583 Ids->InsertId( 2, idNodes[1] );
5584 Ids->InsertId( 3, idNodes[0] );
5586 Ids->InsertId( 0, idNodes[0] );
5587 Ids->InsertId( 1, idNodes[1] );
5588 Ids->InsertId( 2, idNodes[2] );
5589 Ids->InsertId( 3, idNodes[3] );
5592 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5593 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5594 newugrid->SetPoints( ugrid->GetPoints() ) ;
5595 newugrid->InsertNextCell(VTK_QUAD, Ids);
5597 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5598 Mapper->SetInput( newugrid );
5601 vtkActor* quad = vtkActor::New();
5602 quad->SetMapper( Mapper );
5603 quad->SetProperty( ac->GetProperty() );
5604 quad->SetBackfaceProperty( ac->GetBackfaceProperty() );
5605 quad->VisibilityOn();
5606 mySimulationActors->AddItem( quad );
5607 theRenderer->AddActor(quad);
5609 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5614 //=============================================================================
5618 //=============================================================================
5619 void SMESHGUI::DisplaySimulationTetra( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5621 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5624 EraseSimulationActors();
5625 mySimulationActors = vtkActorCollection::New();
5626 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5627 Standard_Boolean result;
5628 SMESH_Actor* ac = FindActor( aMesh, result, true );
5630 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5633 vtkIdList *Ids = vtkIdList::New();
5634 for ( ; ite.More(); ite.Next() ) {
5635 idNodes[i] = ite.Key();
5639 Ids->InsertId( 0, idNodes[0] );
5640 Ids->InsertId( 1, idNodes[1] );
5641 Ids->InsertId( 2, idNodes[2] );
5642 Ids->InsertId( 3, idNodes[3] );
5644 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5645 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5646 newugrid->SetPoints( ugrid->GetPoints() ) ;
5647 newugrid->InsertNextCell(VTK_TETRA, Ids);
5649 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5650 Mapper->SetInput( newugrid );
5653 vtkActor* tetra = vtkActor::New();
5654 tetra->SetMapper( Mapper );
5655 tetra->SetProperty( ac->GetProperty() );
5656 tetra->SetBackfaceProperty( ac->GetBackfaceProperty() );
5657 tetra->VisibilityOn();
5658 mySimulationActors->AddItem( tetra );
5659 theRenderer->AddActor(tetra);
5661 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5666 //=============================================================================
5670 //=============================================================================
5671 void SMESHGUI::DisplaySimulationHexa( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5673 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5676 EraseSimulationActors();
5677 mySimulationActors = vtkActorCollection::New();
5678 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5679 Standard_Boolean result;
5680 SMESH_Actor* ac = FindActor( aMesh, result, true );
5682 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5685 vtkIdList *Ids = vtkIdList::New();
5686 for ( ; ite.More(); ite.Next() ) {
5687 idNodes[i] = ite.Key();
5691 Ids->InsertId( 0, idNodes[0] );
5692 Ids->InsertId( 1, idNodes[1] );
5693 Ids->InsertId( 2, idNodes[2] );
5694 Ids->InsertId( 3, idNodes[3] );
5695 Ids->InsertId( 4, idNodes[4] );
5696 Ids->InsertId( 5, idNodes[5] );
5697 Ids->InsertId( 6, idNodes[6] );
5698 Ids->InsertId( 7, idNodes[7] );
5700 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5701 vtkUnstructuredGrid* newugrid = vtkUnstructuredGrid::New();
5702 newugrid->SetPoints( ugrid->GetPoints() ) ;
5703 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5705 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
5706 Mapper->SetInput( newugrid );
5709 vtkActor* hexa = vtkActor::New();
5710 hexa->SetMapper( Mapper );
5711 hexa->SetProperty( ac->GetProperty() );
5712 hexa->SetBackfaceProperty( ac->GetBackfaceProperty() );
5713 hexa->VisibilityOn();
5714 mySimulationActors->AddItem( hexa );
5715 theRenderer->AddActor(hexa);
5717 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5722 //=============================================================================
5726 //=============================================================================
5727 void SMESHGUI::AddFace( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex, bool reverse )
5729 QApplication::setOverrideCursor( Qt::waitCursor );
5730 Standard_Boolean result;
5731 SMESH_Actor* ac = FindActor( aMesh, result, true );
5733 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5734 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5735 anArrayOfIdeces->length(MapIndex.Extent());
5738 for ( ; ite.More(); ite.Next() ) {
5739 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5744 if ( MapIndex.Extent() == 4 ) {
5747 TColStd_MapIteratorOfMapOfInteger ite1( MapIndex );
5748 for ( ; ite1.More(); ite1.Next() ) {
5749 idNodes[i] = ite1.Key();
5753 vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
5754 float *p0 = ugrid->GetPoint(idNodes[0]);
5755 float *p1 = ugrid->GetPoint(idNodes[1]);
5756 float *p2 = ugrid->GetPoint(idNodes[2]);
5757 float *p3 = ugrid->GetPoint(idNodes[3]);
5759 gp_Pnt P0(p0[0],p0[1],p0[2]);
5761 gp_Vec V1( P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5762 gp_Vec V2( P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5763 gp_Vec V3( P0, gp_Pnt(p3[0],p3[1],p3[2]) );
5765 gp_Vec Cross1 = V1 ^ V2;
5766 gp_Vec Cross2 = V2 ^ V3;
5768 if ( Cross1.Dot(Cross2) < 0 ) {
5770 V1 = gp_Vec(P0, gp_Pnt(p2[0],p2[1],p2[2]) );
5771 V2 = gp_Vec(P0, gp_Pnt(p1[0],p1[1],p1[2]) );
5775 if ( Cross1.Dot(Cross2) < 0 ) {
5776 tmp = anArrayOfIdeces[2];
5777 anArrayOfIdeces[2] = anArrayOfIdeces[3];
5778 anArrayOfIdeces[3] = tmp;
5780 tmp = anArrayOfIdeces[1];
5781 anArrayOfIdeces[1] = anArrayOfIdeces[2];
5782 anArrayOfIdeces[2] = tmp;
5789 for (i=0; i < (MapIndex.Extent()/2); i++) {
5790 tmp = anArrayOfIdeces[i];
5791 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent()-i-1];
5792 anArrayOfIdeces[MapIndex.Extent()-i-1] = tmp;
5795 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5796 aMeshEditor->AddFace(anArrayOfIdeces);
5798 if ( myAutomaticUpdate ) {
5799 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5800 if ( Mesh != NULL ) {
5801 smeshGUI->DisplayActor( Mesh );
5802 smeshGUI->DisplayEdges( Mesh );
5803 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5804 AddActorInSelection( Mesh );
5807 QApplication::restoreOverrideCursor();
5811 //=============================================================================
5815 //=============================================================================
5816 void SMESHGUI::AddVolume( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5818 QApplication::setOverrideCursor( Qt::waitCursor );
5819 Standard_Boolean result;
5820 SMESH_Actor* ac = FindActor( aMesh, result, true );
5822 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5823 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5824 anArrayOfIdeces->length(MapIndex.Extent());
5827 for ( ; ite.More(); ite.Next() ) {
5828 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5832 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5833 aMeshEditor->AddVolume(anArrayOfIdeces);
5835 if ( myAutomaticUpdate ) {
5836 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5837 if ( Mesh != NULL ) {
5838 smeshGUI->DisplayActor( Mesh );
5839 smeshGUI->DisplayEdges( Mesh );
5840 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5841 AddActorInSelection( Mesh );
5844 QApplication::restoreOverrideCursor();
5848 //=============================================================================
5852 //=============================================================================
5853 void SMESHGUI::AddEdge( SMESH::SMESH_Mesh_ptr aMesh, const TColStd_MapOfInteger& MapIndex )
5855 QApplication::setOverrideCursor( Qt::waitCursor );
5856 Standard_Boolean result;
5857 SMESH_Actor* ac = FindActor( aMesh, result, true );
5859 TColStd_MapIteratorOfMapOfInteger ite( MapIndex );
5860 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
5861 anArrayOfIdeces->length(MapIndex.Extent());
5864 for ( ; ite.More(); ite.Next() ) {
5865 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
5869 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5870 aMeshEditor->AddEdge(anArrayOfIdeces);
5872 if ( myAutomaticUpdate ) {
5873 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5874 if ( Mesh != NULL ) {
5875 smeshGUI->DisplayActor( Mesh );
5876 smeshGUI->DisplayEdges( Mesh );
5877 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5878 AddActorInSelection( Mesh );
5881 QApplication::restoreOverrideCursor();
5884 //=============================================================================
5888 //=============================================================================
5889 void SMESHGUI::AddNode( SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
5891 QApplication::setOverrideCursor( Qt::waitCursor );
5892 Standard_Boolean result;
5893 SMESH_Actor* ac = FindActor( aMesh, result, true );
5895 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
5896 aMeshEditor->AddNode(x,y,z);
5898 if ( myAutomaticUpdate ) {
5899 SMESH_Actor* Mesh = smeshGUI->ReadScript(aMesh);
5900 if ( Mesh != NULL ) {
5901 smeshGUI->DisplayActor( Mesh );
5902 smeshGUI->DisplayEdges( Mesh );
5903 smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
5904 AddActorInSelection( Mesh );
5908 QApplication::restoreOverrideCursor();
5911 //=============================================================================
5915 //=============================================================================
5916 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor *ac)
5918 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5921 EraseSimulationActors();
5922 mySimulationActors2D = vtkActor2DCollection::New();
5924 vtkRenderer *theRenderer = ((VTKViewer_ViewFrame*)myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5926 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
5927 gs2->SetGlyphTypeToTriangle();
5930 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
5931 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
5932 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
5934 legend->SetNumberOfEntries(4);
5935 legend->SetEntryString( 0, tr( "SMESH_BOUNDARYEDGES" ) );
5936 legend->SetEntrySymbol( 0, gs2->GetOutput() );
5937 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.) );
5938 legend->SetEntryString( 1, tr( "SMESH_MANIFOLDEDGES" ) );
5939 legend->SetEntrySymbol( 1, gs2->GetOutput() );
5940 legend->SetEntryColor(1, ac->GetMapper()->GetLookupTable()->GetColor(0.666667) );
5941 legend->SetEntryString( 2, tr( "SMESH_NONMANIFOLDEDGES" ) );
5942 legend->SetEntrySymbol( 2, gs2->GetOutput() );
5943 legend->SetEntryColor(2, ac->GetMapper()->GetLookupTable()->GetColor(0.222222) );
5944 legend->SetEntryString( 3, tr( "SMESH_FEATUREEDGES" ) );
5945 legend->SetEntrySymbol( 3, gs2->GetOutput() );
5946 legend->SetEntryColor(3, ac->GetMapper()->GetLookupTable()->GetColor(0.444444) );
5947 legend->SetPadding( 5 );
5948 // legend->GetProperty()->SetColor();
5950 mySimulationActors2D->AddItem( legend );
5951 theRenderer->AddActor2D( legend );
5954 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->Repaint();
5957 //===============================================================================
5958 // function : OnEditDelete()
5960 //===============================================================================
5961 void SMESHGUI::OnEditDelete()
5963 if ( QAD_MessageBox::warn2
5964 ( QAD_Application::getDesktop(),
5965 tr ("SMESH_WRN_WARNING"),
5966 tr ("SMESH_REALLY_DELETE"),
5967 tr ("SMESH_BUT_YES"), tr ("SMESH_BUT_NO"), 1, 0, 0 ) != 1 )
5970 int nbSf = myActiveStudy->getStudyFramesCount();
5972 Standard_Boolean found;
5973 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
5974 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
5975 SALOMEDS::GenericAttribute_var anAttr;
5976 SALOMEDS::AttributeIOR_var anIOR;
5978 SALOME_Selection* Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
5979 SALOME_ListIteratorOfListIO It( Sel->StoredIObjects() );
5980 for(;It.More();It.Next()) {
5981 Handle(SALOME_InteractiveObject) IObject = It.Value();
5982 if ( IObject->hasEntry() ) {
5983 SALOMEDS::SObject_var SO = myStudy->FindObjectID( IObject->getEntry() );
5985 /* Erase child graphical objects */
5986 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5987 for (; it->More();it->Next()) {
5988 SALOMEDS::SObject_var CSO= it->Value();
5989 if (CSO->FindAttribute(anAttr, "AttributeIOR") ) {
5990 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5992 for ( int i = 0; i < nbSf; i++ ) {
5993 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
5994 if ( sf->getTypeView() == VIEW_VTK ) {
5995 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
5996 SMESH_Actor* ac = smeshGUI->FindActorByEntry( CSO->GetID(), found, false );
5998 Renderer->RemoveActor(ac->EdgeDevice);
5999 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6000 Renderer->RemoveActor(ac);
6007 /* Erase main graphical object */
6008 for ( int i = 0; i < nbSf; i++ ) {
6009 QAD_StudyFrame* sf = myActiveStudy->getStudyFrame(i);
6010 if ( sf->getTypeView() == VIEW_VTK ) {
6011 vtkRenderer* Renderer = ((VTKViewer_ViewFrame*)smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
6012 VTKViewer_RenderWindowInteractor* myRenderInter= ((VTKViewer_ViewFrame*)sf->getRightFrame()->getViewFrame())->getRWInteractor();
6013 SMESH_Actor* ac = smeshGUI->FindActorByEntry( IObject->getEntry(), found, false );
6015 Renderer->RemoveActor(ac->EdgeDevice);
6016 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6018 myRenderInter->Remove( IObject );
6022 /* Erase objects in Study */
6023 SALOMEDS::SObject_var obj = myStudy->FindObjectID( IObject->getEntry() );
6024 if ( !obj->_is_nil() ) {
6025 QAD_Operation* op = new SALOMEGUI_ImportOperation( myActiveStudy );
6027 aStudyBuilder->RemoveObject(obj);
6031 } /* IObject->hasEntry() */
6034 /* Clear any previous selection */
6035 Sel->ClearIObjects() ;
6036 myActiveStudy->updateObjBrowser();