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();