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
22 // File : SMESHGUI.cxx
23 // Author : Nicolas REJNERI
28 #include "SMESHGUI_AddHypothesisDlg.h"
29 #include "SMESHGUI_AddAlgorithmDlg.h"
30 #include "SMESHGUI_InitMeshDlg.h"
31 #include "SMESHGUI_AddSubMeshDlg.h"
32 #include "SMESHGUI_NodesDlg.h"
33 #include "SMESHGUI_TransparencyDlg.h"
34 #include "SMESHGUI_GroupDlg.h"
35 #include "SMESHGUI_RemoveNodesDlg.h"
36 #include "SMESHGUI_RemoveElementsDlg.h"
37 #include "SMESHGUI_MeshInfosDlg.h"
38 #include "SMESHGUI_Preferences_ColorDlg.h"
39 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
40 #include "SMESHGUI_Preferences_SelectionDlg.h"
41 #include "SMESHGUI_aParameterDlg.h"
42 #include "SMESHGUI_ComputeScalarValue.h"
43 #include "SMESHGUI_MoveNodesDlg.h"
44 #include "SMESHGUI_OrientationElementsDlg.h"
45 #include "SMESHGUI_DiagonalInversionDlg.h"
46 #include "SMESHGUI_AddFaceDlg.h"
47 #include "SMESHGUI_AddEdgeDlg.h"
48 #include "SMESHGUI_AddVolumeDlg.h"
49 #include "SMESHGUI_EditHypothesesDlg.h"
50 #include "SMESHGUI_CreateHypothesesDlg.h"
51 #include "SMESHGUI_FilterDlg.h"
52 #include "SMESHGUI_XmlHandler.h"
54 #include "SMESH_Actor.h"
55 #include "SMESH_Object.h"
58 #include "Utils_ORB_INIT.hxx"
59 #include "Utils_SINGLETON.hxx"
62 #include "QAD_Tools.h"
63 #include "QAD_Config.h"
64 #include "QAD_Settings.h"
65 #include "QAD_RightFrame.h"
66 #include "QAD_MessageBox.h"
67 #include "QAD_Resource.h"
68 #include "QAD_FileDlg.h"
69 #include "QAD_Desktop.h"
70 #include "QAD_ResourceMgr.h"
71 #include "QAD_WaitCursor.h"
73 #include "OCCViewer_ViewPort.h"
74 #include "OCCViewer_ViewPort3d.h"
75 #include "OCCViewer_Viewer3d.h"
77 #include "GEOM_InteractiveObject.hxx"
79 #include "SALOME_NamingService.hxx"
80 #include "SALOME_ListIteratorOfListIO.hxx"
81 #include "SALOME_InteractiveObject.hxx"
83 #include "SALOMEGUI_Desktop.h"
84 #include "SALOMEGUI_NameDlg.h"
85 #include "SALOMEGUI_ImportOperation.h"
86 #include "SALOMEGUI_QtCatchCorbaException.hxx"
88 #include "utilities.h"
91 #include "SMDS_Mesh.hxx"
92 #include "SMESHDS_Document.hxx"
93 #include "Document_Reader.h"
94 #include "Document_Writer.h"
95 #include "Mesh_Reader.h"
96 #include "Mesh_Writer.h"
98 #include "DriverDAT_R_SMESHDS_Document.h"
99 #include "DriverMED_R_SMESHDS_Document.h"
100 #include "DriverUNV_R_SMESHDS_Document.h"
101 #include "DriverDAT_W_SMESHDS_Document.h"
102 #include "DriverMED_W_SMESHDS_Document.h"
103 #include "DriverUNV_W_SMESHDS_Document.h"
104 #include "DriverDAT_R_SMESHDS_Mesh.h"
105 #include "DriverMED_R_SMESHDS_Mesh.h"
106 #include "DriverUNV_R_SMESHDS_Mesh.h"
107 #include "DriverDAT_W_SMESHDS_Mesh.h"
108 #include "DriverMED_W_SMESHDS_Mesh.h"
109 #include "DriverUNV_W_SMESHDS_Mesh.h"
112 #define INCLUDE_MENUITEM_DEF
113 #include <qapplication.h>
114 #include <qlineedit.h>
115 #include <qmenudata.h>
116 #include <qmenubar.h>
117 #include <qpopupmenu.h>
120 #include <qcheckbox.h>
121 #include <qcolordialog.h>
122 #include <qspinbox.h>
126 #include <qradiobutton.h>
129 #include "VTKViewer_Common.h"
130 #include "VTKViewer_ViewFrame.h"
131 #include "VTKViewer_InteractorStyleSALOME.h"
133 #include <vtkScalarBarActor.h>
134 #include <vtkLegendBoxActor.h>
135 #include <vtkFeatureEdges.h>
136 #include <vtkDoubleArray.h>
137 #include <vtkTextProperty.h>
139 // Open CASCADE Includes
140 #include <gp_Pnt.hxx>
141 #include <gp_Vec.hxx>
143 #include <boost/shared_ptr.hpp>
145 static SMESHGUI *smeshGUI = 0;
146 static CORBA::ORB_var _orb;
150 typedef pair<int,string> TKeyOfVisualObj;
151 typedef boost::shared_ptr<SMESH_VisualObj> TVisualObjPtr;
152 typedef map<TKeyOfVisualObj,TVisualObjPtr> TVisualObjCont;
153 static TVisualObjCont VISUALOBJCONT;
156 TVisualObjPtr GetVisualObj(int theStudyId, const char* theEntry){
157 TVisualObjPtr aVisualObj;
159 TVisualObjCont::key_type aKey(theStudyId,theEntry);
160 TVisualObjCont::iterator anIter = VISUALOBJCONT.find(aKey);
161 if(anIter != VISUALOBJCONT.end()){
162 aVisualObj = anIter->second;
164 SALOMEDS::Study_var aStudy = QAD_Application::getDesktop()->getActiveStudy()->getStudyDocument();
165 SALOMEDS::SObject_var aSObj = aStudy->FindObjectID(theEntry);
166 if(!CORBA::is_nil(aSObj)){
167 SALOMEDS::GenericAttribute_var anAttr;
168 if(aSObj->FindAttribute(anAttr,"AttributeIOR")){
169 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
170 CORBA::String_var aVal = anIOR->Value();
171 CORBA::Object_var anObj =_orb->string_to_object(aVal.in());
172 if(!CORBA::is_nil(anObj)){
173 //Try narrow to SMESH_Mesh interafce
174 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
175 if(!aMesh->_is_nil()){
176 aVisualObj.reset(new SMESH_MeshObj(aMesh));
177 aVisualObj->Update();
178 TVisualObjCont::value_type aValue(aKey,aVisualObj);
179 VISUALOBJCONT.insert(aValue);
182 //Try narrow to SMESH_Group interafce
183 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(anObj);
184 if(!aGroup->_is_nil()){
185 SALOMEDS::SObject_var aFatherSObj = aSObj->GetFather();
186 if(aFatherSObj->_is_nil()) return aVisualObj;
187 aFatherSObj = aFatherSObj->GetFather();
188 if(aFatherSObj->_is_nil()) return aVisualObj;
189 CORBA::String_var anEntry = aFatherSObj->GetID();
190 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
191 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
192 aVisualObj.reset(new SMESH_GroupObj(aGroup,aMeshObj));
193 aVisualObj->Update();
194 TVisualObjCont::value_type aValue(aKey,aVisualObj);
195 VISUALOBJCONT.insert(aValue);
199 //Try narrow to SMESH_subMesh interafce
200 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
201 if(!aSubMesh->_is_nil()){
202 SALOMEDS::SObject_var aFatherSObj = aSObj->GetFather();
203 if(aFatherSObj->_is_nil()) return aVisualObj;
204 aFatherSObj = aFatherSObj->GetFather();
205 if(aFatherSObj->_is_nil()) return aVisualObj;
206 CORBA::String_var anEntry = aFatherSObj->GetID();
207 TVisualObjPtr aVisObj = GetVisualObj(theStudyId,anEntry.in());
208 if(SMESH_MeshObj* aMeshObj = dynamic_cast<SMESH_MeshObj*>(aVisObj.get())){
209 aVisualObj.reset(new SMESH_subMeshObj(aSubMesh,aMeshObj));
210 aVisualObj->Update();
211 TVisualObjCont::value_type aValue(aKey,aVisualObj);
212 VISUALOBJCONT.insert(aValue);
221 INFOS("GetMeshObj - There is no SMESH_Mesh object for the SALOMEDS::Strudy and Entry!!!");
227 VTKViewer_ViewFrame* GetVtkViewFrame(QAD_StudyFrame* theStudyFrame){
228 QAD_ViewFrame* aViewFrame = theStudyFrame->getRightFrame()->getViewFrame();
229 return dynamic_cast<VTKViewer_ViewFrame*>(aViewFrame);
232 void UpdateSelectionProp() {
233 QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
234 QList<QAD_StudyFrame> aFrameList = aStudy->getStudyFrames();
236 QString SCr, SCg, SCb;
237 SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
238 SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
239 SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
240 QColor aHiColor = Qt::white;
241 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
242 aHiColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
244 SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
245 SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
246 SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
247 QColor aSelColor = Qt::yellow;
248 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
249 aSelColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
250 QString SW = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
251 if (SW.isEmpty()) SW = "5";
253 SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
254 SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
255 SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
256 QColor aPreColor = Qt::cyan;
257 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
258 aPreColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
259 QString PW = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
260 if (PW.isEmpty()) PW = "5";
262 QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
263 if (SP1.isEmpty()) SP1 = "0.025";
264 QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
265 if (SP2.isEmpty()) SP2 = "0.001";
267 for (QAD_StudyFrame* aStudyFrame = aFrameList.first(); aStudyFrame; aStudyFrame = aFrameList.next()) {
268 if (aStudyFrame->getTypeView() == VIEW_VTK) {
269 VTKViewer_ViewFrame* aVtkViewFrame = GetVtkViewFrame(aStudyFrame);
270 if (!aVtkViewFrame) continue;
271 // update VTK viewer properties
272 VTKViewer_RenderWindowInteractor* anInteractor = aVtkViewFrame->getRWInteractor();
274 // mesh element selection
275 anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255.,
276 aSelColor.blue()/255., SW.toInt());
279 anInteractor->SetSelectionTolerance(SP1.toDouble(), SP2.toDouble());
282 VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
284 aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255.,
285 aPreColor.blue()/255., PW.toInt());
289 vtkRenderer* aRenderer = aVtkViewFrame->getRenderer();
290 vtkActorCollection *aCollection = aRenderer->GetActors();
291 aCollection->InitTraversal();
292 while(vtkActor *anAct = aCollection->GetNextActor()){
293 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
294 anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255.,
295 aHiColor.blue()/255.);
296 anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255.,
297 aPreColor.blue()/255.);
304 VTKViewer_ViewFrame* GetCurrentVtkView(){
305 QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
306 QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
307 return GetVtkViewFrame(aStudyFrame);
311 SMESH_Actor* FindActorByEntry(QAD_StudyFrame *theStudyFrame,
312 const char* theEntry)
314 if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
315 vtkRenderer *aRenderer = aViewFrame->getRenderer();
316 vtkActorCollection *aCollection = aRenderer->GetActors();
317 aCollection->InitTraversal();
318 while(vtkActor *anAct = aCollection->GetNextActor()){
319 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
320 if(anActor->hasIO()){
321 Handle(SALOME_InteractiveObject) anIO = anActor->getIO();
322 if(anIO->hasEntry() && strcmp(anIO->getEntry(),theEntry) == 0){
333 SMESH_Actor* FindActorByEntry(const char* theEntry){
334 QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
335 QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
336 return FindActorByEntry(aStudyFrame,theEntry);
340 SMESH_Actor* CreateActor(SALOMEDS::Study_ptr theStudy,
341 const char* theEntry,
342 int theIsClear = false)
344 SMESH_Actor *anActor = NULL;
345 CORBA::Long anId = theStudy->StudyId();
346 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,theEntry)){
347 SALOMEDS::SObject_var aSObj = theStudy->FindObjectID(theEntry);
348 if(!aSObj->_is_nil()){
349 SALOMEDS::GenericAttribute_var anAttr;
350 if(aSObj->FindAttribute(anAttr,"AttributeName")){
351 SALOMEDS::AttributeName_var aName = SALOMEDS::AttributeName::_narrow(anAttr);
352 CORBA::String_var aVal = aName->Value();
353 string aNameVal = aVal.in();
354 SMESH::FilterManager_ptr aFilterMgr = smeshGUI->GetFilterMgr();
355 anActor = SMESH_Actor::New(aVisualObj,aFilterMgr,theEntry,aNameVal.c_str(),theIsClear);
363 void DisplayActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
364 if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
365 aViewFrame->AddActor(theActor);
366 aViewFrame->Repaint();
371 void RemoveActor(QAD_StudyFrame *theStudyFrame, SMESH_Actor* theActor){
372 if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
373 aViewFrame->RemoveActor(theActor);
374 aViewFrame->Repaint();
380 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
381 aViewFrame->onViewFitAll();
382 aViewFrame->Repaint();
386 vtkRenderer* GetCurrentRenderer(){
387 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView())
388 return aViewFrame->getRenderer();
392 void RepaintCurrentView(){
393 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView())
394 aViewFrame->Repaint();
398 enum EDisplaing {eDisplayAll, eDisplay, eDisplayOnly, eErase, eEraseAll};
399 void UpdateView(QAD_StudyFrame *theStudyFrame, EDisplaing theAction,
400 const char* theEntry = "")
402 if(VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(theStudyFrame)){
403 vtkRenderer *aRenderer = aViewFrame->getRenderer();
404 vtkActorCollection *aCollection = aRenderer->GetActors();
405 aCollection->InitTraversal();
408 while(vtkActor *anAct = aCollection->GetNextActor()){
409 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
410 anActor->SetVisibility(true);
417 while(vtkActor *anAct = aCollection->GetNextActor()){
418 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
419 anActor->SetVisibility(false);
424 if(SMESH_Actor *anActor = FindActorByEntry(theStudyFrame,theEntry)){
428 anActor->SetVisibility(true);
431 anActor->SetVisibility(false);
438 QAD_Study* aStudy = theStudyFrame->getStudy();
439 SALOMEDS::Study_var aDocument = aStudy->getStudyDocument();
440 if(anActor = CreateActor(aDocument,theEntry,true)) {
441 DisplayActor(theStudyFrame,anActor);
454 void UpdateView(EDisplaing theAction, const char* theEntry = ""){
455 QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
456 QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
457 UpdateView(aStudyFrame,theAction,theEntry);
460 static bool IsReferencedObject( SALOMEDS::SObject_ptr SO )
462 if ( !SO->_is_nil() ) {
463 SALOMEDS::GenericAttribute_var anAttr;
464 if ( SO->FindAttribute( anAttr, "AttributeTarget" ) ) {
465 SALOMEDS::AttributeTarget_var aTarget = SALOMEDS::AttributeTarget::_narrow( anAttr );
466 SALOMEDS::Study::ListOfSObject_var aList = aTarget->Get();
467 if ( aList->length() > 0 ) {
475 void SetPointRepresentation(bool theIsVisible){
476 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
477 vtkRenderer *aRenderer = aViewFrame->getRenderer();
478 vtkActorCollection *aCollection = aRenderer->GetActors();
479 aCollection->InitTraversal();
480 while(vtkActor *anAct = aCollection->GetNextActor()){
481 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
482 if(anActor->GetVisibility()){
483 anActor->SetPointRepresentation(theIsVisible);
487 RepaintCurrentView();
492 //=============================================================================
496 //=============================================================================
497 class CustomItem:public QCustomMenuItem
500 CustomItem(const QString & s, const QFont & f):string(s), font(f)
507 void paint(QPainter * p, const QColorGroup & /*cg */ , bool /*act */ ,
508 bool /*enabled */ , int x, int y, int w, int h)
511 p->drawText(x, y, w, h,
512 AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
517 return QFontMetrics(font).
518 size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
525 //=============================================================================
529 //=============================================================================
530 SMESHGUI::SMESHGUI( const QString& theName, QObject* theParent ) :
531 SALOMEGUI( theName, theParent )
535 //=============================================================================
539 //=============================================================================
540 SMESHGUI::~SMESHGUI()
544 //=============================================================================
548 //=============================================================================
549 SMESHGUI* SMESHGUI::GetSMESHGUI()
552 GetOrCreateSMESHGUI( QAD_Application::getDesktop() );
558 Standard_EXPORT SALOMEGUI* GetComponentGUI() {
559 return SMESHGUI::GetSMESHGUI();
562 //=============================================================================
566 //=============================================================================
567 SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
571 smeshGUI = new SMESHGUI;
572 smeshGUI->myActiveDialogBox = 0 ;
573 smeshGUI->myState = -1 ;
574 smeshGUI->myDesktop = desktop ;
576 /* get smesh engine */
577 Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
578 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
580 /* get geom engine */
581 Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");
582 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
584 /* set current study */
585 smeshGUI->myActiveStudy = desktop->getActiveStudy();
586 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
587 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
588 smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
589 smeshGUI->myComponentMesh->SetCurrentStudy( smeshGUI->myStudy );
590 // smeshGUI->myComponentGeom->NbLabels();
592 /* create service object */
593 smeshGUI->myStudyAPI = SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
595 smeshGUI->myDocument = new SMESHDS_Document(1);//NBU
597 smeshGUI->mySimulationActors = vtkActorCollection::New();
598 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
601 smeshGUI->myFilterMgr = smeshGUI->myComponentMesh->CreateFilterManager();
603 /* load resources for all available meshers */
604 smeshGUI->InitAvailableHypotheses();
606 /* study may have changed - set current study */
607 smeshGUI->myActiveStudy = desktop->getActiveStudy();
608 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
609 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
610 smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
611 smeshGUI->myComponentMesh->SetCurrentStudy( smeshGUI->myStudy );
613 // Set active study to Study API
614 smeshGUI->myStudyAPI.Update( smeshGUI->myStudy );
617 /* Automatic Update flag */
618 smeshGUI->myAutomaticUpdate = ( QAD_CONFIG->getSetting( "SMESH:AutomaticUpdate" ).compare( "true" ) == 0 );
623 //=============================================================================
627 //=============================================================================
628 void SMESHGUI::SetState(int aState)
630 this->myState = aState;
634 //=============================================================================
638 //=============================================================================
639 void SMESHGUI::ResetState()
645 //=============================================================================
649 //=============================================================================
650 void SMESHGUI::EmitSignalDeactivateDialog()
652 emit this->SignalDeactivateActiveDialog();
656 //=============================================================================
660 //=============================================================================
661 void SMESHGUI::EmitSignalCloseAllDialogs()
663 emit SignalCloseAllDialogs();
667 //=============================================================================
671 //=============================================================================
672 QDialog *SMESHGUI::GetActiveDialogBox()
674 return this->myActiveDialogBox;
677 //=============================================================================
681 //=============================================================================
682 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
684 this->myActiveDialogBox = (QDialog *) aDlg;
688 //=============================================================================
692 //=============================================================================
693 QAD_Study *SMESHGUI::GetActiveStudy()
695 return this->myActiveStudy;
698 //=============================================================================
702 //=============================================================================
703 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
705 return SALOMEDS::Study::_narrow(myStudy);
708 //=============================================================================
712 //=============================================================================
713 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
718 //=============================================================================
722 //=============================================================================
723 QAD_Desktop *SMESHGUI::GetDesktop()
725 return this->myDesktop;
728 //=============================================================================
732 //=============================================================================
733 bool SMESHGUI::ActiveStudyChanged(QAD_Desktop* parent)
735 MESSAGE("SMESHGUI::activeStudyChanged init.");
736 QAD_Study* prevStudy = 0;
738 prevStudy = smeshGUI->myActiveStudy;
739 /* Create or retrieve an object SMESHGUI */
740 MESSAGE("Active study changed : prev study =" << prevStudy);
741 SMESHGUI::GetOrCreateSMESHGUI( parent );
742 MESSAGE("Active study changed : active study =" << smeshGUI->myActiveStudy);
743 if ( prevStudy != smeshGUI->myActiveStudy ) {
744 smeshGUI->EmitSignalCloseAllDialogs();
745 MESSAGE("Active study changed : SMESHGUI nullified" << endl);
747 ::UpdateSelectionProp();
749 MESSAGE("SMESHGUI::activeStudyChanged done.");
753 //=============================================================================
757 //=============================================================================
758 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
760 /* Here the position is on the bottom right corner - 10 */
761 // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
763 QAD_Desktop *PP = QAD_Application::getDesktop();
764 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
765 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
769 //=============================================================================
773 //=============================================================================
774 void SMESHGUI::EraseSimulationActors()
776 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
778 vtkRenderer *theRenderer =
779 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
780 getRightFrame()->getViewFrame())->getRenderer();
781 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
783 if (mySimulationActors != NULL)
785 mySimulationActors->InitTraversal();
786 vtkActor *ac = mySimulationActors->GetNextActor();
787 while (!(ac == NULL))
789 theRenderer->RemoveActor(ac);
790 ac = mySimulationActors->GetNextActor();
792 mySimulationActors->RemoveAllItems();
794 if (mySimulationActors2D != NULL)
796 mySimulationActors2D->InitTraversal();
797 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
798 while (!(ac == NULL))
800 theRenderer->RemoveActor2D(ac);
801 ac = mySimulationActors2D->GetNextActor2D();
803 mySimulationActors2D->RemoveAllItems();
805 SetPointRepresentation(false);
809 //=============================================================================
813 //=============================================================================
814 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape,
818 if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
819 SMESH::SMESH_Mesh_var aMesh = myComponentMesh->CreateMesh( aShape );
820 if ( !aMesh->_is_nil() ) {
821 SALOMEDS::SObject_var SM = smeshGUI->myStudy->FindObjectIOR( _orb->object_to_string( aMesh ) );
822 myStudyAPI.SetName( SM, NameMesh );
823 return SMESH::SMESH_Mesh::_narrow(aMesh);
827 catch( const SALOME::SALOME_Exception& S_ex ) {
828 QtCatchCorbaException( S_ex );
830 return SMESH::SMESH_Mesh::_nil();
833 //=============================================================================
837 //=============================================================================
838 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh,
839 GEOM::GEOM_Shape_ptr aShape,
842 SMESH::SMESH_subMesh_var aSubMesh;
844 if ( !aMesh->_is_nil() && !aShape->_is_nil() )
846 aSubMesh = SMESH::SMESH_subMesh::_duplicate( aMesh->GetSubMesh( aShape, NameMesh.latin1() ) ); //VSR: published automatically
848 catch( const SALOME::SALOME_Exception& S_ex ) {
849 QtCatchCorbaException( S_ex );
850 aSubMesh = SMESH::SMESH_subMesh::_nil();
852 return aSubMesh._retn();
855 //=============================================================================
859 //=============================================================================
860 SMESH::SMESH_Group_ptr SMESHGUI::AddGroup( SMESH::SMESH_Mesh_ptr aMesh,
861 SMESH::ElementType aType,
864 SMESH::SMESH_Group_var aGroup;
866 if ( !aMesh->_is_nil() )
868 aGroup = SMESH::SMESH_Group::_duplicate( aMesh->CreateGroup( aType, strdup(aName) ) ); //VSR: published automatically
870 catch( const SALOME::SALOME_Exception& S_ex ) {
871 QtCatchCorbaException( S_ex );
872 aGroup = SMESH::SMESH_Group::_nil();
874 myActiveStudy->updateObjBrowser( true );
875 return aGroup._retn();
878 //=============================================================================
882 //=============================================================================
884 static void addMap( const map<string, HypothesisData*>& theMap,
885 map<string, HypothesisData*>& toMap)
887 map<string, HypothesisData*>::const_iterator it;
888 for ( it = theMap.begin(); it != theMap.end(); it++ )
893 //=============================================================================
895 * InitAvailableHypotheses (read from resource XML file)
897 //=============================================================================
898 void SMESHGUI::InitAvailableHypotheses ()
901 if ((myHypothesesMap.begin() == myHypothesesMap.end()) &&
902 (myAlgorithmsMap.begin() == myAlgorithmsMap.end()))
905 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
908 // Find name of a resource XML file ("SMESH_Meshers.xml");
910 char* cenv = getenv("SMESH_MeshersList");
912 HypsXml.sprintf("%s", cenv);
914 QStringList HypsXmlList = QStringList::split( ":", HypsXml, false );
915 if (HypsXmlList.count() == 0)
917 QAD_MessageBox::error1(QAD_Application::getDesktop(),
918 tr("SMESH_WRN_WARNING"),
919 tr("MESHERS_FILE_NO_VARIABLE"),
924 // loop on files in HypsXml
925 QString aNoAccessFiles;
926 for ( int i = 0; i < HypsXmlList.count(); i++ ) {
927 QString HypsXml = HypsXmlList[ i ];
929 // Find full path to the resource XML file
930 QString xmlFile = HypsXml + ".xml";
931 xmlFile = QAD_Tools::addSlash(resMgr->findFile(xmlFile, HypsXml)) + xmlFile;
933 QFile file (QAD_Tools::unix2win(xmlFile));
934 if (file.exists() && file.open(IO_ReadOnly))
938 SMESHGUI_XmlHandler* myXmlHandler = new SMESHGUI_XmlHandler();
939 ASSERT(myXmlHandler);
941 QXmlInputSource source (file);
942 QXmlSimpleReader reader;
943 reader.setContentHandler(myXmlHandler);
944 reader.setErrorHandler(myXmlHandler);
945 bool ok = reader.parse(source);
949 addMap( myXmlHandler->myHypothesesMap, myHypothesesMap );
950 addMap( myXmlHandler->myAlgorithmsMap, myAlgorithmsMap );
954 QAD_MessageBox::error1(myDesktop,
955 tr("INF_PARSE_ERROR"),
956 tr(myXmlHandler->errorProtocol()),
962 if (aNoAccessFiles.isEmpty())
963 aNoAccessFiles = xmlFile;
965 aNoAccessFiles += ", " + xmlFile;
970 if (!aNoAccessFiles.isEmpty())
972 QString aMess = tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
973 aMess += tr("MESHERS_FILE_CHECK_VARIABLE");
975 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
976 tr("SMESH_WRN_WARNING"),
984 //=============================================================================
986 * GetAvailableHypotheses (read from resource XML file)
988 //=============================================================================
989 QStringList SMESHGUI::GetAvailableHypotheses (const bool isAlgo)
991 QStringList aHypList;
993 // Init list of available hypotheses, if needed
994 InitAvailableHypotheses();
996 // fill list of hypotheses/algorithms
997 map<string, HypothesisData*>::iterator anIter;
1000 anIter = myAlgorithmsMap.begin();
1001 for (; anIter != myAlgorithmsMap.end(); anIter++)
1003 aHypList.append(((*anIter).first).c_str());
1008 anIter = myHypothesesMap.begin();
1009 for (; anIter != myHypothesesMap.end(); anIter++)
1011 aHypList.append(((*anIter).first).c_str());
1018 //=============================================================================
1022 //=============================================================================
1023 HypothesisData* SMESHGUI::GetHypothesisData (const char* aHypType)
1025 HypothesisData* aHypData = 0;
1027 // Init list of available hypotheses, if needed
1028 InitAvailableHypotheses();
1030 if (myHypothesesMap.find(aHypType) == myHypothesesMap.end())
1032 if (myAlgorithmsMap.find(aHypType) != myAlgorithmsMap.end())
1034 aHypData = myAlgorithmsMap[aHypType];
1039 aHypData = myHypothesesMap[aHypType];
1044 //=============================================================================
1046 * Get a Hypothesis Creator from a Plugin Library
1048 //=============================================================================
1049 SMESHGUI_GenericHypothesisCreator* SMESHGUI::GetHypothesisCreator(const QString& aHypType)
1051 char* sHypType = (char*)aHypType.latin1();
1052 MESSAGE("Get HypothesisCreator for " << sHypType);
1054 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
1056 // check, if creator for this hypothesis type already exists
1057 if (myHypCreatorMap.find(sHypType) != myHypCreatorMap.end())
1059 aCreator = myHypCreatorMap[sHypType];
1063 // 1. Init list of available hypotheses, if needed
1064 InitAvailableHypotheses();
1066 // 2. Get names of plugin libraries
1067 HypothesisData* aHypData = GetHypothesisData(sHypType);
1072 QString aClientLibName = aHypData->ClientLibName;
1073 QString aServerLibName = aHypData->ServerLibName;
1075 // 3. Load Client Plugin Library
1078 // load plugin library
1079 MESSAGE("Loading client meshers plugin library ...");
1080 void* libHandle = dlopen (aClientLibName, RTLD_LAZY);
1083 // report any error, if occured
1084 const char* anError = dlerror();
1089 // get method, returning hypothesis creator
1090 MESSAGE("Find GetHypothesisCreator() method ...");
1091 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
1092 (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI);
1093 GetHypothesisCreator procHandle =
1094 (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
1097 MESSAGE("bad hypothesis client plugin library");
1102 // get hypothesis creator
1103 MESSAGE("Get Hypothesis Creator for " << aHypType);
1104 aCreator = procHandle(aHypType, aServerLibName, smeshGUI);
1107 MESSAGE("no such a hypothesis in this plugin");
1111 // map hypothesis creator to a hypothesis name
1112 myHypCreatorMap[sHypType] = aCreator;
1117 catch (const SALOME::SALOME_Exception& S_ex)
1119 QtCatchCorbaException(S_ex);
1126 //=============================================================================
1130 //=============================================================================
1131 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis (const QString& aHypType,
1132 const QString& aHypName,
1135 MESSAGE("Create " << aHypType << " with name " << aHypName);
1137 SMESH::SMESH_Hypothesis_var Hyp;
1139 HypothesisData* aHypData = GetHypothesisData((char*)aHypType.latin1());
1140 QString aServLib = aHypData->ServerLibName;
1144 Hyp = myComponentMesh->CreateHypothesis(aHypType, aServLib);
1145 if (!Hyp->_is_nil())
1147 SALOMEDS::SObject_var SHyp =
1148 smeshGUI->myStudy->FindObjectIOR( _orb->object_to_string( Hyp ) );
1149 if (!SHyp->_is_nil())
1151 if ( !aHypName.isEmpty() )
1152 myStudyAPI.SetName( SHyp, aHypName );
1153 myActiveStudy->updateObjBrowser(true);
1158 catch (const SALOME::SALOME_Exception & S_ex)
1160 QtCatchCorbaException(S_ex);
1163 return SMESH::SMESH_Hypothesis::_nil();
1166 //=============================================================================
1170 //=============================================================================
1171 bool SMESHGUI::AddHypothesisOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
1172 SMESH::SMESH_Hypothesis_ptr aHyp)
1174 int res = SMESH::HYP_UNKNOWN_FATAL;
1177 if ( !aMesh->_is_nil() ) {
1178 SALOMEDS::SObject_var SM = myStudyAPI.FindObject( aMesh );
1179 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
1181 res = aMesh->AddHypothesis( aShape, aHyp );
1182 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1183 SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1184 if ( !SM->_is_nil() && !SH->_is_nil() ) {
1185 //myStudyAPI.SetHypothesis(SM, SH); // VSR: published automatically by engine
1186 myStudyAPI.ModifiedMesh(SM, false);
1189 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1191 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1193 tr(QString("SMESH_HYP_%1").arg(res)),
1194 tr("SMESH_BUT_OK"));
1197 else if ( res > SMESH::HYP_OK ) {
1199 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1200 tr("SMESH_WRN_WARNING"),
1201 tr(QString("SMESH_HYP_%1").arg(res)),
1202 tr("SMESH_BUT_OK"));
1206 catch( const SALOME::SALOME_Exception& S_ex ) {
1208 QtCatchCorbaException( S_ex );
1209 res = SMESH::HYP_UNKNOWN_FATAL;
1212 return res < SMESH::HYP_UNKNOWN_FATAL;
1215 //=============================================================================
1219 //=============================================================================
1220 bool SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh
1221 (const Handle(SALOME_InteractiveObject)& IObject)
1223 int res = SMESH::HYP_UNKNOWN_FATAL;
1226 if (IObject->hasReference())
1229 SMESH::SMESH_Hypothesis_var anHyp;
1230 SALOMEDS::SObject_var SO_Hypothesis =
1231 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
1232 SALOMEDS::GenericAttribute_var anAttr;
1233 SALOMEDS::AttributeIOR_var anIOR;
1235 if (!SO_Hypothesis->_is_nil()) {
1236 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
1237 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1238 anHyp = SMESH::SMESH_Hypothesis::_narrow
1239 (_orb->string_to_object(anIOR->Value()));
1242 SALOMEDS::SObject_var SO_Applied_Hypothesis =
1243 smeshGUI->myStudy->FindObjectID(IObject->getReference());
1244 if (!SO_Applied_Hypothesis->_is_nil()) {
1245 SALOMEDS::SObject_var MorSM =
1246 smeshGUI->myStudyAPI.GetMeshOrSubmesh(SO_Applied_Hypothesis);
1247 if (!MorSM->_is_nil()) {
1248 GEOM::GEOM_Shape_var aShape =
1249 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
1250 if (!aShape->_is_nil() && MorSM->FindAttribute(anAttr, "AttributeIOR")) {
1251 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1252 SMESH::SMESH_Mesh_var aMesh =
1253 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1254 SMESH::SMESH_subMesh_var aSubMesh =
1255 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1257 if (!aSubMesh->_is_nil())
1258 aMesh = aSubMesh->GetFather();
1260 if (!aMesh->_is_nil())
1262 res = aMesh->RemoveHypothesis(aShape, anHyp);
1263 if ( res < SMESH::HYP_UNKNOWN_FATAL )
1264 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
1265 if ( res > SMESH::HYP_OK ) {
1267 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1268 tr("SMESH_WRN_WARNING"),
1269 tr(QString("SMESH_HYP_%1").arg(res)),
1270 tr("SMESH_BUT_OK"));
1279 catch( const SALOME::SALOME_Exception& S_ex ) {
1281 QtCatchCorbaException( S_ex );
1282 res = SMESH::HYP_UNKNOWN_FATAL;
1285 else if (IObject->hasEntry())
1287 MESSAGE("IObject entry " << IObject->getEntry());
1289 return res < SMESH::HYP_UNKNOWN_FATAL;
1292 //=============================================================================
1296 //=============================================================================
1297 bool SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh(SALOMEDS::SObject_ptr MorSM,
1298 SMESH::SMESH_Hypothesis_ptr anHyp)
1300 SALOMEDS::SObject_var AHR, aRef;
1301 SALOMEDS::GenericAttribute_var anAttr;
1302 SALOMEDS::AttributeIOR_var anIOR;
1303 int res = SMESH::HYP_UNKNOWN_FATAL;
1306 if (!MorSM->_is_nil()) {
1308 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
1309 if (!aShape->_is_nil()) {
1310 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
1311 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1312 SMESH::SMESH_Mesh_var aMesh =
1313 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1314 SMESH::SMESH_subMesh_var aSubMesh =
1315 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1317 if ( !aSubMesh->_is_nil() )
1318 aMesh = aSubMesh->GetFather();
1320 if (!aMesh->_is_nil()) {
1321 res = aMesh->RemoveHypothesis(aShape, anHyp);
1322 if ( res < SMESH::HYP_UNKNOWN_FATAL )
1323 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
1324 if ( res > SMESH::HYP_OK ) {
1326 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1327 tr("SMESH_WRN_WARNING"),
1328 tr(QString("SMESH_HYP_%1").arg(res)),
1329 tr("SMESH_BUT_OK"));
1336 catch( const SALOME::SALOME_Exception& S_ex ) {
1338 QtCatchCorbaException( S_ex );
1339 res = SMESH::HYP_UNKNOWN_FATAL;
1342 return res < SMESH::HYP_UNKNOWN_FATAL;
1345 //=============================================================================
1349 //=============================================================================
1350 bool SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh,
1351 SMESH::SMESH_Hypothesis_ptr aHyp )
1353 int res = SMESH::HYP_UNKNOWN_FATAL;
1356 if ( !aMesh->_is_nil() ) {
1357 SALOMEDS::SObject_var SM = myStudyAPI.FindObject( aMesh );
1358 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
1360 res = aMesh->AddHypothesis( aShape, aHyp );
1361 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1362 //SALOMEDS::SObject_var SH = myStudyAPI.FindObject( aHyp );
1363 //if ( !SM->_is_nil() && !SH->_is_nil() ) {
1364 //myStudyAPI.SetAlgorithms(SM, SH);
1365 myStudyAPI.ModifiedMesh( SM, false );
1368 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1370 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1372 tr(QString("SMESH_HYP_%1").arg(res)),
1373 tr("SMESH_BUT_OK"));
1376 else if ( res > SMESH::HYP_OK ) {
1378 QAD_MessageBox::warn1( QAD_Application::getDesktop(),
1379 tr( "SMESH_WRN_WARNING" ),
1380 tr(QString("SMESH_HYP_%1").arg(res)),
1381 tr( "SMESH_BUT_OK" ) );
1385 catch( const SALOME::SALOME_Exception& S_ex ) {
1387 QtCatchCorbaException( S_ex );
1388 res = SMESH::HYP_UNKNOWN_FATAL;
1391 return res < SMESH::HYP_UNKNOWN_FATAL;
1394 //=============================================================================
1398 //=============================================================================
1399 bool SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh,
1400 SMESH::SMESH_Hypothesis_ptr aHyp )
1402 int res = SMESH::HYP_UNKNOWN_FATAL;
1405 if ( !aSubMesh->_is_nil() ) {
1407 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1408 SALOMEDS::SObject_var SsubM = myStudyAPI.FindObject( aSubMesh );
1409 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
1410 if ( !aMesh->_is_nil() && !SsubM->_is_nil() && !aShape->_is_nil() ) {
1411 res = aMesh->AddHypothesis( aShape, aHyp );
1412 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1413 //SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1414 // if (!SsubM->_is_nil() && !SH->_is_nil())
1416 // myStudyAPI.SetHypothesis(SsubM, SH);
1417 myStudyAPI.ModifiedMesh( SsubM, false );
1420 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1422 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1424 tr(QString("SMESH_HYP_%1").arg(res)),
1425 tr("SMESH_BUT_OK"));
1428 else if ( res > SMESH::HYP_OK ) {
1430 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1431 tr( "SMESH_WRN_WARNING" ),
1432 tr(QString("SMESH_HYP_%1").arg(res)),
1433 tr( "SMESH_BUT_OK" ) );
1438 catch( const SALOME::SALOME_Exception& S_ex ) {
1440 QtCatchCorbaException( S_ex );
1441 res = SMESH::HYP_UNKNOWN_FATAL;
1444 return res < SMESH::HYP_UNKNOWN_FATAL;
1447 //=============================================================================
1451 //=============================================================================
1452 bool SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh,
1453 SMESH::SMESH_Hypothesis_ptr aHyp )
1455 int res = SMESH::HYP_UNKNOWN_FATAL;
1458 if ( !aSubMesh->_is_nil() ) {
1460 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1461 SALOMEDS::SObject_var SsubM = myStudyAPI.FindObject(aSubMesh);
1462 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
1463 if ( !aMesh->_is_nil() && !SsubM->_is_nil() && !aShape->_is_nil() ) {
1464 res = aMesh->AddHypothesis( aShape, aHyp );
1465 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1466 //SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1467 //if (!SsubM->_is_nil() && !SH->_is_nil()) {
1468 //myStudyAPI.SetAlgorithms(SsubM, SH);
1469 myStudyAPI.ModifiedMesh( SsubM, false );
1472 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1474 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1476 tr(QString("SMESH_HYP_%1").arg(res)),
1477 tr("SMESH_BUT_OK"));
1480 else if ( res > SMESH::HYP_OK ) {
1482 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1483 tr( "SMESH_WRN_WARNING" ),
1484 tr(QString("SMESH_HYP_%1").arg(res)),
1485 tr( "SMESH_BUT_OK" ) );
1490 catch( const SALOME::SALOME_Exception& S_ex ) {
1492 QtCatchCorbaException( S_ex );
1493 res = SMESH::HYP_UNKNOWN_FATAL;
1496 return res < SMESH::HYP_UNKNOWN_FATAL;
1499 //=============================================================================
1503 //=============================================================================
1504 int SMESHGUI::GetNameOfSelectedIObjects(SALOME_Selection * Sel, QString & aName)
1506 int nbSel = Sel->IObjectCount();
1509 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1510 aName = IObject->getName();
1514 aName = tr("SMESH_OBJECTS_SELECTED").arg(nbSel);
1519 //=============================================================================
1523 //=============================================================================
1524 int SMESHGUI::GetNameOfSelectedNodes(SALOME_Selection * Sel, QString & aName){
1526 if(Sel->IObjectCount() == 1){
1527 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1528 if(IObject->hasEntry()){
1529 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1530 TColStd_MapOfInteger MapIndex;
1531 Sel->GetIndex(IObject, MapIndex);
1532 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1533 for(; ite.More(); ite.Next()){
1534 aName += QString(" %1").arg(anActor->GetNodeObjId(ite.Key()));
1536 return MapIndex.Extent();
1543 //=============================================================================
1547 //=============================================================================
1548 int SMESHGUI::GetNameOfSelectedElements(SALOME_Selection * Sel, QString & aName){
1550 if(Sel->IObjectCount() == 1){
1551 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1552 if(IObject->hasEntry()){
1553 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1554 TColStd_MapOfInteger MapIndex;
1555 Sel->GetIndex(IObject, MapIndex);
1556 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1557 std::vector<int> aList;
1558 for(; ite.More(); ite.Next()){
1559 int aVtkId = ite.Key();
1560 int anObjId = anActor->GetElemObjId(aVtkId);
1561 std::vector<int>::iterator found = find(aList.begin(), aList.end(), anObjId);
1562 // MESSAGE("GetNameOfSelectedElements(): VTK Id = " << aVtkId << ", OBJECT Id = " << anObjId);
1563 if (found == aList.end()) {
1564 aList.push_back(anObjId);
1565 aName += QString(" %1").arg(anObjId);
1568 return aList.size();
1576 //=============================================================================
1580 //=============================================================================
1581 int SMESHGUI::GetNameOfSelectedEdges(SALOME_Selection * Sel, QString & aName){
1583 if(Sel->IObjectCount() == 1){
1584 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1585 if(IObject->hasEntry()){
1586 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1587 TColStd_MapOfInteger MapIndex;
1588 Sel->GetIndex(IObject, MapIndex);
1589 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1590 for(; ite.More(); ite.Next()){
1591 aName += QString(" %1").arg(ite.Key());
1593 return MapIndex.Extent();
1601 //=============================================================================
1605 //=============================================================================
1606 SMESH_Actor *SMESHGUI::FindActorByEntry(QString theEntry,
1607 Standard_Boolean & theResult,
1608 bool onlyInActiveView)
1611 int aNbStudyFrames = myActiveStudy->getStudyFramesCount();
1612 for (int i = 0; i < aNbStudyFrames; i++){
1613 QAD_StudyFrame *aStudyFrame = myActiveStudy->getStudyFrame(i);
1614 if(SMESH_Actor *anActor = ::FindActorByEntry(aStudyFrame,theEntry.latin1())){
1622 //=============================================================================
1626 //=============================================================================
1627 SMESH_Actor* SMESHGUI::FindActor(CORBA::Object_ptr theObj,
1628 Standard_Boolean & theResult,
1629 bool theOnlyInActiveView)
1632 SMESH_Actor* aRes = NULL;
1633 if ( !CORBA::is_nil( theObj ) ) {
1634 SALOMEDS::SObject_var aSObject = SALOMEDS::SObject::_narrow( myStudy->FindObjectIOR( _orb->object_to_string( theObj ) ) );
1635 if( !aSObject->_is_nil()) {
1636 CORBA::String_var anEntry = aSObject->GetID();
1637 aRes = FindActorByEntry( anEntry.in(), theResult, theOnlyInActiveView );
1643 //=============================================================================
1647 //=============================================================================
1648 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject) & IO,
1649 Standard_Boolean & testResult)
1651 SMESH::SMESH_Mesh_var aMesh;
1657 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1658 SALOMEDS::GenericAttribute_var anAttr;
1659 SALOMEDS::AttributeIOR_var anIOR;
1660 if (!obj->_is_nil())
1662 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1664 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1666 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1667 if (!aMesh->_is_nil())
1670 return SMESH::SMESH_Mesh::_duplicate(aMesh);
1675 return SMESH::SMESH_Mesh::_nil();
1678 //=============================================================================
1682 //=============================================================================
1683 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject) & IO,
1684 Standard_Boolean & testResult)
1686 SMESH::SMESH_subMesh_var aSubMesh;
1692 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1693 SALOMEDS::GenericAttribute_var anAttr;
1694 SALOMEDS::AttributeIOR_var anIOR;
1695 if (!obj->_is_nil())
1697 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1699 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1700 aSubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1701 if (!aSubMesh->_is_nil())
1704 return SMESH::SMESH_subMesh::_duplicate(aSubMesh);
1709 return SMESH::SMESH_subMesh::_nil();
1712 //=============================================================================
1716 //=============================================================================
1717 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis(const Handle(SALOME_InteractiveObject) & IO,
1718 Standard_Boolean & testResult)
1720 SMESH::SMESH_Hypothesis_var aHyp;
1726 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1727 SALOMEDS::GenericAttribute_var anAttr;
1728 SALOMEDS::AttributeIOR_var anIOR;
1729 if (!obj->_is_nil())
1731 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1733 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1734 aHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1735 if (!aHyp->_is_nil())
1738 return SMESH::SMESH_Hypothesis::_duplicate(aHyp);
1743 return SMESH::SMESH_Hypothesis::_nil();
1746 //=============================================================================
1750 //=============================================================================
1751 SMESH::SMESH_Group_ptr SMESHGUI::ConvertIOinSMESHGroup(const Handle(SALOME_InteractiveObject) & IO,
1752 Standard_Boolean & testResult)
1754 SMESH::SMESH_Group_var aGroup;
1758 if (IO->hasEntry()) {
1759 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1760 SALOMEDS::GenericAttribute_var anAttr;
1761 SALOMEDS::AttributeIOR_var anIOR;
1762 if (!obj->_is_nil()) {
1763 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1764 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1765 aGroup = SMESH::SMESH_Group::_narrow(_orb->string_to_object(anIOR->Value()));
1766 if (!aGroup->_is_nil()) {
1768 return SMESH::SMESH_Group::_duplicate(aGroup);
1773 return SMESH::SMESH_Group::_nil();
1776 //=============================================================================
1780 //=============================================================================
1781 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject) & IO,
1782 Standard_Boolean & testResult)
1784 GEOM::GEOM_Shape_var aShape;
1788 if (IO->hasEntry()) {
1789 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1790 SALOMEDS::GenericAttribute_var anAttr;
1791 SALOMEDS::AttributeIOR_var anIOR;
1792 if (!obj->_is_nil()) {
1793 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1794 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1795 aShape = myComponentGeom->GetIORFromString(anIOR->Value());
1796 if (!aShape->_is_nil()) {
1798 return GEOM::GEOM_Shape::_duplicate(aShape);
1803 return GEOM::GEOM_Shape::_nil();
1806 //=============================================================================
1810 //=============================================================================
1811 void SMESHGUI::SetViewMode(int commandId){
1812 SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1813 if(Sel->IObjectCount() >= 1){
1814 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1815 for(; It.More(); It.Next()){
1816 Handle(SALOME_InteractiveObject) IObject = It.Value();
1817 if(IObject->hasEntry()){
1818 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1821 ChangeRepresentation(anActor,0);
1824 ChangeRepresentation(anActor,1);
1827 ChangeRepresentation(anActor,2);
1830 ChangeRepresentation(anActor,5);
1833 ChangeRepresentation(anActor,3);
1839 if(commandId == 1133)
1840 ChangeRepresentation(NULL,4);
1844 //=============================================================================
1848 //=============================================================================
1849 void SMESHGUI::ChangeRepresentation(SMESH_Actor * theActor, int type){
1852 //theActor->UnShrink();
1853 theActor->SetRepresentation(SMESH_Actor::eEdge);
1857 //theActor->UnShrink();
1858 theActor->SetRepresentation(SMESH_Actor::eSurface);
1862 theActor->IsShrunk() ? theActor->UnShrink() : theActor->SetShrink();
1863 //theActor->SetRepresentation(SMESH_Actor::eSurface);
1867 //theActor->UnShrink();
1868 theActor->SetRepresentation(SMESH_Actor::ePoint);
1873 theActor->GetSufaceColor(color[0], color[1], color[2]);
1874 int c0 = int (color[0] * 255);
1875 int c1 = int (color[1] * 255);
1876 int c2 = int (color[2] * 255);
1877 QColor c(c0, c1, c2);
1880 theActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1881 c0 = int (edgecolor[0] * 255);
1882 c1 = int (edgecolor[1] * 255);
1883 c2 = int (edgecolor[2] * 255);
1884 QColor e(c0, c1, c2);
1886 float backfacecolor[3];
1887 theActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
1888 c0 = int (backfacecolor[0] * 255);
1889 c1 = int (backfacecolor[1] * 255);
1890 c2 = int (backfacecolor[2] * 255);
1891 QColor b(c0, c1, c2);
1894 theActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1895 c0 = int (nodecolor[0] * 255);
1896 c1 = int (nodecolor[1] * 255);
1897 c2 = int (nodecolor[2] * 255);
1898 QColor n(c0, c1, c2);
1900 int Edgewidth = (int)theActor->GetLineWidth();
1903 int intValue = int(theActor->GetNodeSize());
1904 float Shrink = theActor->GetShrinkFactor();
1906 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),"");
1907 aDlg->SetColor(1, c);
1908 aDlg->SetColor(2, e);
1909 aDlg->SetColor(3, n);
1910 aDlg->SetColor(4, b);
1911 aDlg->SetIntValue(1, Edgewidth);
1912 aDlg->SetIntValue(2, intValue);
1913 aDlg->SetIntValue(3, int(Shrink*100.));
1915 QColor color = aDlg->GetColor(1);
1916 QColor edgecolor = aDlg->GetColor(2);
1917 QColor nodecolor = aDlg->GetColor(3);
1918 QColor backfacecolor = aDlg->GetColor(4);
1919 /* actor color and backface color */
1920 theActor->SetSufaceColor(float (color.red()) / 255.,
1921 float (color.green()) / 255.,
1922 float (color.blue()) / 255.);
1923 theActor->SetBackSufaceColor(float (backfacecolor.red()) / 255.,
1924 float (backfacecolor.green()) / 255.,
1925 float (backfacecolor.blue()) / 255.);
1928 theActor->SetEdgeColor(float (edgecolor.red()) / 255.,
1929 float (edgecolor.green()) / 255.,
1930 float (edgecolor.blue()) / 255.);
1932 /* Shrink factor and size edges */
1933 theActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
1934 theActor->SetLineWidth(aDlg->GetIntValue(1));
1936 /* Nodes color and size */
1937 theActor->SetNodeColor(float (nodecolor.red()) / 255.,
1938 float (nodecolor.green()) / 255.,
1939 float (nodecolor.blue()) / 255.);
1940 theActor->SetNodeSize(aDlg->GetIntValue(2));
1947 EmitSignalDeactivateDialog();
1948 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(),"",false);
1955 //=============================================================================
1959 //=============================================================================
1960 void SMESHGUI::UpdateView(){
1961 ::RepaintCurrentView();
1964 //=============================================================================
1968 //=============================================================================
1969 void SMESHGUI::DisplayActor(SMESH_Actor * theActor, bool theVisibility){
1970 theActor->SetVisibility(theVisibility);
1971 ::DisplayActor(myActiveStudy->getActiveStudyFrame(),theActor);
1974 //=============================================================================
1978 //=============================================================================
1979 void SMESHGUI::EraseActor(SMESH_Actor * theActor){
1980 theActor->SetVisibility(false);
1983 //=============================================================================
1987 //=============================================================================
1988 bool SMESHGUI::AddActorInSelection(SMESH_Actor * ac)
1990 SALOME_Selection *Sel =
1991 SALOME_Selection::Selection(myActiveStudy->getSelection());
1992 Sel->ClearIObjects();
1994 return Sel->AddIObject(ac->getIO());
1999 //=============================================================================
2003 //=============================================================================
2004 QString SMESHGUI::CheckHomogeneousSelection()
2006 SALOME_Selection *Sel =
2007 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2010 SALOME_ListIteratorOfListIO Itinit(Sel->StoredIObjects());
2011 for (; Itinit.More(); Itinit.Next())
2013 List.Append(Itinit.Value());
2016 QString RefType = CheckTypeObject(Sel->firstIObject());
2017 SALOME_ListIteratorOfListIO It(List);
2018 for (; It.More(); It.Next())
2020 Handle(SALOME_InteractiveObject) IObject = It.Value();
2021 QString Type = CheckTypeObject(IObject);
2022 if (Type.compare(RefType) != 0)
2023 return "Heterogeneous Selection";
2026 Sel->ClearIObjects();
2027 SALOME_ListIteratorOfListIO It1(List);
2028 for (; It1.More(); It1.Next())
2030 int res = Sel->AddIObject(It1.Value());
2032 myActiveStudy->highlight(It1.Value(), false);
2034 myActiveStudy->highlight(It1.Value(), true);
2039 //=============================================================================
2043 //=============================================================================
2044 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject) & IO)
2046 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
2047 if (!sobj->_is_nil()) {
2048 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
2049 if (strcmp(scomp->GetID(), IO->getEntry()) == 0)
2050 { // component is selected
2055 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2056 Sel->ClearIObjects();
2058 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter(HYPOTHESIS);
2059 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter(ALGORITHM);
2060 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter(MESH);
2061 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter(SUBMESH);
2062 Handle(SMESH_TypeFilter) aGroupFilter = new SMESH_TypeFilter(GROUP);
2063 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter(MESHorSUBMESH);
2064 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter(SUBMESH_VERTEX);
2065 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter(SUBMESH_EDGE);
2066 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter(SUBMESH_FACE);
2067 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter(SUBMESH_SOLID);
2068 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter(SUBMESH_COMPOUND);
2070 Sel->AddFilter(aHypFilter);
2071 if (Sel->AddIObject(IO) != -1) {
2072 Sel->ClearFilters();
2073 return "Hypothesis";
2076 Sel->ClearFilters();
2077 Sel->AddFilter(anAlgoFilter);
2078 if (Sel->AddIObject(IO) != -1) {
2079 Sel->ClearFilters();
2083 Sel->ClearFilters();
2084 Sel->AddFilter(aMeshFilter);
2085 if (Sel->AddIObject(IO) != -1) {
2086 Sel->ClearFilters();
2090 Sel->ClearFilters();
2091 Sel->AddFilter(aSubMeshFilter);
2092 if (Sel->AddIObject(IO) != -1) {
2093 Sel->ClearFilters();
2097 Sel->ClearFilters();
2098 Sel->AddFilter(aGroupFilter);
2099 if (Sel->AddIObject(IO) != -1) {
2100 Sel->ClearFilters();
2104 Sel->ClearFilters();
2105 Sel->AddFilter(aSubMeshVextexFilter);
2106 if (Sel->AddIObject(IO) != -1) {
2107 Sel->ClearFilters();
2108 return "SubMeshVertex";
2111 Sel->ClearFilters();
2112 Sel->AddFilter(aSubMeshEdgeFilter);
2113 if (Sel->AddIObject(IO) != -1) {
2114 Sel->ClearFilters();
2115 return "SubMeshEdge";
2118 Sel->ClearFilters();
2119 Sel->AddFilter(aSubMeshFaceFilter);
2120 if (Sel->AddIObject(IO) != -1) {
2121 Sel->ClearFilters();
2122 return "SubMeshFace";
2125 Sel->ClearFilters();
2126 Sel->AddFilter(aSubMeshSolidFilter);
2127 if (Sel->AddIObject(IO) != -1) {
2128 Sel->ClearFilters();
2129 return "SubMeshSolid";
2132 Sel->ClearFilters();
2133 Sel->AddFilter(aSubMeshCompoundFilter);
2134 if (Sel->AddIObject(IO) != -1) {
2135 Sel->ClearFilters();
2136 return "SubMeshCompound";
2139 Sel->ClearFilters();
2140 Sel->AddIObject(IO);
2145 static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
2146 return theStudy->GetProperties()->IsLocked();
2149 static int checkLock(const SALOMEDS::Study_var& theStudy) {
2150 if (isStudyLocked(theStudy)) {
2151 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
2152 QObject::tr("WRN_WARNING"),
2153 QObject::tr("WRN_STUDY_LOCKED"),
2154 QObject::tr("BUT_OK") );
2160 //=============================================================================
2164 //=============================================================================
2165 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
2167 SALOMEDS::Study_var aStudy = smeshGUI->myActiveStudy->getStudyDocument(); //Document OCAF de l'etude active
2168 // QAD_Viewer3d* v3d;
2169 OCCViewer_Viewer3d *v3d;
2171 Handle(AIS_InteractiveContext) ic;
2172 vtkRenderer *Renderer;
2173 vtkRenderWindow *RenWin;
2175 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
2176 v3d = ((OCCViewer_ViewFrame *) smeshGUI->myActiveStudy->
2177 getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
2178 ic = v3d->getAISContext();
2180 else if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2181 Renderer = ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2182 getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
2183 RenWin = Renderer->GetRenderWindow();
2186 switch (theCommandID) {
2188 if(checkLock(aStudy)) break;
2189 smeshGUI->OnEditDelete();
2196 if(checkLock(aStudy)) break;
2197 //Import_Document(parent, theCommandID); //NBU
2198 Import_Mesh(parent,theCommandID);
2202 case 122: // EXPORT MED
2206 Export_Mesh(parent, theCommandID);
2210 case 200: // SCALAR BAR
2212 SALOME_Selection *Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2213 if( Sel && Sel->IObjectCount() ) {
2214 Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
2215 if( anIO->hasEntry() ) {
2216 if( SMESH_Actor* anActor = ::FindActorByEntry( anIO->getEntry() ) ) {
2217 anActor->SetControlMode( SMESH_Actor::eNone );
2225 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2226 SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( parent, Sel );
2230 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
2237 smeshGUI->SetViewMode(theCommandID);
2243 if(checkLock(aStudy)) break;
2249 case 301: // DISPLAY
2250 case 302: // DISPLAY ONLY
2252 EDisplaing anAction;
2253 switch(theCommandID){
2254 case 300: anAction = eErase; break;
2255 case 301: anAction = eDisplay; break;
2256 case 302: anAction = eDisplayOnly; break;
2259 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2260 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2261 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2262 for (; It.More(); It.Next()) {
2263 Handle(SALOME_InteractiveObject) IOS = It.Value();
2264 if (IOS->hasEntry()) {
2265 ::UpdateView(anAction,IOS->getEntry());
2269 Sel->ClearIObjects();
2275 if(checkLock(aStudy)) break;
2276 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2277 smeshGUI->EmitSignalDeactivateDialog();
2278 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2279 Sel->ClearIObjects();
2280 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2281 smeshGUI->ViewNodes();
2282 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
2285 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2286 tr("SMESH_WRN_WARNING"),
2287 tr("SMESH_WRN_VIEWER_VTK"),
2288 tr("SMESH_BUT_OK"));
2293 case 2151: // FILTER
2295 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
2297 smeshGUI->EmitSignalDeactivateDialog();
2298 SMESHGUI_FilterDlg *aDlg = new SMESHGUI_FilterDlg( parent, SMESH::EDGE );
2303 case 405: // MOVE NODE
2305 if(checkLock(aStudy)) break;
2306 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2307 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2308 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg(parent, "", Sel);
2312 case 701: // COMPUTE MESH
2314 if(checkLock(aStudy)) break;
2315 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2316 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2317 int nbSel = Sel->IObjectCount();
2322 SMESH::SMESH_Mesh_var aMesh;
2323 SMESH::SMESH_subMesh_var aSubMesh;
2324 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2325 if (IObject->hasEntry()){
2326 SALOMEDS::SObject_var aMeshSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2327 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( aMeshSObj );
2328 if ( aShape->_is_nil() ) {
2332 SALOMEDS::GenericAttribute_var anAttr;
2333 if(!aMeshSObj->_is_nil() && aMeshSObj->FindAttribute(anAttr, "AttributeIOR")){
2334 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2335 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : IOR = "<< anIOR->Value());
2336 CORBA::Object_var anObj;
2338 anObj = _orb->string_to_object(anIOR->Value());
2339 if (CORBA::is_nil(anObj)){
2340 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : nil object");
2342 }catch(CORBA::COMM_FAILURE & ex){
2343 INFOS("SMESHGUI::OnGUIEvent - Compute mesh : exception (1)");
2345 aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
2346 aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
2347 if (!aMesh->_is_nil()){
2348 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMeshSObj);
2349 if (!refShape->_is_nil()) {
2350 if(!smeshGUI->myComponentMesh->IsReadyToCompute(aMesh,refShape)){
2351 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2352 tr("SMESH_WRN_WARNING"),
2353 tr("SMESH_WRN_MISSING_PARAMETERS"),
2354 tr("SMESH_BUT_OK"));
2358 if (smeshGUI->myComponentMesh->Compute(aMesh,refShape))
2359 smeshGUI->myStudyAPI.ModifiedMesh(aMeshSObj,true);
2360 // TO Do : change icon of all submeshes
2362 catch(const SALOME::SALOME_Exception & S_ex){
2363 QtCatchCorbaException(S_ex);
2366 }else if(!aSubMesh->_is_nil()){
2367 aMesh = aSubMesh->GetFather();
2368 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMeshSObj);
2369 if(!refShape->_is_nil()){
2370 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aMesh,refShape);
2372 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2373 tr("SMESH_WRN_WARNING"),
2374 tr("SMESH_WRN_MISSING_PARAMETERS"),
2375 tr("SMESH_BUT_OK"));
2379 if ( smeshGUI->myComponentMesh->Compute(aMesh,refShape) )
2380 smeshGUI->myStudyAPI.ModifiedMesh(aMeshSObj,true);
2381 // TO Do : change icon of all submeshes
2382 }catch(const SALOME::SALOME_Exception & S_ex){
2383 QtCatchCorbaException(S_ex);
2389 CORBA::Long anId = smeshGUI->myStudy->StudyId();
2390 TVisualObjPtr aVisualObj = GetVisualObj(anId,IObject->getEntry());
2391 if(smeshGUI->myAutomaticUpdate && aVisualObj){
2392 aVisualObj->Update();
2393 SMESH_Actor* anActor = ::FindActorByEntry(IObject->getEntry());
2395 anActor = ::CreateActor(smeshGUI->myStudy,IObject->getEntry());
2397 ::DisplayActor(smeshGUI->myActiveStudy->getActiveStudyFrame(),anActor); //apo
2403 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2404 tr("SMESH_WRN_WARNING"),
2405 tr("SMESH_WRN_VIEWER_VTK"),
2406 tr("SMESH_BUT_OK"));
2411 case 702: // ADD SUB MESH
2413 if(checkLock(aStudy)) break;
2414 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2415 smeshGUI->EmitSignalDeactivateDialog();
2416 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2417 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
2420 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2421 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2422 tr("SMESH_BUT_OK"));
2427 case 703: // INIT MESH
2429 if(checkLock(aStudy)) break;
2430 smeshGUI->EmitSignalDeactivateDialog();
2431 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2432 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
2436 case 704: // EDIT Hypothesis
2438 if(checkLock(aStudy)) break;
2439 smeshGUI->EmitSignalDeactivateDialog();
2440 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2441 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2445 case 705: // EDIT Global Hypothesis
2447 if(checkLock(aStudy)) break;
2448 smeshGUI->EmitSignalDeactivateDialog();
2449 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2450 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2454 case 706: // EDIT Local Hypothesis
2456 if(checkLock(aStudy)) break;
2457 smeshGUI->EmitSignalDeactivateDialog();
2458 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2459 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2463 case 406: // ORIENTATION ELEMENTS
2465 if(checkLock(aStudy)) break;
2466 smeshGUI->EmitSignalDeactivateDialog();
2467 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2468 smeshGUI->myDesktop->SetSelectionMode(FaceSelection, true);
2469 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg(parent, "", Sel);
2473 case 407: // DIAGONAL INVERSION
2475 if(checkLock(aStudy)) break;
2476 smeshGUI->EmitSignalDeactivateDialog();
2477 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2478 Sel->ClearIObjects();
2479 smeshGUI->myDesktop->SetSelectionMode(EdgeOfCellSelection, true);
2480 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg(parent, "", Sel);
2484 case 801: // CREATE GROUP
2486 if(checkLock(aStudy)) break;
2487 smeshGUI->EmitSignalDeactivateDialog();
2488 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2489 int nbSel = Sel->IObjectCount();
2491 // check if mesh is selected
2492 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2493 if (IObject->hasEntry()) {
2494 SALOMEDS::SObject_var aMeshSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2495 if (!aMeshSObj->_is_nil()) {
2496 CORBA::Object_var anObj = aMeshSObj->GetObject();
2497 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
2498 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
2499 if (aMesh->_is_nil() && !aSubMesh->_is_nil()) {
2500 aMesh = aSubMesh->GetFather();
2502 if (!aMesh->_is_nil()) {
2503 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aMesh);
2512 case 802: // CONSTRUCT GROUP
2514 if(checkLock(aStudy)) break;
2515 smeshGUI->EmitSignalDeactivateDialog();
2516 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2517 int nbSel = Sel->IObjectCount();
2519 // check if submesh is selected
2520 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2521 if (IObject->hasEntry()) {
2522 SALOMEDS::SObject_var aSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2523 if(!aSObj->_is_nil()) {
2524 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(aSObj->GetObject());
2525 if (!aSubMesh->_is_nil()) {
2527 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2528 // get submesh elements list by types
2529 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2530 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2531 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2532 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2533 // create group for each type o elements
2534 QString aName = IObject->getName();
2535 MESSAGE("SMESHGUI::OnGUIEvent - Construct group on submesh : "<<aName);
2536 MESSAGE(" Number of elements : nodes "<<aNodes->length() << ", edges " << aEdges->length()
2537 << ", faces " << aFaces->length() << ", volumes " << aVolumes->length());
2538 if (aNodes->length() > 0) {
2539 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::NODE, aName);
2540 aGroup->Add(aNodes);
2542 if (aEdges->length() > 0) {
2543 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::EDGE, aName);
2544 aGroup->Add(aEdges);
2546 if (aFaces->length() > 0) {
2547 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::FACE, aName);
2548 aGroup->Add(aFaces);
2550 if (aVolumes->length() > 0) {
2551 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::VOLUME, aName);
2552 aGroup->Add(aVolumes);
2554 smeshGUI->myActiveStudy->updateObjBrowser(true);
2555 }catch(const SALOME::SALOME_Exception & S_ex){
2556 QtCatchCorbaException(S_ex);
2565 case 803: // EDIT GROUP
2567 if(checkLock(aStudy)) break;
2568 smeshGUI->EmitSignalDeactivateDialog();
2569 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2570 int nbSel = Sel->IObjectCount();
2572 // check if group is selected
2573 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2574 if (IObject->hasEntry()) {
2575 SALOMEDS::SObject_var aSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2576 if(!aSObj->_is_nil()) {
2577 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(aSObj->GetObject());
2578 if (!aGroup->_is_nil()) {
2579 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aGroup);
2588 case 804: // Add elements to group
2590 if(checkLock(aStudy)) break;
2591 if (smeshGUI->myState == 800) {
2592 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) smeshGUI->myActiveDialogBox;
2593 if (aDlg) aDlg->onAdd();
2598 case 805: // Remove elements from group
2600 if(checkLock(aStudy)) break;
2601 if (smeshGUI->myState == 800) {
2602 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) smeshGUI->myActiveDialogBox;
2603 if (aDlg) aDlg->onRemove();
2608 case 900: // MESH INFOS
2610 smeshGUI->EmitSignalDeactivateDialog();
2611 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg(parent, "", false);
2615 case 1001: // AUTOMATIC UPDATE PREFERENCES
2617 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001));
2618 if (parent->menuBar()->isItemChecked(1001)) {
2619 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
2620 smeshGUI->myAutomaticUpdate = true;
2623 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
2624 smeshGUI->myAutomaticUpdate = false;
2629 case 1003: // MESH PREFERENCES
2631 smeshGUI->SetDisplaySettings();
2637 SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( parent );
2643 SMESHGUI_Preferences_SelectionDlg* aDlg =
2644 new SMESHGUI_Preferences_SelectionDlg(parent);
2647 QString SCr, SCg, SCb;
2648 SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
2649 SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
2650 SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
2651 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2652 aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2653 else aColor = Qt::cyan;
2654 aDlg->SetColor(1, aColor);
2656 SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
2657 SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
2658 SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
2659 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2660 aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2661 else aColor = Qt::yellow;
2662 aDlg->SetColor(2, aColor);
2664 SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
2665 SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
2666 SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
2667 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2668 aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2669 else aColor = Qt::white;
2670 aDlg->SetColor(3, aColor);
2672 QString SW1 = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
2673 if (SW1.isEmpty()) SW1 = "5";
2674 aDlg->SetWidth(1, SW1.toInt());
2676 QString SW2 = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
2677 if (SW2.isEmpty()) SW2 = "5";
2678 aDlg->SetWidth(2, SW2.toInt());
2680 QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
2681 if (SP1.isEmpty()) SP1 = "0.025";
2682 aDlg->SetPrecision(1, SP1.toDouble());
2684 QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
2685 if (SP2.isEmpty()) SP2 = "0.001";
2686 aDlg->SetPrecision(2, SP2.toDouble());
2689 QColor aPreColor = aDlg->GetColor(1);
2690 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorRed", aPreColor.red());
2691 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorGreen", aPreColor.green());
2692 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorBlue", aPreColor.blue());
2694 QColor aSelColor = aDlg->GetColor(2);
2695 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorRed", aSelColor.red());
2696 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorGreen", aSelColor.green());
2697 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorBlue", aSelColor.blue());
2699 QColor aHiColor = aDlg->GetColor(3);
2700 QAD_CONFIG->addSetting("SMESH:SettingsSelectColorRed", aHiColor.red());
2701 QAD_CONFIG->addSetting("SMESH:SettingsSelectColorGreen", aHiColor.green());
2702 QAD_CONFIG->addSetting("SMESH:SettingsSelectColorBlue", aHiColor.blue());
2704 int aPreWidth = aDlg->GetWidth(1);
2705 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectWidth", aPreWidth);
2706 int aSelWidth = aDlg->GetWidth(2);
2707 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectWidth", aSelWidth);
2709 double aTolNodes = aDlg->GetPrecision(1);
2710 QAD_CONFIG->addSetting("SMESH:SettingsNodeSelectTol", aTolNodes);
2711 double aTolItems = aDlg->GetPrecision(2);
2712 QAD_CONFIG->addSetting("SMESH:SettingsElementsSelectTol", aTolItems);
2714 // update current study settings
2715 ::UpdateSelectionProp();
2717 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
2718 if (studyFrame->getTypeView() == VIEW_VTK) {
2719 VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(studyFrame);
2720 // update VTK viewer properties
2721 VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor();
2723 anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255.,
2724 aSelColor.blue()/255., aSelWidth);
2725 anInteractor->SetSelectionTolerance(aTolNodes, aTolItems);
2726 VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
2728 aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255.,
2729 aPreColor.blue()/255., aPreWidth);
2732 vtkRenderer* aRenderer = aViewFrame->getRenderer();
2733 vtkActorCollection *aCollection = aRenderer->GetActors();
2734 aCollection->InitTraversal();
2735 while(vtkActor *anAct = aCollection->GetNextActor()){
2736 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
2737 anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255.,
2738 aHiColor.blue()/255.);
2739 anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255.,
2740 aPreColor.blue()/255.);
2749 case 1100: // EDIT HYPOTHESIS
2751 if(checkLock(aStudy)) break;
2752 SALOME_Selection *Sel =
2753 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2754 int nbSel = Sel->IObjectCount();
2757 Standard_Boolean res;
2758 SMESH::SMESH_Hypothesis_var Hyp =
2759 smeshGUI->ConvertIOinSMESHHypothesis(Sel->firstIObject(), res);
2761 /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2762 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2763 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2766 char* sName = Hyp->GetName();
2767 SMESHGUI_GenericHypothesisCreator* aCreator = smeshGUI->GetHypothesisCreator(sName);
2770 aCreator->EditHypothesis(Hyp);
2781 case 1101: // RENAME
2783 if(checkLock(aStudy)) break;
2784 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2785 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2786 for (; It.More(); It.Next()) {
2787 Handle(SALOME_InteractiveObject) IObject = It.Value();
2789 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2790 SALOMEDS::GenericAttribute_var anAttr;
2791 SALOMEDS::AttributeName_var aName;
2792 if (!obj->_is_nil()) {
2793 if (obj->FindAttribute(anAttr, "AttributeName")) {
2794 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2795 QString newName = QString(aName->Value());
2796 newName = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), newName);
2797 if (!newName.isEmpty()) {
2798 smeshGUI->myActiveStudy->renameIObject(IObject, newName);
2806 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2808 if(checkLock(aStudy)) break;
2810 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2811 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2812 for (int i = 0; It.More(); It.Next(), i++) {
2813 Handle(SALOME_InteractiveObject) IObject = It.Value();
2814 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh(IObject);
2816 Sel->ClearIObjects();
2817 smeshGUI->myActiveStudy->updateObjBrowser(true);
2821 case 401: // GEOM::EDGE
2823 if(checkLock(aStudy)) break;
2824 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2825 smeshGUI->EmitSignalDeactivateDialog();
2826 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2827 Sel->ClearIObjects();
2828 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2829 smeshGUI->ViewNodes();
2830 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg(parent, "", Sel);
2833 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2834 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2835 tr("SMESH_BUT_OK"));
2839 case 4021: // TRIANGLE
2841 if(checkLock(aStudy)) break;
2842 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2843 smeshGUI->EmitSignalDeactivateDialog();
2844 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2845 Sel->ClearIObjects();
2846 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2847 smeshGUI->ViewNodes();
2848 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg(parent, "", Sel, 3);
2851 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2852 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2853 tr("SMESH_BUT_OK"));
2859 if(checkLock(aStudy)) break;
2860 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2861 smeshGUI->EmitSignalDeactivateDialog();
2862 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2863 Sel->ClearIObjects();
2864 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2865 smeshGUI->ViewNodes();
2866 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg(parent, "", Sel, 4);
2870 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2871 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2872 tr("SMESH_BUT_OK"));
2878 if(checkLock(aStudy)) break;
2879 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2880 smeshGUI->EmitSignalDeactivateDialog();
2881 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2882 Sel->ClearIObjects();
2883 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2884 smeshGUI->ViewNodes();
2885 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg(parent, "", Sel, 4);
2888 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2889 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2890 tr("SMESH_BUT_OK"));
2896 if(checkLock(aStudy)) break;
2897 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2898 smeshGUI->EmitSignalDeactivateDialog();
2899 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2900 Sel->ClearIObjects();
2901 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2902 smeshGUI->ViewNodes();
2903 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg(parent, "", Sel, 8);
2906 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2907 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2908 tr("SMESH_BUT_OK"));
2913 case 4041: // REMOVES NODES
2915 if(checkLock(aStudy)) break;
2916 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2917 smeshGUI->EmitSignalDeactivateDialog();
2918 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2919 Sel->ClearIObjects();
2920 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2921 smeshGUI->ViewNodes();
2922 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
2925 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2926 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2927 tr("SMESH_BUT_OK"));
2931 case 4042: // REMOVES ELEMENTS
2933 if(checkLock(aStudy)) break;
2934 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2935 smeshGUI->EmitSignalDeactivateDialog();
2936 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2937 Sel->ClearIObjects();
2938 smeshGUI->myDesktop->SetSelectionMode(CellSelection, true);
2939 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
2943 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2944 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2945 tr("SMESH_BUT_OK"));
2950 case 5000: // HYPOTHESIS
2952 if(checkLock(aStudy)) break;
2953 smeshGUI->EmitSignalDeactivateDialog();
2954 SMESHGUI_CreateHypothesesDlg *aDlg =
2955 new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false);
2960 if(checkLock(aStudy)) break;
2961 smeshGUI->EmitSignalDeactivateDialog();
2962 SMESHGUI_CreateHypothesesDlg *aDlg =
2963 new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true);
2967 case 6016: // CONTROLS
2976 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
2977 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2978 if ( Sel->IObjectCount() == 1 && Sel->firstIObject()->hasEntry() ) {
2979 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( Sel->firstIObject()->getEntry() );
2980 if ( !SO->_is_nil() ) {
2981 CORBA::Object_var aObject = SO->GetObject();
2982 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( aObject );
2983 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2984 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aObject );
2985 if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2986 smeshGUI->Control( theCommandID );
2991 QAD_MessageBox::warn1(smeshGUI->GetDesktop(),
2992 tr( "SMESH_WRN_WARNING" ),
2993 tr( "SMESH_BAD_SELECTION" ),
2994 tr( "SMESH_BUT_OK" ) );
2998 QAD_MessageBox::warn1(smeshGUI->GetDesktop(),
2999 tr( "SMESH_WRN_WARNING" ),
3000 tr( "NOT_A_VTK_VIEWER" ),
3001 tr( "SMESH_BUT_OK" ) );
3006 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3007 if (Sel->IObjectCount() == 1) {
3008 Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
3009 if(anIObject->hasEntry())
3010 if(SMESH_Actor *anActor = ::FindActorByEntry(anIObject->getEntry())){
3011 anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3018 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3019 if (Sel->IObjectCount() == 1) {
3020 Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
3021 if(anIObject->hasEntry())
3022 if(SMESH_Actor *anActor = ::FindActorByEntry(anIObject->getEntry())){
3023 anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3028 case 10001: // DISPLAY MODE PREFERENCE
3031 parent->menuBar()->setItemChecked(10001, true);
3032 parent->menuBar()->setItemChecked(10002, false);
3033 parent->menuBar()->setItemChecked(10004, false);
3034 parent->menuBar()->setItemEnabled(10003, true);
3035 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
3040 parent->menuBar()->setItemChecked(10002, true);
3041 parent->menuBar()->setItemChecked(10001, false);
3042 parent->menuBar()->setItemChecked(10004, false);
3043 parent->menuBar()->setItemEnabled(10003, true);
3044 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3049 parent->menuBar()->setItemChecked(10003,!parent->menuBar()->isItemChecked(10003));
3050 QAD_CONFIG->addSetting("SMESH:Shrink", parent->menuBar()->isItemChecked(10003) ? "yes" : "no");
3055 parent->menuBar()->setItemChecked(10001, false);
3056 parent->menuBar()->setItemChecked(10004, true);
3057 parent->menuBar()->setItemChecked(10002, false);
3058 parent->menuBar()->setItemEnabled(10003, false);
3059 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Nodes");
3065 smeshGUI->myActiveStudy->updateObjBrowser(true);
3069 //=============================================================================
3070 /*! function : GetMeshesUsingAlgoOrHypothesis()
3071 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
3072 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
3074 //=============================================================================
3075 SALOMEDS::Study::ListOfSObject *
3076 SMESHGUI::GetMeshesUsingAlgoOrHypothesis(SMESH::
3077 SMESH_Hypothesis_ptr AlgoOrHyp)
3079 SALOMEDS::Study::ListOfSObject_var listSOmesh =
3080 new SALOMEDS::Study::ListOfSObject;
3081 listSOmesh->length(0);
3082 unsigned int index = 0;
3083 if (!AlgoOrHyp->_is_nil()) {
3084 SALOMEDS::SObject_var SO_Hypothesis =
3085 smeshGUI->GetStudyAPI().FindObject(AlgoOrHyp);
3086 if (!SO_Hypothesis->_is_nil()) {
3087 SALOMEDS::Study::ListOfSObject_var listSO =
3088 smeshGUI->myStudy->FindDependances(SO_Hypothesis);
3089 MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO->length());
3090 for (unsigned int i = 0; i < listSO->length(); i++) {
3091 SALOMEDS::SObject_ptr SO = listSO[i];
3092 if (!SO->_is_nil()) {
3093 SALOMEDS::SObject_var aFather = SO->GetFather();
3094 if (!aFather->_is_nil()) {
3095 SALOMEDS::SObject_var SOfatherFather = aFather->GetFather();
3096 if (!SOfatherFather->_is_nil()) {
3097 MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
3099 listSOmesh->length(index);
3100 listSOmesh[index - 1] = SOfatherFather;
3107 MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
3108 return listSOmesh._retn();
3111 //=============================================================================
3115 //=============================================================================
3116 void SMESHGUI::Import_Mesh(QAD_Desktop * parent, int theCommandID){
3120 if(theCommandID == 113){
3121 filter = tr("MED files (*.med)");
3122 }else if (theCommandID == 112){
3123 filter = tr("IDEAS files (*.unv)");
3124 }else if (theCommandID == 111){
3125 filter = tr("DAT files (*.dat)");
3127 QString filename = QAD_FileDlg::getFileName(parent,
3132 if(!filename.isEmpty()){
3134 SMESH::mesh_array_var aMeshes;
3136 SMESH::DriverMED_ReadStatus res;
3137 aMeshes = smeshGUI->myComponentMesh->CreateMeshesFromMED(filename.latin1(),
3139 if ( res > SMESH::DRS_OK ) {
3141 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3142 tr("SMESH_WRN_WARNING"),
3143 tr(QString("SMESH_DRS_%1").arg(res)),
3144 tr("SMESH_BUT_OK"));
3149 catch (const SALOME::SALOME_Exception& S_ex)
3152 QtCatchCorbaException(S_ex);
3155 for ( int i = 0, n = aMeshes->length(); i < n; i++ ) {
3156 SALOMEDS::SObject_var aMeshSO = smeshGUI->myStudyAPI.FindObject( aMeshes[i] );
3157 if ( !aMeshSO->_is_nil() ) {
3158 SALOMEDS::StudyBuilder_var aBuilder = smeshGUI->myStudy->NewBuilder();
3159 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow( aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ) );
3160 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3166 //=============================================================================
3170 //=============================================================================
3171 void SMESHGUI::Export_Mesh(QAD_Desktop * parent, int theCommandID)
3173 SALOME_Selection *Sel =
3174 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3175 int nbSel = Sel->IObjectCount();
3178 Standard_Boolean res;
3179 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3180 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(IObject, res);
3181 if ( res && ( nbSel == 1 || theCommandID == 122 ) ) {// MED export supports multiple meshes
3182 QString aFilter, aTitle = tr("Export mesh");
3183 switch ( theCommandID ) {
3185 aFilter = tr("MED files (*.med)");
3188 aFilter = tr("DAT files (*.dat)");
3191 aFilter = tr("IDEAS files (*.unv)");
3197 QString filename = QAD_FileDlg::getFileName(parent, "", aFilter, aTitle, false);
3199 if ( !filename.isEmpty() ) {
3200 // Check whether the file already exists and delete it if yes
3201 QFile aFile( filename );
3202 if ( aFile.exists() )
3206 for ( SALOME_ListIteratorOfListIO it( Sel->StoredIObjects() ); it.More(); it.Next() ) {
3207 aMesh = smeshGUI->ConvertIOinMesh( it.Value(), res );
3209 switch ( theCommandID ) {
3211 aMesh->ExportMED( filename.latin1(), true ); // currently, automatic groups are always created
3214 aMesh->ExportDAT( filename.latin1() );
3217 aMesh->ExportUNV( filename.latin1() );
3228 //=============================================================================
3232 //=============================================================================
3233 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3234 QAD_StudyFrame * studyFrame)
3239 //=============================================================================
3243 //=============================================================================
3244 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3245 QAD_StudyFrame * studyFrame)
3250 //=============================================================================
3254 //=============================================================================
3255 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3256 QAD_StudyFrame * studyFrame)
3261 //=============================================================================
3265 //=============================================================================
3266 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3268 MESSAGE("SMESHGUI::SetSettings.");
3269 SMESHGUI::GetOrCreateSMESHGUI(parent);
3272 QString DisplayMode = "Shading";
3273 if ( QAD_CONFIG->hasSetting("SMESH:DisplayMode") )
3274 DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3276 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3278 bool Shrink = false;
3279 if ( QAD_CONFIG->hasSetting("SMESH:Shrink") )
3280 Shrink = QAD_CONFIG->getSetting("SMESH:Shrink") == "yes";
3282 if (DisplayMode == "Wireframe") {
3284 parent->menuBar()->setItemChecked(10004, false);
3285 parent->menuBar()->setItemChecked(10002, false);
3286 parent->menuBar()->setItemChecked(10001, true);
3287 parent->menuBar()->setItemEnabled(10003, true);
3289 else if (DisplayMode == "Nodes") {
3291 parent->menuBar()->setItemChecked(10004, true);
3292 parent->menuBar()->setItemChecked(10002, false);
3293 parent->menuBar()->setItemChecked(10001, false);
3294 parent->menuBar()->setItemEnabled(10003, false);
3297 // default is shading
3298 parent->menuBar()->setItemChecked(10004, false);
3299 parent->menuBar()->setItemChecked(10002, true);
3300 parent->menuBar()->setItemChecked(10001, false);
3301 parent->menuBar()->setItemEnabled(10003, true);
3303 parent->menuBar()->setItemChecked(10003, Shrink);
3305 /* Automatic Update */
3306 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3307 if (AutoUpdate.compare("true") == 0) {
3308 parent->menuBar()->setItemChecked(1001, true);
3309 smeshGUI->myAutomaticUpdate = true;
3312 parent->menuBar()->setItemChecked(1001, false);
3313 smeshGUI->myAutomaticUpdate = false;
3317 ::UpdateSelectionProp();
3320 parent->menuBar()->setItemEnabled(111, false); // IMPORT DAT
3321 parent->menuBar()->setItemEnabled(112, false); // IMPORT UNV
3326 //=============================================================================
3330 //=============================================================================
3331 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject)
3333 // NRI : Temporary added
3334 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3335 // theObject = "NothingSelected";
3336 // theContext = "NothingSelected";
3340 SALOME_Selection *Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3341 int nbSel = Sel->IObjectCount();
3344 theObject = "NothingSelected";
3345 theContext = "NothingSelected";
3348 if ( smeshGUI->myState == 800 && Sel->HasIndex( Sel->firstIObject() ) )
3349 theObject = "Elements";
3351 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3355 theObject = smeshGUI->CheckHomogeneousSelection();
3360 //=============================================================================
3364 //=============================================================================
3365 bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
3366 const QString& theParent, const QString& theObject)
3368 // get active study frame
3369 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3371 // get parent component which selected object(s) belongs to
3372 QString parentComp = ( (SALOMEGUI_Desktop*)parent )->getComponentFromSelection();
3375 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3376 int nbSel = Sel->IObjectCount();
3381 else if ( nbSel == 1 ) {
3382 if ( parentComp != parent->getActiveComponent() ) {
3383 // object not belongs to SMESH module - remove all commands except common Display/Erase...
3385 int id = popup->idAt( 0 );
3386 if ( id <= QAD_TopLabel_Popup_ID )
3387 popup->removeItemAt( 0 );
3393 // get selected interactive object
3394 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3395 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3396 // find popup menu's TopLabel item
3397 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
3398 if ( topItem >= 0 ) {
3399 if ( theParent == "Viewer" ) {
3400 // set bold font for popup menu's TopLabel item (Viewer popup)
3401 QFont fnt = QApplication::font(); fnt.setBold( TRUE );
3402 popup->removeItem( QAD_TopLabel_Popup_ID );
3403 popup->insertItem( new CustomItem( QString( IObject->getName() ), fnt ), QAD_TopLabel_Popup_ID, topItem );
3405 else if ( theParent == "ObjectBrowser" ) {
3406 // remove popup menu's TopLabel item (Object Browser popup)
3407 popup->removeItem( QAD_TopLabel_Popup_ID );
3411 // remove "Display only" command for component object
3412 if ( theObject.compare( "Component" ) == 0 ) {
3413 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3415 else if ( theObject == "Hypothesis" || theObject == "Algorithm" ) {
3416 // remove Display/Erase commands
3417 popup->removeItem( QAD_Display_Popup_ID );
3418 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3419 popup->removeItem( QAD_Erase_Popup_ID );
3420 // remove "Unassign ..." command if hyp/algo is not assigned
3421 if ( SO->_is_nil() || !IObject->hasReference()/* !IsReferencedObject( SO ) */)
3422 popup->removeItem( 1102 );
3424 else if ( theObject == "Mesh" || theObject == "SubMesh" || theObject == "Group" ) {
3426 GEOM::GEOM_Shape_var aShape = GetSMESHGUI()->GetStudyAPI().GetShapeOnMeshOrSubMesh( SO );
3427 if ( aShape->_is_nil() ) {
3429 popup->removeItem( 701 ); // Compute
3430 popup->removeItem( 705 ); // Edit hypothesis
3431 popup->removeItem( 706 ); // ...
3433 SMESH_Actor* ac = ::FindActorByEntry(IObject->getEntry());
3434 // if object has actor
3435 if ( ac && studyFrame->getTypeView() == VIEW_VTK ) {
3436 VTKViewer_RenderWindowInteractor* myRenderInter =
3437 ( ( VTKViewer_ViewFrame* ) studyFrame->getRightFrame()->getViewFrame() )->getRWInteractor();
3438 if ( myRenderInter->isVisible( IObject ) ) {
3439 popup->removeItem( QAD_Display_Popup_ID );
3440 popup->setItemChecked( 9010, ac->GetPointsLabeled() ); // Numbering / Display Nodes #
3441 popup->setItemChecked( 9011, ac->GetCellsLabeled() ); // Numbering / Display Elements #
3442 TVisualObjPtr aVisualObj = ac->GetObject();
3443 int aNbEdges = aVisualObj->GetNbEntities(SMESH::EDGE);
3444 int aNbFaces = aVisualObj->GetNbEntities(SMESH::FACE);
3445 int aNbVolumes = aVisualObj->GetNbEntities(SMESH::VOLUME);
3446 QMenuItem* mi = popup->findItem( 1131 );
3447 if ( mi && mi->popup() ) {
3448 int prType = ac->GetRepresentation();
3449 // Display Mode / Wireframe
3450 if(!aNbFaces && !aNbVolumes && !aNbEdges){
3451 mi->popup()->removeItem( 211 );
3453 mi->popup()->setItemChecked( 211, prType == SMESH_Actor::eEdge );
3455 // Display Mode / Shading
3456 if(!aNbFaces && !aNbVolumes){
3457 mi->popup()->removeItem( 212 );
3459 mi->popup()->setItemChecked( 212, prType == SMESH_Actor::eSurface );
3461 // Display Mode / Points
3462 mi->popup()->setItemChecked( 215, prType == SMESH_Actor::ePoint );
3463 // Display Mode / Shrink
3464 bool isShrunk = ac->IsShrunk();
3465 bool isShrunkable = ac->IsShrunkable();
3466 mi->popup()->setItemChecked( 213, isShrunk );
3467 mi->popup()->setItemEnabled( 213, prType != SMESH_Actor::ePoint && isShrunkable);
3470 mi = popup->findItem( 2000 );
3471 if ( mi && mi->popup() ) {
3472 SMESH_Actor::eControl cMode = ac->GetControlMode();
3474 case SMESH_Actor::eLengthEdges:
3475 mi->popup()->setItemChecked( 6001, true ); break;
3476 case SMESH_Actor::eFreeBorders:
3477 mi->popup()->setItemChecked( 6003, true );
3478 mi->popup()->removeItem( 201 );
3480 case SMESH_Actor::eMultiConnection:
3481 mi->popup()->setItemChecked( 6004, true ); break;
3482 case SMESH_Actor::eArea:
3483 mi->popup()->setItemChecked( 6011, true ); break;
3484 case SMESH_Actor::eTaper:
3485 mi->popup()->setItemChecked( 6012, true ); break;
3486 case SMESH_Actor::eAspectRatio:
3487 mi->popup()->setItemChecked( 6013, true ); break;
3488 case SMESH_Actor::eMinimumAngle:
3489 mi->popup()->setItemChecked( 6014, true ); break;
3490 case SMESH_Actor::eWarping:
3491 mi->popup()->setItemChecked( 6015, true ); break;
3492 case SMESH_Actor::eSkew:
3493 mi->popup()->setItemChecked( 6016, true ); break;
3494 case SMESH_Actor::eNone:
3496 mi->popup()->removeItem( 200 );
3497 mi->popup()->removeItem( 201 );
3500 TVisualObjPtr aVisualObj = ac->GetObject();
3501 SMESH::ElementType aType;
3503 mi->popup()->removeItem( 6001 );
3504 mi->popup()->removeItem( 6003 );
3505 mi->popup()->removeItem( 6004 );
3508 mi->popup()->removeItem( 6011 );
3509 mi->popup()->removeItem( 6012 );
3510 mi->popup()->removeItem( 6013 );
3511 mi->popup()->removeItem( 6014 );
3512 mi->popup()->removeItem( 6015 );
3513 mi->popup()->removeItem( 6016 );
3515 if(!aNbFaces && !aNbEdges)
3516 popup->removeItem( 2000 ); // Scalar Bar
3520 popup->removeItem( QAD_Erase_Popup_ID );
3521 popup->removeItem( 114 ); // Numbering popup menu
3522 popup->removeItem( 1131 ); // Display mode
3523 popup->removeItem( 1132 ); // Color / size
3524 popup->removeItem( 1133 ); // Transparency
3525 popup->removeItem( 2000 ); // Scalar Bar
3529 // object doesn't have actor
3530 CORBA::Object_var anObject = SO->GetObject();
3531 bool bDisplay = false;
3532 if ( !CORBA::is_nil( anObject ) ) {
3533 SMESH::SMESH_Mesh_var aMeshObj = SMESH::SMESH_Mesh::_narrow( anObject );
3534 if ( !aMeshObj->_is_nil() && ( aMeshObj->NbNodes() > 0 || aMeshObj->NbFaces() > 0 || aMeshObj->NbVolumes() > 0 ) )
3536 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObject );
3537 if ( !aSubMeshObj->_is_nil() && ( aSubMeshObj->GetNumberOfNodes() > 0 || aSubMeshObj->GetNumberOfElements() > 0 ) )
3539 SMESH::SMESH_Group_var aGroupObj = SMESH::SMESH_Group::_narrow( anObject );
3540 if ( !aGroupObj->_is_nil() && aGroupObj->Size() > 0 )
3544 popup->removeItem( QAD_Display_Popup_ID );
3545 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3547 popup->removeItem( QAD_Erase_Popup_ID );
3548 popup->removeItem( 114 ); // Numbering popup menu
3549 popup->removeItem( 1131 ); // Display mode
3550 popup->removeItem( 1132 ); // Color / size
3551 popup->removeItem( 1133 ); // Transparency
3552 popup->removeItem( 2000 ); // Scalar Bar
3556 // another SMESH object
3557 popup->removeItem( QAD_Display_Popup_ID );
3558 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3559 popup->removeItem( QAD_Erase_Popup_ID );
3564 // multiple selection
3565 if ( parentComp != parent->getActiveComponent() ) {
3566 // object not belongs to SMESH module - remove all commands except common Display/Erase...
3568 int id = popup->idAt( 0 );
3569 if ( id <= QAD_TopLabel_Popup_ID )
3570 popup->removeItemAt( 0 );
3574 if ( parentComp.isNull() ) {
3575 // objects from different components are selected
3576 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3577 popup->removeItem( QAD_Display_Popup_ID );
3578 popup->removeItem( QAD_Erase_Popup_ID );
3582 QString type = smeshGUI->CheckHomogeneousSelection();
3583 if ( type != "Heterogeneous Selection" ) {
3584 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
3585 if ( topItem >= 0 ) {
3586 // set bold font for popup menu's TopLabel item
3587 QFont fnt = QApplication::font(); fnt.setBold( TRUE );
3588 popup->removeItem( QAD_TopLabel_Popup_ID );
3589 popup->insertItem( new CustomItem( QString("%1 ").arg( nbSel ) + type + "(s) ", fnt ), QAD_TopLabel_Popup_ID, topItem );
3597 //=============================================================================
3598 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3599 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3601 //=============================================================================
3602 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
3604 if(theIO->hasEntry()){
3605 QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
3606 QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
3607 ::UpdateView(aStudyFrame,eDisplay,theIO->getEntry());
3611 //=============================================================================
3615 //=============================================================================
3616 void SMESHGUI::setOrb()
3620 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
3621 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
3625 INFOS("internal error : orb not found");
3628 ASSERT(!CORBA::is_nil(_orb));
3631 //=============================================================================
3635 //=============================================================================
3636 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr theMesh){}
3638 //=============================================================================
3642 //=============================================================================
3643 void SMESHGUI::Dump(SMESH_Actor * Mactor)
3645 vtkUnstructuredGrid *ugrid = Mactor->GetUnstructuredGrid();
3646 vtkPoints *Pts = ugrid->GetPoints();
3647 int nbPts = Pts->GetNumberOfPoints();
3648 int nbCells = ugrid->GetNumberOfCells();
3652 In = fopen("/tmp/dumpMesh", "w+");
3653 fprintf(In, "%d %d\n", nbPts, nbCells);
3654 for (int i = 0; i < nbPts; i++)
3656 float *p = ugrid->GetPoint(i);
3657 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
3660 for (int i = 0; i < nbCells; i++)
3662 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
3663 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3664 for (j = 0; j < Id->GetNumberOfIds(); j++)
3666 fprintf(In, " %d", Id->GetId(j));
3673 //=============================================================================
3677 //=============================================================================
3678 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr theMesh,
3679 const TColStd_MapOfInteger & MapIndex)
3683 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
3684 CORBA::String_var anEntry = aSobj->GetID();
3685 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
3686 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3687 anArrayOfIdeces->length(MapIndex.Extent());
3688 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
3689 for(int i = 0; ite.More(); ite.Next(), i++){
3690 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
3692 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
3693 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3694 if(myAutomaticUpdate){
3695 CORBA::Long anId = smeshGUI->myStudy->StudyId();
3696 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
3697 aVisualObj->Update(true);
3701 }catch(SALOME::SALOME_Exception& exc) {
3702 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
3703 }catch(const std::exception& exc){
3704 INFOS("Follow exception was cought:\n\t"<<exc.what());
3706 INFOS("Unknown exception was cought !!!");
3710 //=============================================================================
3714 //=============================================================================
3715 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr theMesh,
3716 const TColStd_MapOfInteger & MapIndex)
3720 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
3721 CORBA::String_var anEntry = aSobj->GetID();
3722 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
3723 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3724 anArrayOfIdeces->length(MapIndex.Extent());
3725 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
3726 for(int i = 0; ite.More(); ite.Next(), i++){
3727 anArrayOfIdeces[i] = anActor->GetElemObjId(ite.Key());
3729 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
3730 aMeshEditor->RemoveElements(anArrayOfIdeces);
3731 if(myAutomaticUpdate){
3732 CORBA::Long anId = smeshGUI->myStudy->StudyId();
3733 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
3734 aVisualObj->Update(true);
3738 }catch(SALOME::SALOME_Exception& exc) {
3739 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
3740 }catch(const std::exception& exc){
3741 INFOS("Follow exception was cought:\n\t"<<exc.what());
3743 INFOS("Unknown exception was cought !!!");
3747 //=============================================================================
3751 //=============================================================================
3752 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
3753 const TColStd_MapOfInteger & MapIndex)
3755 MESSAGE("OrientationElements - not implemeted yet!");
3758 //=============================================================================
3762 //=============================================================================
3763 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
3764 const TColStd_MapOfInteger & MapIndex)
3766 MESSAGE("OrientationElements - not implemeted yet!");
3769 //=====================================================================================
3771 //=====================================================================================
3772 void SMESHGUI::SupportedViewType(int *buffer, int bufferSize)
3774 if (!buffer || !bufferSize)
3776 buffer[0] = (int)VIEW_VTK;
3779 void SMESHGUI::Deactivate()
3781 if ( SMESHGUI::GetSMESHGUI() ) {
3782 SMESHGUI::GetSMESHGUI()->EmitSignalCloseAllDialogs();
3787 //=============================================================================
3791 //=============================================================================
3792 void SMESHGUI::SetPickable(SMESH_Actor* theActor){
3793 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
3794 int anIsAllPickable = (theActor == NULL);
3795 vtkRenderer *aRenderer = aViewFrame->getRenderer();
3796 vtkActorCollection *aCollection = aRenderer->GetActors();
3797 aCollection->InitTraversal();
3798 while(vtkActor *anAct = aCollection->GetNextActor()){
3799 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
3800 if(anActor->GetVisibility()){
3801 anActor->SetPickable(anIsAllPickable);
3806 theActor->SetPickable(!anIsAllPickable);
3807 RepaintCurrentView();
3812 void SMESHGUI::ViewNodes(){
3813 EraseSimulationActors();
3814 ::SetPointRepresentation(true);
3817 //=============================================================================
3821 //=============================================================================
3822 void SMESHGUI::Control( int theCommandID ){
3823 SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3825 Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
3828 SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
3829 if(SMESH_Actor *anActor = ::FindActorByEntry(anIO->getEntry())){
3830 switch ( theCommandID ){
3832 aTitle = tr( "LENGTH_EDGES" );
3833 aControl = SMESH_Actor::eLengthEdges;
3836 aTitle = tr( "FREE_BORDERS" );
3837 aControl = SMESH_Actor::eFreeBorders;
3840 aTitle = tr( "MULTI_BORDERS" );
3841 aControl = SMESH_Actor::eMultiConnection;
3844 aTitle = tr( "AREA_ELEMENTS" );
3845 aControl = SMESH_Actor::eArea;
3848 aTitle = tr( "TAPER_ELEMENTS" );
3849 aControl = SMESH_Actor::eTaper;
3852 aTitle = tr( "ASPECTRATIO_ELEMENTS" );
3853 aControl = SMESH_Actor::eAspectRatio;
3856 aTitle = tr( "MINIMUMANGLE_ELEMENTS" );
3857 aControl = SMESH_Actor::eMinimumAngle;
3860 aTitle = tr( "WARP_ELEMENTS" );
3861 aControl = SMESH_Actor::eWarping;
3864 aTitle = tr( "SKEW_ELEMENTS" );
3865 aControl = SMESH_Actor::eSkew;
3868 anActor->SetControlMode(aControl);
3869 anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
3875 //=============================================================================
3879 //=============================================================================
3880 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
3885 QString Orientation,
3891 if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
3892 theScalarBar->BoldOn();
3894 theScalarBar->BoldOff();
3896 if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
3897 theScalarBar->ItalicOn();
3899 theScalarBar->ItalicOff();
3901 if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
3902 theScalarBar->ShadowOn();
3904 theScalarBar->ShadowOff();
3906 if (FontFamily.compare("Arial") == 0)
3907 theScalarBar->SetFontFamilyToArial();
3908 else if (FontFamily.compare("Courier") == 0)
3909 theScalarBar->SetFontFamilyToCourier();
3910 else if (FontFamily.compare("Times") == 0)
3911 theScalarBar->SetFontFamilyToTimes();
3913 theScalarBar->SetFontFamilyToArial();
3915 if (Orientation.isNull() || Orientation.isEmpty() ||
3916 (Orientation.compare("Vertical") == 0))
3917 theScalarBar->SetOrientationToVertical();
3919 theScalarBar->SetOrientationToHorizontal();
3921 theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
3922 theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
3924 theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
3925 theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
3928 //=============================================================================
3932 //=============================================================================
3933 void SMESHGUI::SetDisplaySettings()
3935 EmitSignalDeactivateDialog();
3936 SMESHGUI_Preferences_ColorDlg *aDlg =
3937 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
3940 QString SCr, SCg, SCb;
3941 SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
3942 SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
3943 SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
3944 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
3945 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
3946 else color = QColor(0, 170, 255);
3947 aDlg->SetColor(1, color);
3949 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
3950 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
3951 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
3952 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
3953 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
3954 else color = QColor(0, 170, 255);
3955 aDlg->SetColor(2, color);
3957 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
3958 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
3959 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
3960 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
3961 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
3962 else color = Qt::red;
3963 aDlg->SetColor(3, color);
3965 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
3966 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
3967 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
3968 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
3969 color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
3970 else color = Qt::blue;
3971 aDlg->SetColor(4, color);
3973 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
3974 if (intValue.isEmpty()) intValue = "1";
3975 aDlg->SetIntValue(1, intValue.toInt());
3976 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
3977 if (intValue.isEmpty()) intValue = "3";
3978 aDlg->SetIntValue(2, intValue.toInt());
3979 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
3980 if (intValue.isEmpty()) intValue = "75";
3981 aDlg->SetIntValue(3, intValue.toInt());
3984 QColor colorFill = aDlg->GetColor(1);
3985 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
3986 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
3987 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
3989 QColor colorOutline = aDlg->GetColor(2);
3990 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
3991 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
3992 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
3994 QColor colorNode = aDlg->GetColor(3);
3995 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
3996 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
3997 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
3999 QColor colorBackFace = aDlg->GetColor(4);
4000 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4001 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4002 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4004 int width = aDlg->GetIntValue(1);
4005 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4007 int nodes_size = aDlg->GetIntValue(2);
4008 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4010 int shrink_coeff = aDlg->GetIntValue(3);
4011 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4017 //=======================================================================
4018 // function : Parameter()
4019 // purpose : return a parameter (double) from a dialog box
4021 // aValue : is a double used as a default value displayed
4022 // aLabel : is the title for aValue1
4023 // aTitle : is the main title
4024 // bottom : maximum value to be entered
4025 // top : minimum value to be entered
4026 // decimals : number of decimals
4027 //=======================================================================
4028 double SMESHGUI::Parameter(Standard_Boolean & res,
4029 const double aValue,
4032 const double bottom, const double top, const int decimals)
4034 SMESHGUI_aParameterDlg *Dialog =
4035 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
4038 bottom, top, decimals,
4040 Dialog->setValue(aValue);
4042 res = (Dialog->exec() == QDialog::Accepted);
4044 X = Dialog->getDblValue();
4048 //=======================================================================
4049 // function : Parameter()
4050 // purpose : return a parameter (int) from a dialog box
4052 // aValue : is a int used as a default value displayed
4053 // aLabel : is the title for aValue1
4054 // aTitle : is the main title
4055 // bottom : maximum value to be entered
4056 // top : minimum value to be entered
4057 //=======================================================================
4058 int SMESHGUI::Parameter(Standard_Boolean & res,
4060 const char *aLabel, const char *aTitle, const int bottom, const int top)
4062 SMESHGUI_aParameterDlg *Dialog =
4063 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
4068 Dialog->setValue(aValue);
4070 res = (Dialog->exec() == QDialog::Accepted);
4072 X = Dialog->getIntValue();
4076 //=============================================================================
4080 //=============================================================================
4081 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility){}
4083 //=============================================================================
4087 //=============================================================================
4088 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh){}
4090 //=============================================================================
4094 //=============================================================================
4095 void SMESHGUI::Update(){
4096 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
4097 SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
4098 if(Sel->IObjectCount() == 0){
4099 vtkRenderer* aRenderer = aViewFrame->getRenderer();
4100 vtkActorCollection *aCollection = aRenderer->GetActors();
4101 aCollection->InitTraversal();
4102 while(vtkActor *anAct = aCollection->GetNextActor()){
4103 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
4104 if(anActor->hasIO()){
4105 Update(anActor->getIO());
4110 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4111 for(; It.More(); It.Next()){
4112 Handle(SALOME_InteractiveObject) IO = It.Value();
4116 ::RepaintCurrentView();
4120 //=============================================================================
4124 //=============================================================================
4125 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & theIO){
4126 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4127 TVisualObjPtr aVisualObj = ::GetVisualObj(anId,theIO->getEntry());
4128 aVisualObj->Update();
4129 ::UpdateView(eDisplay,theIO->getEntry());
4132 //=============================================================================
4136 //=============================================================================
4137 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
4139 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4142 mySimulationActors = vtkActorCollection::New();
4143 vtkRenderer *theRenderer =
4144 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4145 getRightFrame()->getViewFrame())->getRenderer();
4147 vtkUnstructuredGrid *ugrid =
4148 vtkUnstructuredGrid::SafeDownCast(Mactor->GetUnstructuredGrid());
4149 vtkIdList *IdCells = vtkIdList::New();
4150 ugrid->GetPointCells(idnode, IdCells);
4152 vtkPoints *Pts = vtkPoints::New();
4153 Pts = ugrid->GetPoints();
4155 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
4156 ugridSimulation->SetPoints(Pts);
4157 vtkIdList *IdPts = vtkIdList::New();
4158 for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
4160 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
4161 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
4165 vtkProperty *prop = vtkProperty::New();
4166 prop->SetColor(1., 0., 0.);
4167 prop->SetRepresentationToWireframe();
4169 int Edgewidth = (int)Mactor->GetLineWidth();
4172 prop->SetLineWidth(Edgewidth + 1);
4174 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4175 Mapper->SetInput(ugridSimulation);
4176 vtkActor *ac = vtkActor::New();
4177 ac->SetMapper(Mapper);
4178 ac->SetProperty(prop);
4180 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
4181 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
4183 mySimulationActors->AddItem(ac);
4184 theRenderer->AddActor(ac);
4186 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4192 //=============================================================================
4196 //=============================================================================
4197 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
4200 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4203 EraseSimulationActors();
4204 mySimulationActors = vtkActorCollection::New();
4205 vtkRenderer *theRenderer =
4206 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4207 getRightFrame()->getViewFrame())->getRenderer();
4208 Standard_Boolean result;
4209 SMESH_Actor *ac = FindActor(aMesh, result, true);
4213 vtkUnstructuredGrid *ugrid =
4214 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4215 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4217 vtkPoints *Pts = ugrid->GetPoints();
4218 vtkPoints *newPts = vtkPoints::New();
4219 int nbPts = Pts->GetNumberOfPoints();
4220 for (int i = 0; i < nbPts; i++)
4222 newPts->InsertPoint(i, Pts->GetPoint(i));
4225 newugrid->SetPoints(newPts);
4226 newugrid->GetPoints()->InsertNextPoint(x, y, z);
4228 vtkMaskPoints *verts = vtkMaskPoints::New();
4229 verts->SetInput(newugrid);
4230 verts->SetGenerateVertices(1);
4231 verts->SetOnRatio(1);
4233 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4234 vertMapper->SetInput(verts->GetOutput());
4235 vertMapper->ScalarVisibilityOff();
4237 vtkActor *node = vtkActor::New();
4238 node->SetMapper(vertMapper);
4240 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4241 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4242 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4243 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
4244 if (!nodecolor.isValid())
4245 // nodecolor = QColor(0.,1.,0.);
4246 nodecolor = QColor(0, 1, 0);
4248 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
4249 float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
4252 QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
4256 node->GetProperty()->SetPointSize(intValue);
4258 node->VisibilityOn();
4260 mySimulationActors->AddItem(node);
4261 theRenderer->AddActor(node);
4264 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4268 //=============================================================================
4272 //=============================================================================
4273 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
4276 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4279 vtkRenderer *theRenderer =
4280 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4281 getRightFrame()->getViewFrame())->getRenderer();
4282 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
4287 ac->GetMapper()->ImmediateModeRenderingOn();
4288 ac->GetProperty()->SetRepresentationToWireframe();
4290 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4295 //=============================================================================
4299 //=============================================================================
4300 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
4303 Standard_Boolean result;
4305 SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
4311 //=============================================================================
4315 //=============================================================================
4316 void SMESHGUI::ScalarVisibilityOff(){
4317 if(vtkRenderer *aRenderer = ::GetCurrentRenderer()){
4318 vtkActorCollection *actorList = aRenderer->GetActors();
4319 actorList->InitTraversal();
4320 while(vtkActor *ac = actorList->GetNextActor()){
4321 if(SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac)){
4322 anActor->GetMapper()->ScalarVisibilityOff();
4325 ::RepaintCurrentView();
4329 //=============================================================================
4333 //=============================================================================
4334 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
4335 const TColStd_MapOfInteger & MapIndex)
4337 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4340 EraseSimulationActors();
4341 mySimulationActors = vtkActorCollection::New();
4342 vtkRenderer *theRenderer =
4343 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4344 getRightFrame()->getViewFrame())->getRenderer();
4345 Standard_Boolean result;
4346 SMESH_Actor *ac = FindActor(aMesh, result, true);
4349 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4353 vtkIdList *Ids = vtkIdList::New();
4354 for (; ite.More(); ite.Next())
4356 idNodes[i] = ite.Key();
4360 Ids->InsertId(0, idNodes[0]);
4361 pts[0] = idNodes[0];
4362 Ids->InsertId(1, idNodes[1]);
4363 pts[1] = idNodes[1];
4365 vtkUnstructuredGrid *ugrid =
4366 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4367 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4368 newugrid->SetPoints(ugrid->GetPoints());
4369 newugrid->InsertNextCell(VTK_LINE, 2, pts);
4371 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4372 Mapper->SetInput(newugrid);
4375 vtkActor *edge = vtkActor::New();
4376 edge->SetMapper(Mapper);
4377 edge->SetProperty(ac->GetProperty());
4378 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
4379 edge->VisibilityOn();
4380 mySimulationActors->AddItem(edge);
4381 theRenderer->AddActor(edge);
4384 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4388 //=============================================================================
4392 //=============================================================================
4393 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
4394 const TColStd_MapOfInteger & MapIndex, bool reverse)
4396 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4399 EraseSimulationActors();
4400 mySimulationActors = vtkActorCollection::New();
4401 vtkRenderer *theRenderer =
4402 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4403 getRightFrame()->getViewFrame())->getRenderer();
4404 Standard_Boolean result;
4405 SMESH_Actor *ac = FindActor(aMesh, result, true);
4408 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4412 vtkIdList *Ids = vtkIdList::New();
4413 for (; ite.More(); ite.Next())
4415 idNodes[i] = ite.Key();
4421 Ids->InsertId(0, idNodes[2]);
4422 pts[0] = idNodes[2];
4423 Ids->InsertId(1, idNodes[1]);
4424 pts[1] = idNodes[1];
4425 Ids->InsertId(2, idNodes[0]);
4426 pts[2] = idNodes[0];
4430 Ids->InsertId(0, idNodes[0]);
4431 pts[0] = idNodes[0];
4432 Ids->InsertId(1, idNodes[1]);
4433 pts[1] = idNodes[1];
4434 Ids->InsertId(2, idNodes[2]);
4435 pts[2] = idNodes[2];
4437 vtkUnstructuredGrid *ugrid =
4438 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4439 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4440 newugrid->SetPoints(ugrid->GetPoints());
4441 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
4443 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4444 Mapper->SetInput(newugrid);
4447 vtkActor *tri = vtkActor::New();
4448 tri->SetMapper(Mapper);
4449 tri->SetProperty(ac->GetProperty());
4450 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
4451 tri->VisibilityOn();
4452 mySimulationActors->AddItem(tri);
4453 theRenderer->AddActor(tri);
4456 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4460 //=============================================================================
4464 //=============================================================================
4465 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
4466 const TColStd_MapOfInteger & MapIndex, bool reverse)
4468 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4471 EraseSimulationActors();
4472 mySimulationActors = vtkActorCollection::New();
4473 vtkRenderer *theRenderer =
4474 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4475 getRightFrame()->getViewFrame())->getRenderer();
4476 Standard_Boolean result;
4477 SMESH_Actor *ac = FindActor(aMesh, result, true);
4479 vtkUnstructuredGrid *ugrid =
4480 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4484 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4487 vtkIdList *Ids = vtkIdList::New();
4488 for (; ite.More(); ite.Next())
4490 idNodes[i] = ite.Key();
4494 float *p0 = ugrid->GetPoint(idNodes[0]);
4495 float *p1 = ugrid->GetPoint(idNodes[1]);
4496 float *p2 = ugrid->GetPoint(idNodes[2]);
4497 float *p3 = ugrid->GetPoint(idNodes[3]);
4499 gp_Pnt P0(p0[0], p0[1], p0[2]);
4501 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4502 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4503 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
4505 gp_Vec Cross1 = V1 ^ V2;
4506 gp_Vec Cross2 = V2 ^ V3;
4509 if (Cross1.Dot(Cross2) < 0)
4511 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4512 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4516 if (Cross1.Dot(Cross2) < 0)
4519 idNodes[2] = idNodes[3];
4525 idNodes[1] = idNodes[2];
4532 Ids->InsertId(0, idNodes[3]);
4533 Ids->InsertId(1, idNodes[2]);
4534 Ids->InsertId(2, idNodes[1]);
4535 Ids->InsertId(3, idNodes[0]);
4539 Ids->InsertId(0, idNodes[0]);
4540 Ids->InsertId(1, idNodes[1]);
4541 Ids->InsertId(2, idNodes[2]);
4542 Ids->InsertId(3, idNodes[3]);
4545 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->GetUnstructuredGrid() );
4546 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4547 newugrid->SetPoints(ugrid->GetPoints());
4548 newugrid->InsertNextCell(VTK_QUAD, Ids);
4550 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4551 Mapper->SetInput(newugrid);
4554 vtkActor *quad = vtkActor::New();
4555 quad->SetMapper(Mapper);
4556 quad->SetProperty(ac->GetProperty());
4557 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
4558 quad->VisibilityOn();
4559 mySimulationActors->AddItem(quad);
4560 theRenderer->AddActor(quad);
4562 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4566 //=============================================================================
4570 //=============================================================================
4571 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
4572 const TColStd_MapOfInteger & MapIndex)
4574 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4577 EraseSimulationActors();
4578 mySimulationActors = vtkActorCollection::New();
4579 vtkRenderer *theRenderer =
4580 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4581 getRightFrame()->getViewFrame())->getRenderer();
4582 Standard_Boolean result;
4583 SMESH_Actor *ac = FindActor(aMesh, result, true);
4586 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4589 vtkIdList *Ids = vtkIdList::New();
4590 for (; ite.More(); ite.Next())
4592 idNodes[i] = ite.Key();
4596 Ids->InsertId(0, idNodes[0]);
4597 Ids->InsertId(1, idNodes[1]);
4598 Ids->InsertId(2, idNodes[2]);
4599 Ids->InsertId(3, idNodes[3]);
4601 vtkUnstructuredGrid *ugrid =
4602 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4603 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4604 newugrid->SetPoints(ugrid->GetPoints());
4605 newugrid->InsertNextCell(VTK_TETRA, Ids);
4607 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4608 Mapper->SetInput(newugrid);
4611 vtkActor *tetra = vtkActor::New();
4612 tetra->SetMapper(Mapper);
4613 tetra->SetProperty(ac->GetProperty());
4614 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
4615 tetra->VisibilityOn();
4616 mySimulationActors->AddItem(tetra);
4617 theRenderer->AddActor(tetra);
4619 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4623 //=============================================================================
4627 //=============================================================================
4628 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
4629 const TColStd_MapOfInteger & MapIndex)
4631 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4634 EraseSimulationActors();
4635 mySimulationActors = vtkActorCollection::New();
4636 vtkRenderer *theRenderer =
4637 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4638 getRightFrame()->getViewFrame())->getRenderer();
4639 Standard_Boolean result;
4640 SMESH_Actor *ac = FindActor(aMesh, result, true);
4643 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4646 vtkIdList *Ids = vtkIdList::New();
4647 for (; ite.More(); ite.Next())
4649 idNodes[i] = ite.Key();
4653 Ids->InsertId(0, idNodes[0]);
4654 Ids->InsertId(1, idNodes[1]);
4655 Ids->InsertId(2, idNodes[2]);
4656 Ids->InsertId(3, idNodes[3]);
4657 Ids->InsertId(4, idNodes[4]);
4658 Ids->InsertId(5, idNodes[5]);
4659 Ids->InsertId(6, idNodes[6]);
4660 Ids->InsertId(7, idNodes[7]);
4662 vtkUnstructuredGrid *ugrid =
4663 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4664 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4665 newugrid->SetPoints(ugrid->GetPoints());
4666 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4668 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4669 Mapper->SetInput(newugrid);
4672 vtkActor *hexa = vtkActor::New();
4673 hexa->SetMapper(Mapper);
4674 hexa->SetProperty(ac->GetProperty());
4675 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
4676 hexa->VisibilityOn();
4677 mySimulationActors->AddItem(hexa);
4678 theRenderer->AddActor(hexa);
4680 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4684 //=============================================================================
4688 //=============================================================================
4689 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr theMesh,
4690 const TColStd_MapOfInteger & MapIndex,
4695 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4696 CORBA::String_var anEntry = aSobj->GetID();
4697 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4698 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4699 anArrayOfIdeces->length(MapIndex.Extent());
4700 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4701 for(int i = 0; ite.More(); ite.Next(), i++){
4702 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4705 if(MapIndex.Extent() == 4){
4707 TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
4708 for(int i = 0; ite1.More(); ite1.Next(), i++){
4709 idNodes[i] = ite1.Key();
4711 vtkUnstructuredGrid *ugrid = anActor->GetUnstructuredGrid();
4712 float *p0 = ugrid->GetPoint(idNodes[0]);
4713 float *p1 = ugrid->GetPoint(idNodes[1]);
4714 float *p2 = ugrid->GetPoint(idNodes[2]);
4715 float *p3 = ugrid->GetPoint(idNodes[3]);
4717 gp_Pnt P0(p0[0], p0[1], p0[2]);
4719 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4720 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4721 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
4723 gp_Vec Cross1 = V1 ^ V2;
4724 gp_Vec Cross2 = V2 ^ V3;
4726 if(Cross1.Dot(Cross2) < 0){
4727 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4728 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4732 if(Cross1.Dot(Cross2) < 0){
4733 tmp = anArrayOfIdeces[2];
4734 anArrayOfIdeces[2] = anArrayOfIdeces[3];
4735 anArrayOfIdeces[3] = tmp;
4737 tmp = anArrayOfIdeces[1];
4738 anArrayOfIdeces[1] = anArrayOfIdeces[2];
4739 anArrayOfIdeces[2] = tmp;
4744 for(int i = 0; i < (MapIndex.Extent() / 2); i++){
4745 tmp = anArrayOfIdeces[i];
4746 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
4747 anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
4750 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4751 aMeshEditor->AddFace(anArrayOfIdeces);
4752 if(myAutomaticUpdate){
4753 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4754 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4755 aVisualObj->Update(true);
4757 AddActorInSelection(anActor);
4760 }catch(SALOME::SALOME_Exception& exc) {
4761 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4762 }catch(const std::exception& exc){
4763 INFOS("Follow exception was cought:\n\t"<<exc.what());
4765 INFOS("Unknown exception was cought !!!");
4769 //=============================================================================
4773 //=============================================================================
4774 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr theMesh,
4775 const TColStd_MapOfInteger & MapIndex)
4779 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4780 CORBA::String_var anEntry = aSobj->GetID();
4781 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4782 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4783 anArrayOfIdeces->length(MapIndex.Extent());
4784 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4785 for(int i = 0; ite.More(); ite.Next(), i++){
4786 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4788 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4789 aMeshEditor->AddVolume(anArrayOfIdeces);
4790 if(myAutomaticUpdate){
4791 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4792 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4793 aVisualObj->Update(true);
4797 }catch(SALOME::SALOME_Exception& exc) {
4798 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4799 }catch(const std::exception& exc){
4800 INFOS("Follow exception was cought:\n\t"<<exc.what());
4802 INFOS("Unknown exception was cought !!!");
4805 //=============================================================================
4809 //=============================================================================
4810 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr theMesh,
4811 const TColStd_MapOfInteger & MapIndex)
4815 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4816 CORBA::String_var anEntry = aSobj->GetID();
4817 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4818 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4819 anArrayOfIdeces->length(MapIndex.Extent());
4820 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4821 for(int i = 0; ite.More(); ite.Next(), i++){
4822 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4824 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4825 aMeshEditor->AddEdge(anArrayOfIdeces);
4826 if(myAutomaticUpdate){
4827 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4828 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4829 aVisualObj->Update(true);
4833 }catch(SALOME::SALOME_Exception& exc) {
4834 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4835 }catch(const std::exception& exc){
4836 INFOS("Follow exception was cought:\n\t"<<exc.what());
4838 INFOS("Unknown exception was cought !!!");
4841 //=============================================================================
4845 //=============================================================================
4846 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr theMesh,
4847 float x, float y, float z)
4851 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4852 CORBA::String_var anEntry = aSobj->GetID();
4853 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4854 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4855 aMeshEditor->AddNode(x, y, z);
4856 if(myAutomaticUpdate){
4857 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4858 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4859 aVisualObj->Update(true);
4863 }catch(SALOME::SALOME_Exception& exc) {
4864 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4865 }catch(const std::exception& exc){
4866 INFOS("Follow exception was cought:\n\t"<<exc.what());
4868 INFOS("Unknown exception was cought !!!");
4871 //=============================================================================
4875 //=============================================================================
4876 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
4878 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4881 EraseSimulationActors();
4882 mySimulationActors2D = vtkActor2DCollection::New();
4884 vtkRenderer *theRenderer =
4885 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4886 getRightFrame()->getViewFrame())->getRenderer();
4888 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
4889 gs2->SetGlyphTypeToTriangle();
4892 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
4893 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
4894 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
4896 legend->SetNumberOfEntries(4);
4897 legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
4898 legend->SetEntrySymbol(0, gs2->GetOutput());
4899 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
4900 legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
4901 legend->SetEntrySymbol(1, gs2->GetOutput());
4902 legend->SetEntryColor(1,
4903 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
4904 legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
4905 legend->SetEntrySymbol(2, gs2->GetOutput());
4906 legend->SetEntryColor(2,
4907 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
4908 legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
4909 legend->SetEntrySymbol(3, gs2->GetOutput());
4910 legend->SetEntryColor(3,
4911 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
4912 legend->SetPadding(5);
4913 // legend->GetProperty()->SetColor();
4915 mySimulationActors2D->AddItem(legend);
4916 theRenderer->AddActor2D(legend);
4919 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
4923 //===============================================================================
4924 // function : OnEditDelete()
4926 //===============================================================================
4927 void SMESHGUI::OnEditDelete()
4929 if (QAD_MessageBox::warn2
4930 (QAD_Application::getDesktop(),
4931 tr("SMESH_WRN_WARNING"),
4932 tr("SMESH_REALLY_DELETE"),
4933 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
4936 int nbSf = myActiveStudy->getStudyFramesCount();
4938 Standard_Boolean found;
4939 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
4940 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4941 SALOMEDS::GenericAttribute_var anAttr;
4942 SALOMEDS::AttributeIOR_var anIOR;
4944 SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
4945 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4946 for(; It.More(); It.Next()){
4947 Handle(SALOME_InteractiveObject) IObject = It.Value();
4948 if(IObject->hasEntry()){
4949 SALOMEDS::SObject_var SO = myStudy->FindObjectID(IObject->getEntry());
4951 /* Erase child graphical objects */
4952 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
4953 for(; it->More(); it->Next()){
4954 SALOMEDS::SObject_var CSO = it->Value();
4955 if(CSO->FindAttribute(anAttr, "AttributeIOR")){
4956 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4958 for(int i = 0; i < nbSf; i++){
4959 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
4960 CORBA::String_var anEntry = CSO->GetID();
4961 if(SMESH_Actor* anActor = ::FindActorByEntry(sf,anEntry.in())){
4962 RemoveActor(sf,anActor);
4968 /* Erase main graphical object */
4969 for(int i = 0; i < nbSf; i++){
4970 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
4971 if(SMESH_Actor* anActor = ::FindActorByEntry(sf,IObject->getEntry())){
4972 RemoveActor(sf,anActor);
4976 // Remove object(s) from data structures
4977 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IObject->getEntry());
4978 if(!obj->_is_nil()){
4979 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group ::_narrow(obj->GetObject());
4980 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(obj->GetObject());
4982 if ( !aGroup->_is_nil() ) { // DELETE GROUP
4983 SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
4984 aMesh->RemoveGroup( aGroup );
4986 else if ( !aSubMesh->_is_nil() ) { // DELETE SUBMESH
4987 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
4988 aMesh->RemoveSubMesh( aSubMesh );
4990 else {// default action: remove SObject from the study
4991 // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
4992 //QAD_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
4994 aStudyBuilder->RemoveObjectWithChildren( obj );
4999 } /* IObject->hasEntry() */
5002 /* Clear any previous selection */
5003 Sel->ClearIObjects();
5004 myActiveStudy->updateObjBrowser();
5007 //=======================================================================
5008 // name : SMESHGUI::GetFilterMgr
5009 // Purpose : Get filter manager
5010 //=======================================================================
5011 SMESH::FilterManager_ptr SMESHGUI::GetFilterMgr()