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():
535 //=============================================================================
539 //=============================================================================
540 SMESHGUI::~SMESHGUI()
544 //=============================================================================
548 //=============================================================================
549 SMESHGUI* SMESHGUI::GetSMESHGUI()
552 GetOrCreateSMESHGUI( QAD_Application::getDesktop() );
556 //=============================================================================
560 //=============================================================================
561 SMESHGUI* SMESHGUI::GetOrCreateSMESHGUI( QAD_Desktop* desktop )
565 smeshGUI = new SMESHGUI;
566 smeshGUI->myActiveDialogBox = 0 ;
567 smeshGUI->myState = -1 ;
568 smeshGUI->myDesktop = desktop ;
570 /* get smesh engine */
571 Engines::Component_var comp = desktop->getEngine("FactoryServer", "SMESH");
572 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
574 /* get geom engine */
575 Engines::Component_var comp1 = desktop->getEngine("FactoryServer", "GEOM");
576 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
578 /* set current study */
579 smeshGUI->myActiveStudy = desktop->getActiveStudy();
580 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
581 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
582 smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
583 smeshGUI->myComponentMesh->SetCurrentStudy( smeshGUI->myStudy );
584 // smeshGUI->myComponentGeom->NbLabels();
586 /* create service object */
587 smeshGUI->myStudyAPI = SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
589 smeshGUI->myDocument = new SMESHDS_Document(1);//NBU
591 smeshGUI->mySimulationActors = vtkActorCollection::New();
592 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
595 smeshGUI->myFilterMgr = smeshGUI->myComponentMesh->CreateFilterManager();
597 /* load resources for all available meshers */
598 smeshGUI->InitAvailableHypotheses();
600 /* study may have changed - set current study */
601 smeshGUI->myActiveStudy = desktop->getActiveStudy();
602 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
603 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
604 smeshGUI->myComponentGeom->GetCurrentStudy( smeshGUI->myStudyId );
605 smeshGUI->myComponentMesh->SetCurrentStudy( smeshGUI->myStudy );
607 // Set active study to Study API
608 smeshGUI->myStudyAPI.Update( smeshGUI->myStudy );
611 /* Automatic Update flag */
612 smeshGUI->myAutomaticUpdate = ( QAD_CONFIG->getSetting( "SMESH:AutomaticUpdate" ).compare( "true" ) == 0 );
617 //=============================================================================
621 //=============================================================================
622 void SMESHGUI::SetState(int aState)
624 this->myState = aState;
628 //=============================================================================
632 //=============================================================================
633 void SMESHGUI::ResetState()
639 //=============================================================================
643 //=============================================================================
644 void SMESHGUI::EmitSignalDeactivateDialog()
646 emit this->SignalDeactivateActiveDialog();
650 //=============================================================================
654 //=============================================================================
655 void SMESHGUI::EmitSignalCloseAllDialogs()
657 emit SignalCloseAllDialogs();
661 //=============================================================================
665 //=============================================================================
666 QDialog *SMESHGUI::GetActiveDialogBox()
668 return this->myActiveDialogBox;
671 //=============================================================================
675 //=============================================================================
676 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
678 this->myActiveDialogBox = (QDialog *) aDlg;
682 //=============================================================================
686 //=============================================================================
687 QAD_Study *SMESHGUI::GetActiveStudy()
689 return this->myActiveStudy;
692 //=============================================================================
696 //=============================================================================
697 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
699 return SALOMEDS::Study::_narrow(myStudy);
702 //=============================================================================
706 //=============================================================================
707 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
712 //=============================================================================
716 //=============================================================================
717 QAD_Desktop *SMESHGUI::GetDesktop()
719 return this->myDesktop;
722 //=============================================================================
726 //=============================================================================
727 void SMESHGUI::activeStudyChanged(QAD_Desktop* parent)
729 MESSAGE("SMESHGUI::activeStudyChanged init.");
730 QAD_Study* prevStudy = 0;
732 prevStudy = smeshGUI->myActiveStudy;
733 /* Create or retrieve an object SMESHGUI */
734 MESSAGE("Active study changed : prev study =" << prevStudy);
735 SMESHGUI::GetOrCreateSMESHGUI( parent );
736 MESSAGE("Active study changed : active study =" << smeshGUI->myActiveStudy);
737 if ( prevStudy != smeshGUI->myActiveStudy ) {
738 smeshGUI->EmitSignalCloseAllDialogs();
739 MESSAGE("Active study changed : SMESHGUI nullified" << endl);
741 ::UpdateSelectionProp();
743 MESSAGE("SMESHGUI::activeStudyChanged done.") return;
746 //=============================================================================
750 //=============================================================================
751 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
753 /* Here the position is on the bottom right corner - 10 */
754 // aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
756 QAD_Desktop *PP = QAD_Application::getDesktop();
757 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
758 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
762 //=============================================================================
766 //=============================================================================
767 void SMESHGUI::EraseSimulationActors()
769 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
771 vtkRenderer *theRenderer =
772 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
773 getRightFrame()->getViewFrame())->getRenderer();
774 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
776 if (mySimulationActors != NULL)
778 mySimulationActors->InitTraversal();
779 vtkActor *ac = mySimulationActors->GetNextActor();
780 while (!(ac == NULL))
782 theRenderer->RemoveActor(ac);
783 ac = mySimulationActors->GetNextActor();
785 mySimulationActors->RemoveAllItems();
787 if (mySimulationActors2D != NULL)
789 mySimulationActors2D->InitTraversal();
790 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
791 while (!(ac == NULL))
793 theRenderer->RemoveActor2D(ac);
794 ac = mySimulationActors2D->GetNextActor2D();
796 mySimulationActors2D->RemoveAllItems();
798 SetPointRepresentation(false);
802 //=============================================================================
806 //=============================================================================
807 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh( GEOM::GEOM_Shape_ptr aShape,
811 if ( !myComponentMesh->_is_nil() && !aShape->_is_nil() ) {
812 SMESH::SMESH_Mesh_var aMesh = myComponentMesh->CreateMesh( aShape );
813 if ( !aMesh->_is_nil() ) {
814 SALOMEDS::SObject_var SM = smeshGUI->myStudy->FindObjectIOR( _orb->object_to_string( aMesh ) );
815 myStudyAPI.SetName( SM, NameMesh );
816 return SMESH::SMESH_Mesh::_narrow(aMesh);
820 catch( const SALOME::SALOME_Exception& S_ex ) {
821 QtCatchCorbaException( S_ex );
823 return SMESH::SMESH_Mesh::_nil();
826 //=============================================================================
830 //=============================================================================
831 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh( SMESH::SMESH_Mesh_ptr aMesh,
832 GEOM::GEOM_Shape_ptr aShape,
835 SMESH::SMESH_subMesh_var aSubMesh;
837 if ( !aMesh->_is_nil() && !aShape->_is_nil() )
839 aSubMesh = SMESH::SMESH_subMesh::_duplicate( aMesh->GetSubMesh( aShape, NameMesh.latin1() ) ); //VSR: published automatically
841 catch( const SALOME::SALOME_Exception& S_ex ) {
842 QtCatchCorbaException( S_ex );
843 aSubMesh = SMESH::SMESH_subMesh::_nil();
845 return aSubMesh._retn();
848 //=============================================================================
852 //=============================================================================
853 SMESH::SMESH_Group_ptr SMESHGUI::AddGroup( SMESH::SMESH_Mesh_ptr aMesh,
854 SMESH::ElementType aType,
857 SMESH::SMESH_Group_var aGroup;
859 if ( !aMesh->_is_nil() )
861 aGroup = SMESH::SMESH_Group::_duplicate( aMesh->CreateGroup( aType, strdup(aName) ) ); //VSR: published automatically
863 catch( const SALOME::SALOME_Exception& S_ex ) {
864 QtCatchCorbaException( S_ex );
865 aGroup = SMESH::SMESH_Group::_nil();
867 myActiveStudy->updateObjBrowser( true );
868 return aGroup._retn();
871 //=============================================================================
875 //=============================================================================
877 static void addMap( const map<string, HypothesisData*>& theMap,
878 map<string, HypothesisData*>& toMap)
880 map<string, HypothesisData*>::const_iterator it;
881 for ( it = theMap.begin(); it != theMap.end(); it++ )
886 //=============================================================================
888 * InitAvailableHypotheses (read from resource XML file)
890 //=============================================================================
891 void SMESHGUI::InitAvailableHypotheses ()
894 if ((myHypothesesMap.begin() == myHypothesesMap.end()) &&
895 (myAlgorithmsMap.begin() == myAlgorithmsMap.end()))
898 QAD_ResourceMgr* resMgr = QAD_Desktop::createResourceManager();
901 // Find name of a resource XML file ("SMESH_Meshers.xml");
903 char* cenv = getenv("SMESH_MeshersList");
905 HypsXml.sprintf("%s", cenv);
907 QStringList HypsXmlList = QStringList::split( ":", HypsXml, false );
908 if (HypsXmlList.count() == 0)
910 QAD_MessageBox::error1(QAD_Application::getDesktop(),
911 tr("SMESH_WRN_WARNING"),
912 tr("MESHERS_FILE_NO_VARIABLE"),
917 // loop on files in HypsXml
918 QString aNoAccessFiles;
919 for ( int i = 0; i < HypsXmlList.count(); i++ ) {
920 QString HypsXml = HypsXmlList[ i ];
922 // Find full path to the resource XML file
923 QString xmlFile = HypsXml + ".xml";
924 xmlFile = QAD_Tools::addSlash(resMgr->findFile(xmlFile, HypsXml)) + xmlFile;
926 QFile file (QAD_Tools::unix2win(xmlFile));
927 if (file.exists() && file.open(IO_ReadOnly))
931 SMESHGUI_XmlHandler* myXmlHandler = new SMESHGUI_XmlHandler();
932 ASSERT(myXmlHandler);
934 QXmlInputSource source (file);
935 QXmlSimpleReader reader;
936 reader.setContentHandler(myXmlHandler);
937 reader.setErrorHandler(myXmlHandler);
938 bool ok = reader.parse(source);
942 addMap( myXmlHandler->myHypothesesMap, myHypothesesMap );
943 addMap( myXmlHandler->myAlgorithmsMap, myAlgorithmsMap );
947 QAD_MessageBox::error1(myDesktop,
948 tr("INF_PARSE_ERROR"),
949 tr(myXmlHandler->errorProtocol()),
955 if (aNoAccessFiles.isEmpty())
956 aNoAccessFiles = xmlFile;
958 aNoAccessFiles += ", " + xmlFile;
963 if (!aNoAccessFiles.isEmpty())
965 QString aMess = tr("MESHERS_FILE_CANT_OPEN") + " " + aNoAccessFiles + "\n";
966 aMess += tr("MESHERS_FILE_CHECK_VARIABLE");
968 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
969 tr("SMESH_WRN_WARNING"),
977 //=============================================================================
979 * GetAvailableHypotheses (read from resource XML file)
981 //=============================================================================
982 QStringList SMESHGUI::GetAvailableHypotheses (const bool isAlgo)
984 QStringList aHypList;
986 // Init list of available hypotheses, if needed
987 InitAvailableHypotheses();
989 // fill list of hypotheses/algorithms
990 map<string, HypothesisData*>::iterator anIter;
993 anIter = myAlgorithmsMap.begin();
994 for (; anIter != myAlgorithmsMap.end(); anIter++)
996 aHypList.append(((*anIter).first).c_str());
1001 anIter = myHypothesesMap.begin();
1002 for (; anIter != myHypothesesMap.end(); anIter++)
1004 aHypList.append(((*anIter).first).c_str());
1011 //=============================================================================
1015 //=============================================================================
1016 HypothesisData* SMESHGUI::GetHypothesisData (const char* aHypType)
1018 HypothesisData* aHypData = 0;
1020 // Init list of available hypotheses, if needed
1021 InitAvailableHypotheses();
1023 if (myHypothesesMap.find(aHypType) == myHypothesesMap.end())
1025 if (myAlgorithmsMap.find(aHypType) != myAlgorithmsMap.end())
1027 aHypData = myAlgorithmsMap[aHypType];
1032 aHypData = myHypothesesMap[aHypType];
1037 //=============================================================================
1039 * Get a Hypothesis Creator from a Plugin Library
1041 //=============================================================================
1042 SMESHGUI_GenericHypothesisCreator* SMESHGUI::GetHypothesisCreator(const QString& aHypType)
1044 char* sHypType = (char*)aHypType.latin1();
1045 MESSAGE("Get HypothesisCreator for " << sHypType);
1047 SMESHGUI_GenericHypothesisCreator* aCreator = 0;
1049 // check, if creator for this hypothesis type already exists
1050 if (myHypCreatorMap.find(sHypType) != myHypCreatorMap.end())
1052 aCreator = myHypCreatorMap[sHypType];
1056 // 1. Init list of available hypotheses, if needed
1057 InitAvailableHypotheses();
1059 // 2. Get names of plugin libraries
1060 HypothesisData* aHypData = GetHypothesisData(sHypType);
1065 QString aClientLibName = aHypData->ClientLibName;
1066 QString aServerLibName = aHypData->ServerLibName;
1068 // 3. Load Client Plugin Library
1071 // load plugin library
1072 MESSAGE("Loading client meshers plugin library ...");
1073 void* libHandle = dlopen (aClientLibName, RTLD_LAZY);
1076 // report any error, if occured
1077 const char* anError = dlerror();
1082 // get method, returning hypothesis creator
1083 MESSAGE("Find GetHypothesisCreator() method ...");
1084 typedef SMESHGUI_GenericHypothesisCreator* (*GetHypothesisCreator) \
1085 (QString aHypType, QString aServerLibName, SMESHGUI* aSMESHGUI);
1086 GetHypothesisCreator procHandle =
1087 (GetHypothesisCreator)dlsym( libHandle, "GetHypothesisCreator" );
1090 MESSAGE("bad hypothesis client plugin library");
1095 // get hypothesis creator
1096 MESSAGE("Get Hypothesis Creator for " << aHypType);
1097 aCreator = procHandle(aHypType, aServerLibName, smeshGUI);
1100 MESSAGE("no such a hypothesis in this plugin");
1104 // map hypothesis creator to a hypothesis name
1105 myHypCreatorMap[sHypType] = aCreator;
1110 catch (const SALOME::SALOME_Exception& S_ex)
1112 QtCatchCorbaException(S_ex);
1119 //=============================================================================
1123 //=============================================================================
1124 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis (const QString& aHypType,
1125 const QString& aHypName,
1128 MESSAGE("Create " << aHypType << " with name " << aHypName);
1130 SMESH::SMESH_Hypothesis_var Hyp;
1132 HypothesisData* aHypData = GetHypothesisData((char*)aHypType.latin1());
1133 QString aServLib = aHypData->ServerLibName;
1137 Hyp = myComponentMesh->CreateHypothesis(aHypType, aServLib);
1138 if (!Hyp->_is_nil())
1140 SALOMEDS::SObject_var SHyp =
1141 smeshGUI->myStudy->FindObjectIOR( _orb->object_to_string( Hyp ) );
1142 if (!SHyp->_is_nil())
1144 if ( !aHypName.isEmpty() )
1145 myStudyAPI.SetName( SHyp, aHypName );
1146 myActiveStudy->updateObjBrowser(true);
1151 catch (const SALOME::SALOME_Exception & S_ex)
1153 QtCatchCorbaException(S_ex);
1156 return SMESH::SMESH_Hypothesis::_nil();
1159 //=============================================================================
1163 //=============================================================================
1164 bool SMESHGUI::AddHypothesisOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
1165 SMESH::SMESH_Hypothesis_ptr aHyp)
1167 int res = SMESH::HYP_UNKNOWN_FATAL;
1170 if ( !aMesh->_is_nil() ) {
1171 SALOMEDS::SObject_var SM = myStudyAPI.FindObject( aMesh );
1172 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
1174 res = aMesh->AddHypothesis( aShape, aHyp );
1175 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1176 SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1177 if ( !SM->_is_nil() && !SH->_is_nil() ) {
1178 //myStudyAPI.SetHypothesis(SM, SH); // VSR: published automatically by engine
1179 myStudyAPI.ModifiedMesh(SM, false);
1182 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1184 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1186 tr(QString("SMESH_HYP_%1").arg(res)),
1187 tr("SMESH_BUT_OK"));
1190 else if ( res > SMESH::HYP_OK ) {
1192 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1193 tr("SMESH_WRN_WARNING"),
1194 tr(QString("SMESH_HYP_%1").arg(res)),
1195 tr("SMESH_BUT_OK"));
1199 catch( const SALOME::SALOME_Exception& S_ex ) {
1201 QtCatchCorbaException( S_ex );
1202 res = SMESH::HYP_UNKNOWN_FATAL;
1205 return res < SMESH::HYP_UNKNOWN_FATAL;
1208 //=============================================================================
1212 //=============================================================================
1213 bool SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh
1214 (const Handle(SALOME_InteractiveObject)& IObject)
1216 int res = SMESH::HYP_UNKNOWN_FATAL;
1219 if (IObject->hasReference())
1222 SMESH::SMESH_Hypothesis_var anHyp;
1223 SALOMEDS::SObject_var SO_Hypothesis =
1224 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
1225 SALOMEDS::GenericAttribute_var anAttr;
1226 SALOMEDS::AttributeIOR_var anIOR;
1228 if (!SO_Hypothesis->_is_nil()) {
1229 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR")) {
1230 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1231 anHyp = SMESH::SMESH_Hypothesis::_narrow
1232 (_orb->string_to_object(anIOR->Value()));
1235 SALOMEDS::SObject_var SO_Applied_Hypothesis =
1236 smeshGUI->myStudy->FindObjectID(IObject->getReference());
1237 if (!SO_Applied_Hypothesis->_is_nil()) {
1238 SALOMEDS::SObject_var MorSM =
1239 smeshGUI->myStudyAPI.GetMeshOrSubmesh(SO_Applied_Hypothesis);
1240 if (!MorSM->_is_nil()) {
1241 GEOM::GEOM_Shape_var aShape =
1242 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
1243 if (!aShape->_is_nil() && MorSM->FindAttribute(anAttr, "AttributeIOR")) {
1244 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1245 SMESH::SMESH_Mesh_var aMesh =
1246 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1247 SMESH::SMESH_subMesh_var aSubMesh =
1248 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1250 if (!aSubMesh->_is_nil())
1251 aMesh = aSubMesh->GetFather();
1253 if (!aMesh->_is_nil())
1255 res = aMesh->RemoveHypothesis(aShape, anHyp);
1256 if ( res < SMESH::HYP_UNKNOWN_FATAL )
1257 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
1258 if ( res > SMESH::HYP_OK ) {
1260 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1261 tr("SMESH_WRN_WARNING"),
1262 tr(QString("SMESH_HYP_%1").arg(res)),
1263 tr("SMESH_BUT_OK"));
1272 catch( const SALOME::SALOME_Exception& S_ex ) {
1274 QtCatchCorbaException( S_ex );
1275 res = SMESH::HYP_UNKNOWN_FATAL;
1278 else if (IObject->hasEntry())
1280 MESSAGE("IObject entry " << IObject->getEntry());
1282 return res < SMESH::HYP_UNKNOWN_FATAL;
1285 //=============================================================================
1289 //=============================================================================
1290 bool SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh(SALOMEDS::SObject_ptr MorSM,
1291 SMESH::SMESH_Hypothesis_ptr anHyp)
1293 SALOMEDS::SObject_var AHR, aRef;
1294 SALOMEDS::GenericAttribute_var anAttr;
1295 SALOMEDS::AttributeIOR_var anIOR;
1296 int res = SMESH::HYP_UNKNOWN_FATAL;
1299 if (!MorSM->_is_nil()) {
1301 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
1302 if (!aShape->_is_nil()) {
1303 if (MorSM->FindAttribute(anAttr, "AttributeIOR")) {
1304 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1305 SMESH::SMESH_Mesh_var aMesh =
1306 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1307 SMESH::SMESH_subMesh_var aSubMesh =
1308 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1310 if ( !aSubMesh->_is_nil() )
1311 aMesh = aSubMesh->GetFather();
1313 if (!aMesh->_is_nil()) {
1314 res = aMesh->RemoveHypothesis(aShape, anHyp);
1315 if ( res < SMESH::HYP_UNKNOWN_FATAL )
1316 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
1317 if ( res > SMESH::HYP_OK ) {
1319 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1320 tr("SMESH_WRN_WARNING"),
1321 tr(QString("SMESH_HYP_%1").arg(res)),
1322 tr("SMESH_BUT_OK"));
1329 catch( const SALOME::SALOME_Exception& S_ex ) {
1331 QtCatchCorbaException( S_ex );
1332 res = SMESH::HYP_UNKNOWN_FATAL;
1335 return res < SMESH::HYP_UNKNOWN_FATAL;
1338 //=============================================================================
1342 //=============================================================================
1343 bool SMESHGUI::AddAlgorithmOnMesh( SMESH::SMESH_Mesh_ptr aMesh,
1344 SMESH::SMESH_Hypothesis_ptr aHyp )
1346 int res = SMESH::HYP_UNKNOWN_FATAL;
1349 if ( !aMesh->_is_nil() ) {
1350 SALOMEDS::SObject_var SM = myStudyAPI.FindObject( aMesh );
1351 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SM );
1353 res = aMesh->AddHypothesis( aShape, aHyp );
1354 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1355 //SALOMEDS::SObject_var SH = myStudyAPI.FindObject( aHyp );
1356 //if ( !SM->_is_nil() && !SH->_is_nil() ) {
1357 //myStudyAPI.SetAlgorithms(SM, SH);
1358 myStudyAPI.ModifiedMesh( SM, false );
1361 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1363 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1365 tr(QString("SMESH_HYP_%1").arg(res)),
1366 tr("SMESH_BUT_OK"));
1369 else if ( res > SMESH::HYP_OK ) {
1371 QAD_MessageBox::warn1( QAD_Application::getDesktop(),
1372 tr( "SMESH_WRN_WARNING" ),
1373 tr(QString("SMESH_HYP_%1").arg(res)),
1374 tr( "SMESH_BUT_OK" ) );
1378 catch( const SALOME::SALOME_Exception& S_ex ) {
1380 QtCatchCorbaException( S_ex );
1381 res = SMESH::HYP_UNKNOWN_FATAL;
1384 return res < SMESH::HYP_UNKNOWN_FATAL;
1387 //=============================================================================
1391 //=============================================================================
1392 bool SMESHGUI::AddHypothesisOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh,
1393 SMESH::SMESH_Hypothesis_ptr aHyp )
1395 int res = SMESH::HYP_UNKNOWN_FATAL;
1398 if ( !aSubMesh->_is_nil() ) {
1400 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1401 SALOMEDS::SObject_var SsubM = myStudyAPI.FindObject( aSubMesh );
1402 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh( SsubM );
1403 if ( !aMesh->_is_nil() && !SsubM->_is_nil() && !aShape->_is_nil() ) {
1404 res = aMesh->AddHypothesis( aShape, aHyp );
1405 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1406 //SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1407 // if (!SsubM->_is_nil() && !SH->_is_nil())
1409 // myStudyAPI.SetHypothesis(SsubM, SH);
1410 myStudyAPI.ModifiedMesh( SsubM, false );
1413 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1415 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1417 tr(QString("SMESH_HYP_%1").arg(res)),
1418 tr("SMESH_BUT_OK"));
1421 else if ( res > SMESH::HYP_OK ) {
1423 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1424 tr( "SMESH_WRN_WARNING" ),
1425 tr(QString("SMESH_HYP_%1").arg(res)),
1426 tr( "SMESH_BUT_OK" ) );
1431 catch( const SALOME::SALOME_Exception& S_ex ) {
1433 QtCatchCorbaException( S_ex );
1434 res = SMESH::HYP_UNKNOWN_FATAL;
1437 return res < SMESH::HYP_UNKNOWN_FATAL;
1440 //=============================================================================
1444 //=============================================================================
1445 bool SMESHGUI::AddAlgorithmOnSubMesh( SMESH::SMESH_subMesh_ptr aSubMesh,
1446 SMESH::SMESH_Hypothesis_ptr aHyp )
1448 int res = SMESH::HYP_UNKNOWN_FATAL;
1451 if ( !aSubMesh->_is_nil() ) {
1453 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
1454 SALOMEDS::SObject_var SsubM = myStudyAPI.FindObject(aSubMesh);
1455 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
1456 if ( !aMesh->_is_nil() && !SsubM->_is_nil() && !aShape->_is_nil() ) {
1457 res = aMesh->AddHypothesis( aShape, aHyp );
1458 if ( res < SMESH::HYP_UNKNOWN_FATAL ) {
1459 //SALOMEDS::SObject_var SH = myStudyAPI.FindObject(aHyp);
1460 //if (!SsubM->_is_nil() && !SH->_is_nil()) {
1461 //myStudyAPI.SetAlgorithms(SsubM, SH);
1462 myStudyAPI.ModifiedMesh( SsubM, false );
1465 if ( res >= SMESH::HYP_UNKNOWN_FATAL ) {
1467 QAD_MessageBox::error1(QAD_Application::getDesktop(),
1469 tr(QString("SMESH_HYP_%1").arg(res)),
1470 tr("SMESH_BUT_OK"));
1473 else if ( res > SMESH::HYP_OK ) {
1475 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
1476 tr( "SMESH_WRN_WARNING" ),
1477 tr(QString("SMESH_HYP_%1").arg(res)),
1478 tr( "SMESH_BUT_OK" ) );
1483 catch( const SALOME::SALOME_Exception& S_ex ) {
1485 QtCatchCorbaException( S_ex );
1486 res = SMESH::HYP_UNKNOWN_FATAL;
1489 return res < SMESH::HYP_UNKNOWN_FATAL;
1492 //=============================================================================
1496 //=============================================================================
1497 int SMESHGUI::GetNameOfSelectedIObjects(SALOME_Selection * Sel, QString & aName)
1499 int nbSel = Sel->IObjectCount();
1502 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1503 aName = IObject->getName();
1507 aName = tr("SMESH_OBJECTS_SELECTED").arg(nbSel);
1512 //=============================================================================
1516 //=============================================================================
1517 int SMESHGUI::GetNameOfSelectedNodes(SALOME_Selection * Sel, QString & aName){
1519 if(Sel->IObjectCount() == 1){
1520 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1521 if(IObject->hasEntry()){
1522 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1523 TColStd_MapOfInteger MapIndex;
1524 Sel->GetIndex(IObject, MapIndex);
1525 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1526 for(; ite.More(); ite.Next()){
1527 aName += QString(" %1").arg(anActor->GetNodeObjId(ite.Key()));
1529 return MapIndex.Extent();
1536 //=============================================================================
1540 //=============================================================================
1541 int SMESHGUI::GetNameOfSelectedElements(SALOME_Selection * Sel, QString & aName){
1543 if(Sel->IObjectCount() == 1){
1544 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1545 if(IObject->hasEntry()){
1546 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1547 TColStd_MapOfInteger MapIndex;
1548 Sel->GetIndex(IObject, MapIndex);
1549 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1550 std::vector<int> aList;
1551 for(; ite.More(); ite.Next()){
1552 int aVtkId = ite.Key();
1553 int anObjId = anActor->GetElemObjId(aVtkId);
1554 std::vector<int>::iterator found = find(aList.begin(), aList.end(), anObjId);
1555 // MESSAGE("GetNameOfSelectedElements(): VTK Id = " << aVtkId << ", OBJECT Id = " << anObjId);
1556 if (found == aList.end()) {
1557 aList.push_back(anObjId);
1558 aName += QString(" %1").arg(anObjId);
1561 return aList.size();
1569 //=============================================================================
1573 //=============================================================================
1574 int SMESHGUI::GetNameOfSelectedEdges(SALOME_Selection * Sel, QString & aName){
1576 if(Sel->IObjectCount() == 1){
1577 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1578 if(IObject->hasEntry()){
1579 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1580 TColStd_MapOfInteger MapIndex;
1581 Sel->GetIndex(IObject, MapIndex);
1582 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1583 for(; ite.More(); ite.Next()){
1584 aName += QString(" %1").arg(ite.Key());
1586 return MapIndex.Extent();
1594 //=============================================================================
1598 //=============================================================================
1599 SMESH_Actor *SMESHGUI::FindActorByEntry(QString theEntry,
1600 Standard_Boolean & theResult,
1601 bool onlyInActiveView)
1604 int aNbStudyFrames = myActiveStudy->getStudyFramesCount();
1605 for (int i = 0; i < aNbStudyFrames; i++){
1606 QAD_StudyFrame *aStudyFrame = myActiveStudy->getStudyFrame(i);
1607 if(SMESH_Actor *anActor = ::FindActorByEntry(aStudyFrame,theEntry.latin1())){
1615 //=============================================================================
1619 //=============================================================================
1620 SMESH_Actor* SMESHGUI::FindActor(CORBA::Object_ptr theObj,
1621 Standard_Boolean & theResult,
1622 bool theOnlyInActiveView)
1625 SMESH_Actor* aRes = NULL;
1626 if ( !CORBA::is_nil( theObj ) ) {
1627 SALOMEDS::SObject_var aSObject = SALOMEDS::SObject::_narrow( myStudy->FindObjectIOR( _orb->object_to_string( theObj ) ) );
1628 if( !aSObject->_is_nil()) {
1629 CORBA::String_var anEntry = aSObject->GetID();
1630 aRes = FindActorByEntry( anEntry.in(), theResult, theOnlyInActiveView );
1636 //=============================================================================
1640 //=============================================================================
1641 SMESH::SMESH_Mesh_ptr SMESHGUI::ConvertIOinMesh(const Handle(SALOME_InteractiveObject) & IO,
1642 Standard_Boolean & testResult)
1644 SMESH::SMESH_Mesh_var aMesh;
1650 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1651 SALOMEDS::GenericAttribute_var anAttr;
1652 SALOMEDS::AttributeIOR_var anIOR;
1653 if (!obj->_is_nil())
1655 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1657 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1659 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->Value()));
1660 if (!aMesh->_is_nil())
1663 return SMESH::SMESH_Mesh::_duplicate(aMesh);
1668 return SMESH::SMESH_Mesh::_nil();
1671 //=============================================================================
1675 //=============================================================================
1676 SMESH::SMESH_subMesh_ptr SMESHGUI::ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject) & IO,
1677 Standard_Boolean & testResult)
1679 SMESH::SMESH_subMesh_var aSubMesh;
1685 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1686 SALOMEDS::GenericAttribute_var anAttr;
1687 SALOMEDS::AttributeIOR_var anIOR;
1688 if (!obj->_is_nil())
1690 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1692 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1693 aSubMesh = SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->Value()));
1694 if (!aSubMesh->_is_nil())
1697 return SMESH::SMESH_subMesh::_duplicate(aSubMesh);
1702 return SMESH::SMESH_subMesh::_nil();
1705 //=============================================================================
1709 //=============================================================================
1710 SMESH::SMESH_Hypothesis_ptr SMESHGUI::ConvertIOinSMESHHypothesis(const Handle(SALOME_InteractiveObject) & IO,
1711 Standard_Boolean & testResult)
1713 SMESH::SMESH_Hypothesis_var aHyp;
1719 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1720 SALOMEDS::GenericAttribute_var anAttr;
1721 SALOMEDS::AttributeIOR_var anIOR;
1722 if (!obj->_is_nil())
1724 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1726 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1727 aHyp = SMESH::SMESH_Hypothesis::_narrow(_orb->string_to_object(anIOR->Value()));
1728 if (!aHyp->_is_nil())
1731 return SMESH::SMESH_Hypothesis::_duplicate(aHyp);
1736 return SMESH::SMESH_Hypothesis::_nil();
1739 //=============================================================================
1743 //=============================================================================
1744 SMESH::SMESH_Group_ptr SMESHGUI::ConvertIOinSMESHGroup(const Handle(SALOME_InteractiveObject) & IO,
1745 Standard_Boolean & testResult)
1747 SMESH::SMESH_Group_var aGroup;
1751 if (IO->hasEntry()) {
1752 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1753 SALOMEDS::GenericAttribute_var anAttr;
1754 SALOMEDS::AttributeIOR_var anIOR;
1755 if (!obj->_is_nil()) {
1756 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1757 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1758 aGroup = SMESH::SMESH_Group::_narrow(_orb->string_to_object(anIOR->Value()));
1759 if (!aGroup->_is_nil()) {
1761 return SMESH::SMESH_Group::_duplicate(aGroup);
1766 return SMESH::SMESH_Group::_nil();
1769 //=============================================================================
1773 //=============================================================================
1774 GEOM::GEOM_Shape_ptr SMESHGUI::ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject) & IO,
1775 Standard_Boolean & testResult)
1777 GEOM::GEOM_Shape_var aShape;
1781 if (IO->hasEntry()) {
1782 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1783 SALOMEDS::GenericAttribute_var anAttr;
1784 SALOMEDS::AttributeIOR_var anIOR;
1785 if (!obj->_is_nil()) {
1786 if (obj->FindAttribute(anAttr, "AttributeIOR")) {
1787 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1788 aShape = myComponentGeom->GetIORFromString(anIOR->Value());
1789 if (!aShape->_is_nil()) {
1791 return GEOM::GEOM_Shape::_duplicate(aShape);
1796 return GEOM::GEOM_Shape::_nil();
1799 //=============================================================================
1803 //=============================================================================
1804 void SMESHGUI::SetViewMode(int commandId){
1805 SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
1806 if(Sel->IObjectCount() >= 1){
1807 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1808 for(; It.More(); It.Next()){
1809 Handle(SALOME_InteractiveObject) IObject = It.Value();
1810 if(IObject->hasEntry()){
1811 if(SMESH_Actor *anActor = ::FindActorByEntry(IObject->getEntry())){
1814 ChangeRepresentation(anActor,0);
1817 ChangeRepresentation(anActor,1);
1820 ChangeRepresentation(anActor,2);
1823 ChangeRepresentation(anActor,5);
1826 ChangeRepresentation(anActor,3);
1832 if(commandId == 1133)
1833 ChangeRepresentation(NULL,4);
1837 //=============================================================================
1841 //=============================================================================
1842 void SMESHGUI::ChangeRepresentation(SMESH_Actor * theActor, int type){
1845 //theActor->UnShrink();
1846 theActor->SetRepresentation(SMESH_Actor::eEdge);
1850 //theActor->UnShrink();
1851 theActor->SetRepresentation(SMESH_Actor::eSurface);
1855 theActor->IsShrunk() ? theActor->UnShrink() : theActor->SetShrink();
1856 //theActor->SetRepresentation(SMESH_Actor::eSurface);
1860 //theActor->UnShrink();
1861 theActor->SetRepresentation(SMESH_Actor::ePoint);
1866 theActor->GetSufaceColor(color[0], color[1], color[2]);
1867 int c0 = int (color[0] * 255);
1868 int c1 = int (color[1] * 255);
1869 int c2 = int (color[2] * 255);
1870 QColor c(c0, c1, c2);
1873 theActor->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1874 c0 = int (edgecolor[0] * 255);
1875 c1 = int (edgecolor[1] * 255);
1876 c2 = int (edgecolor[2] * 255);
1877 QColor e(c0, c1, c2);
1879 float backfacecolor[3];
1880 theActor->GetBackSufaceColor(backfacecolor[0], backfacecolor[1], backfacecolor[2]);
1881 c0 = int (backfacecolor[0] * 255);
1882 c1 = int (backfacecolor[1] * 255);
1883 c2 = int (backfacecolor[2] * 255);
1884 QColor b(c0, c1, c2);
1887 theActor->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1888 c0 = int (nodecolor[0] * 255);
1889 c1 = int (nodecolor[1] * 255);
1890 c2 = int (nodecolor[2] * 255);
1891 QColor n(c0, c1, c2);
1893 int Edgewidth = (int)theActor->GetLineWidth();
1896 int intValue = int(theActor->GetNodeSize());
1897 float Shrink = theActor->GetShrinkFactor();
1899 SMESHGUI_Preferences_ColorDlg *aDlg = new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),"");
1900 aDlg->SetColor(1, c);
1901 aDlg->SetColor(2, e);
1902 aDlg->SetColor(3, n);
1903 aDlg->SetColor(4, b);
1904 aDlg->SetIntValue(1, Edgewidth);
1905 aDlg->SetIntValue(2, intValue);
1906 aDlg->SetIntValue(3, int(Shrink*100.));
1908 QColor color = aDlg->GetColor(1);
1909 QColor edgecolor = aDlg->GetColor(2);
1910 QColor nodecolor = aDlg->GetColor(3);
1911 QColor backfacecolor = aDlg->GetColor(4);
1912 /* actor color and backface color */
1913 theActor->SetSufaceColor(float (color.red()) / 255.,
1914 float (color.green()) / 255.,
1915 float (color.blue()) / 255.);
1916 theActor->SetBackSufaceColor(float (backfacecolor.red()) / 255.,
1917 float (backfacecolor.green()) / 255.,
1918 float (backfacecolor.blue()) / 255.);
1921 theActor->SetEdgeColor(float (edgecolor.red()) / 255.,
1922 float (edgecolor.green()) / 255.,
1923 float (edgecolor.blue()) / 255.);
1925 /* Shrink factor and size edges */
1926 theActor->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
1927 theActor->SetLineWidth(aDlg->GetIntValue(1));
1929 /* Nodes color and size */
1930 theActor->SetNodeColor(float (nodecolor.red()) / 255.,
1931 float (nodecolor.green()) / 255.,
1932 float (nodecolor.blue()) / 255.);
1933 theActor->SetNodeSize(aDlg->GetIntValue(2));
1940 EmitSignalDeactivateDialog();
1941 SMESHGUI_TransparencyDlg *aDlg = new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(),"",false);
1948 //=============================================================================
1952 //=============================================================================
1953 void SMESHGUI::UpdateView(){
1954 ::RepaintCurrentView();
1957 //=============================================================================
1961 //=============================================================================
1962 void SMESHGUI::DisplayActor(SMESH_Actor * theActor, bool theVisibility){
1963 theActor->SetVisibility(theVisibility);
1964 ::DisplayActor(myActiveStudy->getActiveStudyFrame(),theActor);
1967 //=============================================================================
1971 //=============================================================================
1972 void SMESHGUI::EraseActor(SMESH_Actor * theActor){
1973 theActor->SetVisibility(false);
1976 //=============================================================================
1980 //=============================================================================
1981 bool SMESHGUI::AddActorInSelection(SMESH_Actor * ac)
1983 SALOME_Selection *Sel =
1984 SALOME_Selection::Selection(myActiveStudy->getSelection());
1985 Sel->ClearIObjects();
1987 return Sel->AddIObject(ac->getIO());
1992 //=============================================================================
1996 //=============================================================================
1997 QString SMESHGUI::CheckHomogeneousSelection()
1999 SALOME_Selection *Sel =
2000 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2003 SALOME_ListIteratorOfListIO Itinit(Sel->StoredIObjects());
2004 for (; Itinit.More(); Itinit.Next())
2006 List.Append(Itinit.Value());
2009 QString RefType = CheckTypeObject(Sel->firstIObject());
2010 SALOME_ListIteratorOfListIO It(List);
2011 for (; It.More(); It.Next())
2013 Handle(SALOME_InteractiveObject) IObject = It.Value();
2014 QString Type = CheckTypeObject(IObject);
2015 if (Type.compare(RefType) != 0)
2016 return "Heterogeneous Selection";
2019 Sel->ClearIObjects();
2020 SALOME_ListIteratorOfListIO It1(List);
2021 for (; It1.More(); It1.Next())
2023 int res = Sel->AddIObject(It1.Value());
2025 myActiveStudy->highlight(It1.Value(), false);
2027 myActiveStudy->highlight(It1.Value(), true);
2032 //=============================================================================
2036 //=============================================================================
2037 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject) & IO)
2039 SALOMEDS::SObject_var sobj = smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->getEntry());
2040 if (!sobj->_is_nil()) {
2041 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
2042 if (strcmp(scomp->GetID(), IO->getEntry()) == 0)
2043 { // component is selected
2048 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2049 Sel->ClearIObjects();
2051 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter(HYPOTHESIS);
2052 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter(ALGORITHM);
2053 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter(MESH);
2054 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter(SUBMESH);
2055 Handle(SMESH_TypeFilter) aGroupFilter = new SMESH_TypeFilter(GROUP);
2056 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter = new SMESH_TypeFilter(MESHorSUBMESH);
2057 Handle(SMESH_TypeFilter) aSubMeshVextexFilter = new SMESH_TypeFilter(SUBMESH_VERTEX);
2058 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter = new SMESH_TypeFilter(SUBMESH_EDGE);
2059 Handle(SMESH_TypeFilter) aSubMeshFaceFilter = new SMESH_TypeFilter(SUBMESH_FACE);
2060 Handle(SMESH_TypeFilter) aSubMeshSolidFilter = new SMESH_TypeFilter(SUBMESH_SOLID);
2061 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter = new SMESH_TypeFilter(SUBMESH_COMPOUND);
2063 Sel->AddFilter(aHypFilter);
2064 if (Sel->AddIObject(IO) != -1) {
2065 Sel->ClearFilters();
2066 return "Hypothesis";
2069 Sel->ClearFilters();
2070 Sel->AddFilter(anAlgoFilter);
2071 if (Sel->AddIObject(IO) != -1) {
2072 Sel->ClearFilters();
2076 Sel->ClearFilters();
2077 Sel->AddFilter(aMeshFilter);
2078 if (Sel->AddIObject(IO) != -1) {
2079 Sel->ClearFilters();
2083 Sel->ClearFilters();
2084 Sel->AddFilter(aSubMeshFilter);
2085 if (Sel->AddIObject(IO) != -1) {
2086 Sel->ClearFilters();
2090 Sel->ClearFilters();
2091 Sel->AddFilter(aGroupFilter);
2092 if (Sel->AddIObject(IO) != -1) {
2093 Sel->ClearFilters();
2097 Sel->ClearFilters();
2098 Sel->AddFilter(aSubMeshVextexFilter);
2099 if (Sel->AddIObject(IO) != -1) {
2100 Sel->ClearFilters();
2101 return "SubMeshVertex";
2104 Sel->ClearFilters();
2105 Sel->AddFilter(aSubMeshEdgeFilter);
2106 if (Sel->AddIObject(IO) != -1) {
2107 Sel->ClearFilters();
2108 return "SubMeshEdge";
2111 Sel->ClearFilters();
2112 Sel->AddFilter(aSubMeshFaceFilter);
2113 if (Sel->AddIObject(IO) != -1) {
2114 Sel->ClearFilters();
2115 return "SubMeshFace";
2118 Sel->ClearFilters();
2119 Sel->AddFilter(aSubMeshSolidFilter);
2120 if (Sel->AddIObject(IO) != -1) {
2121 Sel->ClearFilters();
2122 return "SubMeshSolid";
2125 Sel->ClearFilters();
2126 Sel->AddFilter(aSubMeshCompoundFilter);
2127 if (Sel->AddIObject(IO) != -1) {
2128 Sel->ClearFilters();
2129 return "SubMeshCompound";
2132 Sel->ClearFilters();
2133 Sel->AddIObject(IO);
2138 static int isStudyLocked(const SALOMEDS::Study_var& theStudy){
2139 return theStudy->GetProperties()->IsLocked();
2142 static int checkLock(const SALOMEDS::Study_var& theStudy) {
2143 if (isStudyLocked(theStudy)) {
2144 QAD_MessageBox::warn1 ( (QWidget*)QAD_Application::getDesktop(),
2145 QObject::tr("WRN_WARNING"),
2146 QObject::tr("WRN_STUDY_LOCKED"),
2147 QObject::tr("BUT_OK") );
2153 //=============================================================================
2157 //=============================================================================
2158 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
2160 SALOMEDS::Study_var aStudy = smeshGUI->myActiveStudy->getStudyDocument(); //Document OCAF de l'etude active
2161 // QAD_Viewer3d* v3d;
2162 OCCViewer_Viewer3d *v3d;
2164 Handle(AIS_InteractiveContext) ic;
2165 vtkRenderer *Renderer;
2166 vtkRenderWindow *RenWin;
2168 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_OCC) {
2169 v3d = ((OCCViewer_ViewFrame *) smeshGUI->myActiveStudy->
2170 getActiveStudyFrame()->getRightFrame()->getViewFrame())->getViewer();
2171 ic = v3d->getAISContext();
2173 else if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2174 Renderer = ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2175 getActiveStudyFrame()->getRightFrame()->getViewFrame())->getRenderer();
2176 RenWin = Renderer->GetRenderWindow();
2179 switch (theCommandID) {
2181 if(checkLock(aStudy)) break;
2182 smeshGUI->OnEditDelete();
2189 if(checkLock(aStudy)) break;
2190 //Import_Document(parent, theCommandID); //NBU
2191 Import_Mesh(parent,theCommandID);
2195 case 122: // EXPORT MED
2199 Export_Mesh(parent, theCommandID);
2203 case 200: // SCALAR BAR
2205 SALOME_Selection *Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2206 if( Sel && Sel->IObjectCount() ) {
2207 Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
2208 if( anIO->hasEntry() ) {
2209 if( SMESH_Actor* anActor = ::FindActorByEntry( anIO->getEntry() ) ) {
2210 anActor->SetControlMode( SMESH_Actor::eNone );
2218 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
2219 SMESHGUI_Preferences_ScalarBarDlg::ScalarBarProperties( parent, Sel );
2223 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
2230 smeshGUI->SetViewMode(theCommandID);
2236 if(checkLock(aStudy)) break;
2242 case 301: // DISPLAY
2243 case 302: // DISPLAY ONLY
2245 EDisplaing anAction;
2246 switch(theCommandID){
2247 case 300: anAction = eErase; break;
2248 case 301: anAction = eDisplay; break;
2249 case 302: anAction = eDisplayOnly; break;
2252 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2253 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2254 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2255 for (; It.More(); It.Next()) {
2256 Handle(SALOME_InteractiveObject) IOS = It.Value();
2257 if (IOS->hasEntry()) {
2258 ::UpdateView(anAction,IOS->getEntry());
2262 Sel->ClearIObjects();
2268 if(checkLock(aStudy)) break;
2269 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2270 smeshGUI->EmitSignalDeactivateDialog();
2271 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2272 Sel->ClearIObjects();
2273 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2274 smeshGUI->ViewNodes();
2275 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
2278 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2279 tr("SMESH_WRN_WARNING"),
2280 tr("SMESH_WRN_VIEWER_VTK"),
2281 tr("SMESH_BUT_OK"));
2286 case 2151: // FILTER
2288 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK )
2290 smeshGUI->EmitSignalDeactivateDialog();
2291 SMESHGUI_FilterDlg *aDlg = new SMESHGUI_FilterDlg( parent, SMESH::EDGE );
2296 case 405: // MOVE NODE
2298 if(checkLock(aStudy)) break;
2299 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2300 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2301 SMESHGUI_MoveNodesDlg *aDlg = new SMESHGUI_MoveNodesDlg(parent, "", Sel);
2305 case 701: // COMPUTE MESH
2307 if(checkLock(aStudy)) break;
2308 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2309 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2310 int nbSel = Sel->IObjectCount();
2315 SMESH::SMESH_Mesh_var aMesh;
2316 SMESH::SMESH_subMesh_var aSubMesh;
2317 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2318 if (IObject->hasEntry()){
2319 SALOMEDS::SObject_var aMeshSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2320 GEOM::GEOM_Shape_var aShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh( aMeshSObj );
2321 if ( aShape->_is_nil() ) {
2325 SALOMEDS::GenericAttribute_var anAttr;
2326 if(!aMeshSObj->_is_nil() && aMeshSObj->FindAttribute(anAttr, "AttributeIOR")){
2327 SALOMEDS::AttributeIOR_var anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2328 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : IOR = "<< anIOR->Value());
2329 CORBA::Object_var anObj;
2331 anObj = _orb->string_to_object(anIOR->Value());
2332 if (CORBA::is_nil(anObj)){
2333 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : nil object");
2335 }catch(CORBA::COMM_FAILURE & ex){
2336 INFOS("SMESHGUI::OnGUIEvent - Compute mesh : exception (1)");
2338 aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
2339 aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
2340 if (!aMesh->_is_nil()){
2341 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMeshSObj);
2342 if (!refShape->_is_nil()) {
2343 if(!smeshGUI->myComponentMesh->IsReadyToCompute(aMesh,refShape)){
2344 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2345 tr("SMESH_WRN_WARNING"),
2346 tr("SMESH_WRN_MISSING_PARAMETERS"),
2347 tr("SMESH_BUT_OK"));
2351 if (smeshGUI->myComponentMesh->Compute(aMesh,refShape))
2352 smeshGUI->myStudyAPI.ModifiedMesh(aMeshSObj,true);
2353 // TO Do : change icon of all submeshes
2355 catch(const SALOME::SALOME_Exception & S_ex){
2356 QtCatchCorbaException(S_ex);
2359 }else if(!aSubMesh->_is_nil()){
2360 aMesh = aSubMesh->GetFather();
2361 GEOM::GEOM_Shape_var refShape = smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(aMeshSObj);
2362 if(!refShape->_is_nil()){
2363 bool compute = smeshGUI->myComponentMesh->IsReadyToCompute(aMesh,refShape);
2365 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2366 tr("SMESH_WRN_WARNING"),
2367 tr("SMESH_WRN_MISSING_PARAMETERS"),
2368 tr("SMESH_BUT_OK"));
2372 if ( smeshGUI->myComponentMesh->Compute(aMesh,refShape) )
2373 smeshGUI->myStudyAPI.ModifiedMesh(aMeshSObj,true);
2374 // TO Do : change icon of all submeshes
2375 }catch(const SALOME::SALOME_Exception & S_ex){
2376 QtCatchCorbaException(S_ex);
2382 CORBA::Long anId = smeshGUI->myStudy->StudyId();
2383 TVisualObjPtr aVisualObj = GetVisualObj(anId,IObject->getEntry());
2384 if(smeshGUI->myAutomaticUpdate && aVisualObj){
2385 aVisualObj->Update();
2386 SMESH_Actor* anActor = ::FindActorByEntry(IObject->getEntry());
2388 anActor = ::CreateActor(smeshGUI->myStudy,IObject->getEntry());
2390 ::DisplayActor(smeshGUI->myActiveStudy->getActiveStudyFrame(),anActor); //apo
2396 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2397 tr("SMESH_WRN_WARNING"),
2398 tr("SMESH_WRN_VIEWER_VTK"),
2399 tr("SMESH_BUT_OK"));
2404 case 702: // ADD SUB MESH
2406 if(checkLock(aStudy)) break;
2407 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2408 smeshGUI->EmitSignalDeactivateDialog();
2409 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2410 SMESHGUI_AddSubMeshDlg *aDlg = new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
2413 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2414 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2415 tr("SMESH_BUT_OK"));
2420 case 703: // INIT MESH
2422 if(checkLock(aStudy)) break;
2423 smeshGUI->EmitSignalDeactivateDialog();
2424 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2425 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
2429 case 704: // EDIT Hypothesis
2431 if(checkLock(aStudy)) break;
2432 smeshGUI->EmitSignalDeactivateDialog();
2433 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2434 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2438 case 705: // EDIT Global Hypothesis
2440 if(checkLock(aStudy)) break;
2441 smeshGUI->EmitSignalDeactivateDialog();
2442 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2443 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2447 case 706: // EDIT Local Hypothesis
2449 if(checkLock(aStudy)) break;
2450 smeshGUI->EmitSignalDeactivateDialog();
2451 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2452 SMESHGUI_EditHypothesesDlg *aDlg = new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2456 case 406: // ORIENTATION ELEMENTS
2458 if(checkLock(aStudy)) break;
2459 smeshGUI->EmitSignalDeactivateDialog();
2460 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2461 smeshGUI->myDesktop->SetSelectionMode(FaceSelection, true);
2462 SMESHGUI_OrientationElementsDlg *aDlg = new SMESHGUI_OrientationElementsDlg(parent, "", Sel);
2466 case 407: // DIAGONAL INVERSION
2468 if(checkLock(aStudy)) break;
2469 smeshGUI->EmitSignalDeactivateDialog();
2470 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2471 Sel->ClearIObjects();
2472 smeshGUI->myDesktop->SetSelectionMode(EdgeOfCellSelection, true);
2473 SMESHGUI_DiagonalInversionDlg *aDlg = new SMESHGUI_DiagonalInversionDlg(parent, "", Sel);
2477 case 801: // CREATE GROUP
2479 if(checkLock(aStudy)) break;
2480 smeshGUI->EmitSignalDeactivateDialog();
2481 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2482 int nbSel = Sel->IObjectCount();
2484 // check if mesh is selected
2485 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2486 if (IObject->hasEntry()) {
2487 SALOMEDS::SObject_var aMeshSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2488 if (!aMeshSObj->_is_nil()) {
2489 CORBA::Object_var anObj = aMeshSObj->GetObject();
2490 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow(anObj);
2491 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(anObj);
2492 if (aMesh->_is_nil() && !aSubMesh->_is_nil()) {
2493 aMesh = aSubMesh->GetFather();
2495 if (!aMesh->_is_nil()) {
2496 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aMesh);
2505 case 802: // CONSTRUCT GROUP
2507 if(checkLock(aStudy)) break;
2508 smeshGUI->EmitSignalDeactivateDialog();
2509 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2510 int nbSel = Sel->IObjectCount();
2512 // check if submesh is selected
2513 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2514 if (IObject->hasEntry()) {
2515 SALOMEDS::SObject_var aSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2516 if(!aSObj->_is_nil()) {
2517 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(aSObj->GetObject());
2518 if (!aSubMesh->_is_nil()) {
2520 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
2521 // get submesh elements list by types
2522 SMESH::long_array_var aNodes = aSubMesh->GetElementsByType(SMESH::NODE);
2523 SMESH::long_array_var aEdges = aSubMesh->GetElementsByType(SMESH::EDGE);
2524 SMESH::long_array_var aFaces = aSubMesh->GetElementsByType(SMESH::FACE);
2525 SMESH::long_array_var aVolumes = aSubMesh->GetElementsByType(SMESH::VOLUME);
2526 // create group for each type o elements
2527 QString aName = IObject->getName();
2528 MESSAGE("SMESHGUI::OnGUIEvent - Construct group on submesh : "<<aName);
2529 MESSAGE(" Number of elements : nodes "<<aNodes->length() << ", edges " << aEdges->length()
2530 << ", faces " << aFaces->length() << ", volumes " << aVolumes->length());
2531 if (aNodes->length() > 0) {
2532 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::NODE, aName);
2533 aGroup->Add(aNodes);
2535 if (aEdges->length() > 0) {
2536 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::EDGE, aName);
2537 aGroup->Add(aEdges);
2539 if (aFaces->length() > 0) {
2540 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::FACE, aName);
2541 aGroup->Add(aFaces);
2543 if (aVolumes->length() > 0) {
2544 SMESH::SMESH_Group_var aGroup = smeshGUI->AddGroup(aMesh, SMESH::VOLUME, aName);
2545 aGroup->Add(aVolumes);
2547 smeshGUI->myActiveStudy->updateObjBrowser(true);
2548 }catch(const SALOME::SALOME_Exception & S_ex){
2549 QtCatchCorbaException(S_ex);
2558 case 803: // EDIT GROUP
2560 if(checkLock(aStudy)) break;
2561 smeshGUI->EmitSignalDeactivateDialog();
2562 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2563 int nbSel = Sel->IObjectCount();
2565 // check if group is selected
2566 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2567 if (IObject->hasEntry()) {
2568 SALOMEDS::SObject_var aSObj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2569 if(!aSObj->_is_nil()) {
2570 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow(aSObj->GetObject());
2571 if (!aGroup->_is_nil()) {
2572 SMESHGUI_GroupDlg *aDlg = new SMESHGUI_GroupDlg(parent, "", Sel, aGroup);
2581 case 804: // Add elements to group
2583 if(checkLock(aStudy)) break;
2584 if (smeshGUI->myState == 800) {
2585 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) smeshGUI->myActiveDialogBox;
2586 if (aDlg) aDlg->onAdd();
2591 case 805: // Remove elements from group
2593 if(checkLock(aStudy)) break;
2594 if (smeshGUI->myState == 800) {
2595 SMESHGUI_GroupDlg *aDlg = (SMESHGUI_GroupDlg*) smeshGUI->myActiveDialogBox;
2596 if (aDlg) aDlg->onRemove();
2601 case 900: // MESH INFOS
2603 smeshGUI->EmitSignalDeactivateDialog();
2604 SMESHGUI_MeshInfosDlg *aDlg = new SMESHGUI_MeshInfosDlg(parent, "", false);
2608 case 1001: // AUTOMATIC UPDATE PREFERENCES
2610 parent->menuBar()->setItemChecked(1001, !parent->menuBar()->isItemChecked(1001));
2611 if (parent->menuBar()->isItemChecked(1001)) {
2612 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
2613 smeshGUI->myAutomaticUpdate = true;
2616 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
2617 smeshGUI->myAutomaticUpdate = false;
2622 case 1003: // MESH PREFERENCES
2624 smeshGUI->SetDisplaySettings();
2630 SMESHGUI_Preferences_ScalarBarDlg::ScalarBarPreferences( parent );
2636 SMESHGUI_Preferences_SelectionDlg* aDlg =
2637 new SMESHGUI_Preferences_SelectionDlg(parent);
2640 QString SCr, SCg, SCb;
2641 SCr = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorRed");
2642 SCg = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorGreen");
2643 SCb = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectColorBlue");
2644 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2645 aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2646 else aColor = Qt::cyan;
2647 aDlg->SetColor(1, aColor);
2649 SCr = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorRed");
2650 SCg = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorGreen");
2651 SCb = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectColorBlue");
2652 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2653 aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2654 else aColor = Qt::yellow;
2655 aDlg->SetColor(2, aColor);
2657 SCr = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorRed");
2658 SCg = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorGreen");
2659 SCb = QAD_CONFIG->getSetting("SMESH:SettingsSelectColorBlue");
2660 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
2661 aColor = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
2662 else aColor = Qt::white;
2663 aDlg->SetColor(3, aColor);
2665 QString SW1 = QAD_CONFIG->getSetting("SMESH:SettingsPreSelectWidth");
2666 if (SW1.isEmpty()) SW1 = "5";
2667 aDlg->SetWidth(1, SW1.toInt());
2669 QString SW2 = QAD_CONFIG->getSetting("SMESH:SettingsItemSelectWidth");
2670 if (SW2.isEmpty()) SW2 = "5";
2671 aDlg->SetWidth(2, SW2.toInt());
2673 QString SP1 = QAD_CONFIG->getSetting("SMESH:SettingsNodeSelectTol");
2674 if (SP1.isEmpty()) SP1 = "0.025";
2675 aDlg->SetPrecision(1, SP1.toDouble());
2677 QString SP2 = QAD_CONFIG->getSetting("SMESH:SettingsElementsSelectTol");
2678 if (SP2.isEmpty()) SP2 = "0.001";
2679 aDlg->SetPrecision(2, SP2.toDouble());
2682 QColor aPreColor = aDlg->GetColor(1);
2683 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorRed", aPreColor.red());
2684 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorGreen", aPreColor.green());
2685 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectColorBlue", aPreColor.blue());
2687 QColor aSelColor = aDlg->GetColor(2);
2688 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorRed", aSelColor.red());
2689 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorGreen", aSelColor.green());
2690 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectColorBlue", aSelColor.blue());
2692 QColor aHiColor = aDlg->GetColor(3);
2693 QAD_CONFIG->addSetting("SMESH:SettingsSelectColorRed", aHiColor.red());
2694 QAD_CONFIG->addSetting("SMESH:SettingsSelectColorGreen", aHiColor.green());
2695 QAD_CONFIG->addSetting("SMESH:SettingsSelectColorBlue", aHiColor.blue());
2697 int aPreWidth = aDlg->GetWidth(1);
2698 QAD_CONFIG->addSetting("SMESH:SettingsPreSelectWidth", aPreWidth);
2699 int aSelWidth = aDlg->GetWidth(2);
2700 QAD_CONFIG->addSetting("SMESH:SettingsItemSelectWidth", aSelWidth);
2702 double aTolNodes = aDlg->GetPrecision(1);
2703 QAD_CONFIG->addSetting("SMESH:SettingsNodeSelectTol", aTolNodes);
2704 double aTolItems = aDlg->GetPrecision(2);
2705 QAD_CONFIG->addSetting("SMESH:SettingsElementsSelectTol", aTolItems);
2707 // update current study settings
2708 ::UpdateSelectionProp();
2710 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
2711 if (studyFrame->getTypeView() == VIEW_VTK) {
2712 VTKViewer_ViewFrame* aViewFrame = GetVtkViewFrame(studyFrame);
2713 // update VTK viewer properties
2714 VTKViewer_RenderWindowInteractor* anInteractor = aViewFrame->getRWInteractor();
2716 anInteractor->SetSelectionProp(aSelColor.red()/255., aSelColor.green()/255.,
2717 aSelColor.blue()/255., aSelWidth);
2718 anInteractor->SetSelectionTolerance(aTolNodes, aTolItems);
2719 VTKViewer_InteractorStyleSALOME* aStyle = anInteractor->GetInteractorStyleSALOME();
2721 aStyle->setPreselectionProp(aPreColor.red()/255., aPreColor.green()/255.,
2722 aPreColor.blue()/255., aPreWidth);
2725 vtkRenderer* aRenderer = aViewFrame->getRenderer();
2726 vtkActorCollection *aCollection = aRenderer->GetActors();
2727 aCollection->InitTraversal();
2728 while(vtkActor *anAct = aCollection->GetNextActor()){
2729 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
2730 anActor->SetHighlightColor(aHiColor.red()/255., aHiColor.green()/255.,
2731 aHiColor.blue()/255.);
2732 anActor->SetPreHighlightColor(aPreColor.red()/255., aPreColor.green()/255.,
2733 aPreColor.blue()/255.);
2742 case 1100: // EDIT HYPOTHESIS
2744 if(checkLock(aStudy)) break;
2745 SALOME_Selection *Sel =
2746 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2747 int nbSel = Sel->IObjectCount();
2750 Standard_Boolean res;
2751 SMESH::SMESH_Hypothesis_var Hyp =
2752 smeshGUI->ConvertIOinSMESHHypothesis(Sel->firstIObject(), res);
2754 /* Look for all mesh objects that have this hypothesis affected in order to flag as ModifiedMesh */
2755 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2756 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2759 char* sName = Hyp->GetName();
2760 SMESHGUI_GenericHypothesisCreator* aCreator = smeshGUI->GetHypothesisCreator(sName);
2763 aCreator->EditHypothesis(Hyp);
2774 case 1101: // RENAME
2776 if(checkLock(aStudy)) break;
2777 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2778 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2779 for (; It.More(); It.Next()) {
2780 Handle(SALOME_InteractiveObject) IObject = It.Value();
2782 SALOMEDS::SObject_var obj = smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2783 SALOMEDS::GenericAttribute_var anAttr;
2784 SALOMEDS::AttributeName_var aName;
2785 if (!obj->_is_nil()) {
2786 if (obj->FindAttribute(anAttr, "AttributeName")) {
2787 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2788 QString newName = QString(aName->Value());
2789 newName = SALOMEGUI_NameDlg::getName(QAD_Application::getDesktop(), newName);
2790 if (!newName.isEmpty()) {
2791 smeshGUI->myActiveStudy->renameIObject(IObject, newName);
2799 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2801 if(checkLock(aStudy)) break;
2803 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2804 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2805 for (int i = 0; It.More(); It.Next(), i++) {
2806 Handle(SALOME_InteractiveObject) IObject = It.Value();
2807 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh(IObject);
2809 Sel->ClearIObjects();
2810 smeshGUI->myActiveStudy->updateObjBrowser(true);
2814 case 401: // GEOM::EDGE
2816 if(checkLock(aStudy)) break;
2817 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2818 smeshGUI->EmitSignalDeactivateDialog();
2819 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2820 Sel->ClearIObjects();
2821 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2822 smeshGUI->ViewNodes();
2823 SMESHGUI_AddEdgeDlg *aDlg = new SMESHGUI_AddEdgeDlg(parent, "", Sel);
2826 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2827 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2828 tr("SMESH_BUT_OK"));
2832 case 4021: // TRIANGLE
2834 if(checkLock(aStudy)) break;
2835 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2836 smeshGUI->EmitSignalDeactivateDialog();
2837 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2838 Sel->ClearIObjects();
2839 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2840 smeshGUI->ViewNodes();
2841 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg(parent, "", Sel, 3);
2844 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2845 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2846 tr("SMESH_BUT_OK"));
2852 if(checkLock(aStudy)) break;
2853 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2854 smeshGUI->EmitSignalDeactivateDialog();
2855 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2856 Sel->ClearIObjects();
2857 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2858 smeshGUI->ViewNodes();
2859 SMESHGUI_AddFaceDlg *aDlg = new SMESHGUI_AddFaceDlg(parent, "", Sel, 4);
2863 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2864 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2865 tr("SMESH_BUT_OK"));
2871 if(checkLock(aStudy)) break;
2872 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2873 smeshGUI->EmitSignalDeactivateDialog();
2874 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2875 Sel->ClearIObjects();
2876 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2877 smeshGUI->ViewNodes();
2878 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg(parent, "", Sel, 4);
2881 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2882 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2883 tr("SMESH_BUT_OK"));
2889 if(checkLock(aStudy)) break;
2890 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2891 smeshGUI->EmitSignalDeactivateDialog();
2892 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2893 Sel->ClearIObjects();
2894 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2895 smeshGUI->ViewNodes();
2896 SMESHGUI_AddVolumeDlg *aDlg = new SMESHGUI_AddVolumeDlg(parent, "", Sel, 8);
2899 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2900 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2901 tr("SMESH_BUT_OK"));
2906 case 4041: // REMOVES NODES
2908 if(checkLock(aStudy)) break;
2909 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2910 smeshGUI->EmitSignalDeactivateDialog();
2911 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2912 Sel->ClearIObjects();
2913 smeshGUI->myDesktop->SetSelectionMode(NodeSelection, true);
2914 smeshGUI->ViewNodes();
2915 SMESHGUI_RemoveNodesDlg *aDlg = new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
2918 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2919 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2920 tr("SMESH_BUT_OK"));
2924 case 4042: // REMOVES ELEMENTS
2926 if(checkLock(aStudy)) break;
2927 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK) {
2928 smeshGUI->EmitSignalDeactivateDialog();
2929 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2930 Sel->ClearIObjects();
2931 smeshGUI->myDesktop->SetSelectionMode(CellSelection, true);
2932 SMESHGUI_RemoveElementsDlg *aDlg = new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
2936 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2937 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2938 tr("SMESH_BUT_OK"));
2943 case 5000: // HYPOTHESIS
2945 if(checkLock(aStudy)) break;
2946 smeshGUI->EmitSignalDeactivateDialog();
2947 SMESHGUI_CreateHypothesesDlg *aDlg =
2948 new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, false);
2953 if(checkLock(aStudy)) break;
2954 smeshGUI->EmitSignalDeactivateDialog();
2955 SMESHGUI_CreateHypothesesDlg *aDlg =
2956 new SMESHGUI_CreateHypothesesDlg (parent, "", FALSE, true);
2960 case 6016: // CONTROLS
2969 if ( smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK ) {
2970 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
2971 if ( Sel->IObjectCount() == 1 && Sel->firstIObject()->hasEntry() ) {
2972 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( Sel->firstIObject()->getEntry() );
2973 if ( !SO->_is_nil() ) {
2974 CORBA::Object_var aObject = SO->GetObject();
2975 SMESH::SMESH_Mesh_var aMesh = SMESH::SMESH_Mesh::_narrow( aObject );
2976 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow( aObject );
2977 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group::_narrow( aObject );
2978 if ( !aMesh->_is_nil() || !aSubMesh->_is_nil() || !aGroup->_is_nil() ) {
2979 smeshGUI->Control( theCommandID );
2984 QAD_MessageBox::warn1(smeshGUI->GetDesktop(),
2985 tr( "SMESH_WRN_WARNING" ),
2986 tr( "SMESH_BAD_SELECTION" ),
2987 tr( "SMESH_BUT_OK" ) );
2991 QAD_MessageBox::warn1(smeshGUI->GetDesktop(),
2992 tr( "SMESH_WRN_WARNING" ),
2993 tr( "NOT_A_VTK_VIEWER" ),
2994 tr( "SMESH_BUT_OK" ) );
2999 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3000 if (Sel->IObjectCount() == 1) {
3001 Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
3002 if(anIObject->hasEntry())
3003 if(SMESH_Actor *anActor = ::FindActorByEntry(anIObject->getEntry())){
3004 anActor->SetPointsLabeled( !anActor->GetPointsLabeled() );
3011 SALOME_Selection *Sel = SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3012 if (Sel->IObjectCount() == 1) {
3013 Handle(SALOME_InteractiveObject) anIObject = Sel->firstIObject();
3014 if(anIObject->hasEntry())
3015 if(SMESH_Actor *anActor = ::FindActorByEntry(anIObject->getEntry())){
3016 anActor->SetCellsLabeled( !anActor->GetCellsLabeled() );
3021 case 10001: // DISPLAY MODE PREFERENCE
3024 parent->menuBar()->setItemChecked(10001, true);
3025 parent->menuBar()->setItemChecked(10002, false);
3026 parent->menuBar()->setItemChecked(10004, false);
3027 parent->menuBar()->setItemEnabled(10003, true);
3028 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
3033 parent->menuBar()->setItemChecked(10002, true);
3034 parent->menuBar()->setItemChecked(10001, false);
3035 parent->menuBar()->setItemChecked(10004, false);
3036 parent->menuBar()->setItemEnabled(10003, true);
3037 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3042 parent->menuBar()->setItemChecked(10003,!parent->menuBar()->isItemChecked(10003));
3043 QAD_CONFIG->addSetting("SMESH:Shrink", parent->menuBar()->isItemChecked(10003) ? "yes" : "no");
3048 parent->menuBar()->setItemChecked(10001, false);
3049 parent->menuBar()->setItemChecked(10004, true);
3050 parent->menuBar()->setItemChecked(10002, false);
3051 parent->menuBar()->setItemEnabled(10003, false);
3052 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Nodes");
3058 smeshGUI->myActiveStudy->updateObjBrowser(true);
3062 //=============================================================================
3063 /*! function : GetMeshesUsingAlgoOrHypothesis()
3064 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
3065 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
3067 //=============================================================================
3068 SALOMEDS::Study::ListOfSObject *
3069 SMESHGUI::GetMeshesUsingAlgoOrHypothesis(SMESH::
3070 SMESH_Hypothesis_ptr AlgoOrHyp)
3072 SALOMEDS::Study::ListOfSObject_var listSOmesh =
3073 new SALOMEDS::Study::ListOfSObject;
3074 listSOmesh->length(0);
3075 unsigned int index = 0;
3076 if (!AlgoOrHyp->_is_nil()) {
3077 SALOMEDS::SObject_var SO_Hypothesis =
3078 smeshGUI->GetStudyAPI().FindObject(AlgoOrHyp);
3079 if (!SO_Hypothesis->_is_nil()) {
3080 SALOMEDS::Study::ListOfSObject_var listSO =
3081 smeshGUI->myStudy->FindDependances(SO_Hypothesis);
3082 MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency number ="<<listSO->length());
3083 for (unsigned int i = 0; i < listSO->length(); i++) {
3084 SALOMEDS::SObject_ptr SO = listSO[i];
3085 if (!SO->_is_nil()) {
3086 SALOMEDS::SObject_var aFather = SO->GetFather();
3087 if (!aFather->_is_nil()) {
3088 SALOMEDS::SObject_var SOfatherFather = aFather->GetFather();
3089 if (!SOfatherFather->_is_nil()) {
3090 MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): dependency added to list");
3092 listSOmesh->length(index);
3093 listSOmesh[index - 1] = SOfatherFather;
3100 MESSAGE("SMESHGUI::GetMeshesUsingAlgoOrHypothesis(): completed");
3101 return listSOmesh._retn();
3104 //=============================================================================
3108 //=============================================================================
3109 void SMESHGUI::Import_Mesh(QAD_Desktop * parent, int theCommandID){
3113 if(theCommandID == 113){
3114 filter = tr("MED files (*.med)");
3115 }else if (theCommandID == 112){
3116 filter = tr("IDEAS files (*.unv)");
3117 }else if (theCommandID == 111){
3118 filter = tr("DAT files (*.dat)");
3120 QString filename = QAD_FileDlg::getFileName(parent,
3125 if(!filename.isEmpty()){
3127 SMESH::mesh_array_var aMeshes;
3129 SMESH::DriverMED_ReadStatus res;
3130 aMeshes = smeshGUI->myComponentMesh->CreateMeshesFromMED(filename.latin1(),
3132 if ( res > SMESH::DRS_OK ) {
3134 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3135 tr("SMESH_WRN_WARNING"),
3136 tr(QString("SMESH_DRS_%1").arg(res)),
3137 tr("SMESH_BUT_OK"));
3142 catch (const SALOME::SALOME_Exception& S_ex)
3145 QtCatchCorbaException(S_ex);
3148 for ( int i = 0, n = aMeshes->length(); i < n; i++ ) {
3149 SALOMEDS::SObject_var aMeshSO = smeshGUI->myStudyAPI.FindObject( aMeshes[i] );
3150 if ( !aMeshSO->_is_nil() ) {
3151 SALOMEDS::StudyBuilder_var aBuilder = smeshGUI->myStudy->NewBuilder();
3152 SALOMEDS::AttributePixMap_var aPixmap = SALOMEDS::AttributePixMap::_narrow( aBuilder->FindOrCreateAttribute( aMeshSO, "AttributePixMap" ) );
3153 aPixmap->SetPixMap( "ICON_SMESH_TREE_MESH_IMPORTED" );
3159 //=============================================================================
3163 //=============================================================================
3164 void SMESHGUI::Export_Mesh(QAD_Desktop * parent, int theCommandID)
3166 SALOME_Selection *Sel =
3167 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3168 int nbSel = Sel->IObjectCount();
3171 Standard_Boolean res;
3172 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3173 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(IObject, res);
3174 if ( res && ( nbSel == 1 || theCommandID == 122 ) ) {// MED export supports multiple meshes
3175 QString aFilter, aTitle = tr("Export mesh");
3176 switch ( theCommandID ) {
3178 aFilter = tr("MED files (*.med)");
3181 aFilter = tr("DAT files (*.dat)");
3184 aFilter = tr("IDEAS files (*.unv)");
3190 QString filename = QAD_FileDlg::getFileName(parent, "", aFilter, aTitle, false);
3192 if ( !filename.isEmpty() ) {
3193 // Check whether the file already exists and delete it if yes
3194 QFile aFile( filename );
3195 if ( aFile.exists() )
3199 for ( SALOME_ListIteratorOfListIO it( Sel->StoredIObjects() ); it.More(); it.Next() ) {
3200 aMesh = smeshGUI->ConvertIOinMesh( it.Value(), res );
3202 switch ( theCommandID ) {
3204 aMesh->ExportMED( filename.latin1(), true ); // currently, automatic groups are always created
3207 aMesh->ExportDAT( filename.latin1() );
3210 aMesh->ExportUNV( filename.latin1() );
3221 //=============================================================================
3225 //=============================================================================
3226 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3227 QAD_StudyFrame * studyFrame)
3232 //=============================================================================
3236 //=============================================================================
3237 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3238 QAD_StudyFrame * studyFrame)
3243 //=============================================================================
3247 //=============================================================================
3248 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3249 QAD_StudyFrame * studyFrame)
3254 //=============================================================================
3258 //=============================================================================
3259 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3261 MESSAGE("SMESHGUI::SetSettings.");
3262 SMESHGUI::GetOrCreateSMESHGUI(parent);
3265 QString DisplayMode = "Shading";
3266 if ( QAD_CONFIG->hasSetting("SMESH:DisplayMode") )
3267 DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3269 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3271 bool Shrink = false;
3272 if ( QAD_CONFIG->hasSetting("SMESH:Shrink") )
3273 Shrink = QAD_CONFIG->getSetting("SMESH:Shrink") == "yes";
3275 if (DisplayMode == "Wireframe") {
3277 parent->menuBar()->setItemChecked(10004, false);
3278 parent->menuBar()->setItemChecked(10002, false);
3279 parent->menuBar()->setItemChecked(10001, true);
3280 parent->menuBar()->setItemEnabled(10003, true);
3282 else if (DisplayMode == "Nodes") {
3284 parent->menuBar()->setItemChecked(10004, true);
3285 parent->menuBar()->setItemChecked(10002, false);
3286 parent->menuBar()->setItemChecked(10001, false);
3287 parent->menuBar()->setItemEnabled(10003, false);
3290 // default is shading
3291 parent->menuBar()->setItemChecked(10004, false);
3292 parent->menuBar()->setItemChecked(10002, true);
3293 parent->menuBar()->setItemChecked(10001, false);
3294 parent->menuBar()->setItemEnabled(10003, true);
3296 parent->menuBar()->setItemChecked(10003, Shrink);
3298 /* Automatic Update */
3299 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3300 if (AutoUpdate.compare("true") == 0) {
3301 parent->menuBar()->setItemChecked(1001, true);
3302 smeshGUI->myAutomaticUpdate = true;
3305 parent->menuBar()->setItemChecked(1001, false);
3306 smeshGUI->myAutomaticUpdate = false;
3310 ::UpdateSelectionProp();
3313 parent->menuBar()->setItemEnabled(111, false); // IMPORT DAT
3314 parent->menuBar()->setItemEnabled(112, false); // IMPORT UNV
3319 //=============================================================================
3323 //=============================================================================
3324 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent, QString & theObject)
3326 // NRI : Temporary added
3327 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3328 // theObject = "NothingSelected";
3329 // theContext = "NothingSelected";
3333 SALOME_Selection *Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3334 int nbSel = Sel->IObjectCount();
3337 theObject = "NothingSelected";
3338 theContext = "NothingSelected";
3341 if ( smeshGUI->myState == 800 && Sel->HasIndex( Sel->firstIObject() ) )
3342 theObject = "Elements";
3344 theObject = smeshGUI->CheckTypeObject( Sel->firstIObject() );
3348 theObject = smeshGUI->CheckHomogeneousSelection();
3353 //=============================================================================
3357 //=============================================================================
3358 bool SMESHGUI::CustomPopup(QAD_Desktop* parent, QPopupMenu* popup, const QString& theContext,
3359 const QString& theParent, const QString& theObject)
3361 // get active study frame
3362 QAD_StudyFrame* studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3364 // get parent component which selected object(s) belongs to
3365 QString parentComp = ( (SALOMEGUI_Desktop*)parent )->getComponentFromSelection();
3368 SALOME_Selection* Sel = SALOME_Selection::Selection( smeshGUI->myActiveStudy->getSelection() );
3369 int nbSel = Sel->IObjectCount();
3374 else if ( nbSel == 1 ) {
3375 if ( parentComp != parent->getActiveComponent() ) {
3376 // object not belongs to SMESH module - remove all commands except common Display/Erase...
3378 int id = popup->idAt( 0 );
3379 if ( id <= QAD_TopLabel_Popup_ID )
3380 popup->removeItemAt( 0 );
3386 // get selected interactive object
3387 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3388 SALOMEDS::SObject_var SO = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
3389 // find popup menu's TopLabel item
3390 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
3391 if ( topItem >= 0 ) {
3392 if ( theParent == "Viewer" ) {
3393 // set bold font for popup menu's TopLabel item (Viewer popup)
3394 QFont fnt = QApplication::font(); fnt.setBold( TRUE );
3395 popup->removeItem( QAD_TopLabel_Popup_ID );
3396 popup->insertItem( new CustomItem( QString( IObject->getName() ), fnt ), QAD_TopLabel_Popup_ID, topItem );
3398 else if ( theParent == "ObjectBrowser" ) {
3399 // remove popup menu's TopLabel item (Object Browser popup)
3400 popup->removeItem( QAD_TopLabel_Popup_ID );
3404 // remove "Display only" command for component object
3405 if ( theObject.compare( "Component" ) == 0 ) {
3406 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3408 else if ( theObject == "Hypothesis" || theObject == "Algorithm" ) {
3409 // remove Display/Erase commands
3410 popup->removeItem( QAD_Display_Popup_ID );
3411 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3412 popup->removeItem( QAD_Erase_Popup_ID );
3413 // remove "Unassign ..." command if hyp/algo is not assigned
3414 if ( SO->_is_nil() || !IObject->hasReference()/* !IsReferencedObject( SO ) */)
3415 popup->removeItem( 1102 );
3417 else if ( theObject == "Mesh" || theObject == "SubMesh" || theObject == "Group" ) {
3419 GEOM::GEOM_Shape_var aShape = GetSMESHGUI()->GetStudyAPI().GetShapeOnMeshOrSubMesh( SO );
3420 if ( aShape->_is_nil() ) {
3422 popup->removeItem( 701 ); // Compute
3423 popup->removeItem( 705 ); // Edit hypothesis
3424 popup->removeItem( 706 ); // ...
3426 SMESH_Actor* ac = ::FindActorByEntry(IObject->getEntry());
3427 // if object has actor
3428 if ( ac && studyFrame->getTypeView() == VIEW_VTK ) {
3429 VTKViewer_RenderWindowInteractor* myRenderInter =
3430 ( ( VTKViewer_ViewFrame* ) studyFrame->getRightFrame()->getViewFrame() )->getRWInteractor();
3431 if ( myRenderInter->isVisible( IObject ) ) {
3432 popup->removeItem( QAD_Display_Popup_ID );
3433 popup->setItemChecked( 9010, ac->GetPointsLabeled() ); // Numbering / Display Nodes #
3434 popup->setItemChecked( 9011, ac->GetCellsLabeled() ); // Numbering / Display Elements #
3435 TVisualObjPtr aVisualObj = ac->GetObject();
3436 int aNbEdges = aVisualObj->GetNbEntities(SMESH::EDGE);
3437 int aNbFaces = aVisualObj->GetNbEntities(SMESH::FACE);
3438 int aNbVolumes = aVisualObj->GetNbEntities(SMESH::VOLUME);
3439 QMenuItem* mi = popup->findItem( 1131 );
3440 if ( mi && mi->popup() ) {
3441 int prType = ac->GetRepresentation();
3442 // Display Mode / Wireframe
3443 if(!aNbFaces && !aNbVolumes && !aNbEdges){
3444 mi->popup()->removeItem( 211 );
3446 mi->popup()->setItemChecked( 211, prType == SMESH_Actor::eEdge );
3448 // Display Mode / Shading
3449 if(!aNbFaces && !aNbVolumes){
3450 mi->popup()->removeItem( 212 );
3452 mi->popup()->setItemChecked( 212, prType == SMESH_Actor::eSurface );
3454 // Display Mode / Points
3455 mi->popup()->setItemChecked( 215, prType == SMESH_Actor::ePoint );
3456 // Display Mode / Shrink
3457 bool isShrunk = ac->IsShrunk();
3458 bool isShrunkable = ac->IsShrunkable();
3459 mi->popup()->setItemChecked( 213, isShrunk );
3460 mi->popup()->setItemEnabled( 213, prType != SMESH_Actor::ePoint && isShrunkable);
3463 mi = popup->findItem( 2000 );
3464 if ( mi && mi->popup() ) {
3465 SMESH_Actor::eControl cMode = ac->GetControlMode();
3467 case SMESH_Actor::eLengthEdges:
3468 mi->popup()->setItemChecked( 6001, true ); break;
3469 case SMESH_Actor::eFreeBorders:
3470 mi->popup()->setItemChecked( 6003, true );
3471 mi->popup()->removeItem( 201 );
3473 case SMESH_Actor::eMultiConnection:
3474 mi->popup()->setItemChecked( 6004, true ); break;
3475 case SMESH_Actor::eArea:
3476 mi->popup()->setItemChecked( 6011, true ); break;
3477 case SMESH_Actor::eTaper:
3478 mi->popup()->setItemChecked( 6012, true ); break;
3479 case SMESH_Actor::eAspectRatio:
3480 mi->popup()->setItemChecked( 6013, true ); break;
3481 case SMESH_Actor::eMinimumAngle:
3482 mi->popup()->setItemChecked( 6014, true ); break;
3483 case SMESH_Actor::eWarping:
3484 mi->popup()->setItemChecked( 6015, true ); break;
3485 case SMESH_Actor::eSkew:
3486 mi->popup()->setItemChecked( 6016, true ); break;
3487 case SMESH_Actor::eNone:
3489 mi->popup()->removeItem( 200 );
3490 mi->popup()->removeItem( 201 );
3493 TVisualObjPtr aVisualObj = ac->GetObject();
3494 SMESH::ElementType aType;
3496 mi->popup()->removeItem( 6001 );
3497 mi->popup()->removeItem( 6003 );
3498 mi->popup()->removeItem( 6004 );
3501 mi->popup()->removeItem( 6011 );
3502 mi->popup()->removeItem( 6012 );
3503 mi->popup()->removeItem( 6013 );
3504 mi->popup()->removeItem( 6014 );
3505 mi->popup()->removeItem( 6015 );
3506 mi->popup()->removeItem( 6016 );
3508 if(!aNbFaces && !aNbEdges)
3509 popup->removeItem( 2000 ); // Scalar Bar
3513 popup->removeItem( QAD_Erase_Popup_ID );
3514 popup->removeItem( 114 ); // Numbering popup menu
3515 popup->removeItem( 1131 ); // Display mode
3516 popup->removeItem( 1132 ); // Color / size
3517 popup->removeItem( 1133 ); // Transparency
3518 popup->removeItem( 2000 ); // Scalar Bar
3522 // object doesn't have actor
3523 CORBA::Object_var anObject = SO->GetObject();
3524 bool bDisplay = false;
3525 if ( !CORBA::is_nil( anObject ) ) {
3526 SMESH::SMESH_Mesh_var aMeshObj = SMESH::SMESH_Mesh::_narrow( anObject );
3527 if ( !aMeshObj->_is_nil() && ( aMeshObj->NbNodes() > 0 || aMeshObj->NbFaces() > 0 || aMeshObj->NbVolumes() > 0 ) )
3529 SMESH::SMESH_subMesh_var aSubMeshObj = SMESH::SMESH_subMesh::_narrow( anObject );
3530 if ( !aSubMeshObj->_is_nil() && ( aSubMeshObj->GetNumberOfNodes() > 0 || aSubMeshObj->GetNumberOfElements() > 0 ) )
3532 SMESH::SMESH_Group_var aGroupObj = SMESH::SMESH_Group::_narrow( anObject );
3533 if ( !aGroupObj->_is_nil() && aGroupObj->Size() > 0 )
3537 popup->removeItem( QAD_Display_Popup_ID );
3538 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3540 popup->removeItem( QAD_Erase_Popup_ID );
3541 popup->removeItem( 114 ); // Numbering popup menu
3542 popup->removeItem( 1131 ); // Display mode
3543 popup->removeItem( 1132 ); // Color / size
3544 popup->removeItem( 1133 ); // Transparency
3545 popup->removeItem( 2000 ); // Scalar Bar
3549 // another SMESH object
3550 popup->removeItem( QAD_Display_Popup_ID );
3551 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3552 popup->removeItem( QAD_Erase_Popup_ID );
3557 // multiple selection
3558 if ( parentComp != parent->getActiveComponent() ) {
3559 // object not belongs to SMESH module - remove all commands except common Display/Erase...
3561 int id = popup->idAt( 0 );
3562 if ( id <= QAD_TopLabel_Popup_ID )
3563 popup->removeItemAt( 0 );
3567 if ( parentComp.isNull() ) {
3568 // objects from different components are selected
3569 popup->removeItem( QAD_DisplayOnly_Popup_ID );
3570 popup->removeItem( QAD_Display_Popup_ID );
3571 popup->removeItem( QAD_Erase_Popup_ID );
3575 QString type = smeshGUI->CheckHomogeneousSelection();
3576 if ( type != "Heterogeneous Selection" ) {
3577 int topItem = popup->indexOf( QAD_TopLabel_Popup_ID );
3578 if ( topItem >= 0 ) {
3579 // set bold font for popup menu's TopLabel item
3580 QFont fnt = QApplication::font(); fnt.setBold( TRUE );
3581 popup->removeItem( QAD_TopLabel_Popup_ID );
3582 popup->insertItem( new CustomItem( QString("%1 ").arg( nbSel ) + type + "(s) ", fnt ), QAD_TopLabel_Popup_ID, topItem );
3590 //=============================================================================
3591 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
3592 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
3594 //=============================================================================
3595 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
3597 if(theIO->hasEntry()){
3598 QAD_Study* aStudy = SMESHGUI::GetSMESHGUI()->GetActiveStudy();
3599 QAD_StudyFrame *aStudyFrame = aStudy->getActiveStudyFrame();
3600 ::UpdateView(aStudyFrame,eDisplay,theIO->getEntry());
3604 //=============================================================================
3608 //=============================================================================
3609 void SMESHGUI::setOrb()
3613 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
3614 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
3618 INFOS("internal error : orb not found");
3621 ASSERT(!CORBA::is_nil(_orb));
3624 //=============================================================================
3628 //=============================================================================
3629 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr theMesh){}
3631 //=============================================================================
3635 //=============================================================================
3636 void SMESHGUI::Dump(SMESH_Actor * Mactor)
3638 vtkUnstructuredGrid *ugrid = Mactor->GetUnstructuredGrid();
3639 vtkPoints *Pts = ugrid->GetPoints();
3640 int nbPts = Pts->GetNumberOfPoints();
3641 int nbCells = ugrid->GetNumberOfCells();
3645 In = fopen("/tmp/dumpMesh", "w+");
3646 fprintf(In, "%d %d\n", nbPts, nbCells);
3647 for (int i = 0; i < nbPts; i++)
3649 float *p = ugrid->GetPoint(i);
3650 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
3653 for (int i = 0; i < nbCells; i++)
3655 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
3656 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
3657 for (j = 0; j < Id->GetNumberOfIds(); j++)
3659 fprintf(In, " %d", Id->GetId(j));
3666 //=============================================================================
3670 //=============================================================================
3671 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr theMesh,
3672 const TColStd_MapOfInteger & MapIndex)
3676 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
3677 CORBA::String_var anEntry = aSobj->GetID();
3678 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
3679 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3680 anArrayOfIdeces->length(MapIndex.Extent());
3681 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
3682 for(int i = 0; ite.More(); ite.Next(), i++){
3683 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
3685 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
3686 aMeshEditor->RemoveNodes(anArrayOfIdeces);
3687 if(myAutomaticUpdate){
3688 CORBA::Long anId = smeshGUI->myStudy->StudyId();
3689 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
3690 aVisualObj->Update(true);
3694 }catch(SALOME::SALOME_Exception& exc) {
3695 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
3696 }catch(const std::exception& exc){
3697 INFOS("Follow exception was cought:\n\t"<<exc.what());
3699 INFOS("Unknown exception was cought !!!");
3703 //=============================================================================
3707 //=============================================================================
3708 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr theMesh,
3709 const TColStd_MapOfInteger & MapIndex)
3713 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
3714 CORBA::String_var anEntry = aSobj->GetID();
3715 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
3716 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
3717 anArrayOfIdeces->length(MapIndex.Extent());
3718 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
3719 for(int i = 0; ite.More(); ite.Next(), i++){
3720 anArrayOfIdeces[i] = anActor->GetElemObjId(ite.Key());
3722 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
3723 aMeshEditor->RemoveElements(anArrayOfIdeces);
3724 if(myAutomaticUpdate){
3725 CORBA::Long anId = smeshGUI->myStudy->StudyId();
3726 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
3727 aVisualObj->Update(true);
3731 }catch(SALOME::SALOME_Exception& exc) {
3732 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
3733 }catch(const std::exception& exc){
3734 INFOS("Follow exception was cought:\n\t"<<exc.what());
3736 INFOS("Unknown exception was cought !!!");
3740 //=============================================================================
3744 //=============================================================================
3745 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
3746 const TColStd_MapOfInteger & MapIndex)
3748 MESSAGE("OrientationElements - not implemeted yet!");
3751 //=============================================================================
3755 //=============================================================================
3756 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
3757 const TColStd_MapOfInteger & MapIndex)
3759 MESSAGE("OrientationElements - not implemeted yet!");
3762 //=====================================================================================
3764 //=====================================================================================
3767 bool OnGUIEvent(int theCommandID, QAD_Desktop * parent)
3769 return SMESHGUI::OnGUIEvent(theCommandID, parent);
3772 bool OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3773 QAD_StudyFrame * studyFrame)
3775 return SMESHGUI::OnKeyPress(pe, parent, studyFrame);
3778 bool OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3779 QAD_StudyFrame * studyFrame)
3781 return SMESHGUI::OnMousePress(pe, parent, studyFrame);
3784 bool OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3785 QAD_StudyFrame * studyFrame)
3787 return SMESHGUI::OnMouseMove(pe, parent, studyFrame);
3790 bool SetSettings(QAD_Desktop * parent)
3792 return SMESHGUI::SetSettings(parent);
3795 bool customPopup(QAD_Desktop * parent, QPopupMenu * popup,
3796 const QString & theContext, const QString & theParent,
3797 const QString & theObject)
3799 return SMESHGUI::CustomPopup(parent, popup, theContext, theParent,
3803 void definePopup(QString & theContext, QString & theParent,
3804 QString & theObject)
3806 SMESHGUI::DefinePopup(theContext, theParent, theObject);
3809 bool activeStudyChanged(QAD_Desktop * parent)
3811 SMESHGUI::activeStudyChanged(parent);
3814 void buildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
3816 SMESHGUI::BuildPresentation(theIO);
3819 void supportedViewType(int *buffer, int bufferSize)
3821 if (!buffer || !bufferSize)
3823 buffer[0] = (int)VIEW_VTK;
3828 if ( SMESHGUI::GetSMESHGUI() ) {
3829 SMESHGUI::GetSMESHGUI()->EmitSignalCloseAllDialogs();
3835 //=============================================================================
3839 //=============================================================================
3840 void SMESHGUI::SetPickable(SMESH_Actor* theActor){
3841 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
3842 int anIsAllPickable = (theActor == NULL);
3843 vtkRenderer *aRenderer = aViewFrame->getRenderer();
3844 vtkActorCollection *aCollection = aRenderer->GetActors();
3845 aCollection->InitTraversal();
3846 while(vtkActor *anAct = aCollection->GetNextActor()){
3847 if(SALOME_Actor *anActor = dynamic_cast<SALOME_Actor*>(anAct)){
3848 if(anActor->GetVisibility()){
3849 anActor->SetPickable(anIsAllPickable);
3854 theActor->SetPickable(!anIsAllPickable);
3855 RepaintCurrentView();
3860 void SMESHGUI::ViewNodes(){
3861 EraseSimulationActors();
3862 ::SetPointRepresentation(true);
3865 //=============================================================================
3869 //=============================================================================
3870 void SMESHGUI::Control( int theCommandID ){
3871 SALOME_Selection *Sel = SALOME_Selection::Selection( myActiveStudy->getSelection() );
3873 Handle(SALOME_InteractiveObject) anIO = Sel->firstIObject();
3876 SMESH_Actor::eControl aControl = SMESH_Actor::eNone;
3877 if(SMESH_Actor *anActor = ::FindActorByEntry(anIO->getEntry())){
3878 switch ( theCommandID ){
3880 aTitle = tr( "LENGTH_EDGES" );
3881 aControl = SMESH_Actor::eLengthEdges;
3884 aTitle = tr( "FREE_BORDERS" );
3885 aControl = SMESH_Actor::eFreeBorders;
3888 aTitle = tr( "MULTI_BORDERS" );
3889 aControl = SMESH_Actor::eMultiConnection;
3892 aTitle = tr( "AREA_ELEMENTS" );
3893 aControl = SMESH_Actor::eArea;
3896 aTitle = tr( "TAPER_ELEMENTS" );
3897 aControl = SMESH_Actor::eTaper;
3900 aTitle = tr( "ASPECTRATIO_ELEMENTS" );
3901 aControl = SMESH_Actor::eAspectRatio;
3904 aTitle = tr( "MINIMUMANGLE_ELEMENTS" );
3905 aControl = SMESH_Actor::eMinimumAngle;
3908 aTitle = tr( "WARP_ELEMENTS" );
3909 aControl = SMESH_Actor::eWarping;
3912 aTitle = tr( "SKEW_ELEMENTS" );
3913 aControl = SMESH_Actor::eSkew;
3916 anActor->SetControlMode(aControl);
3917 anActor->GetScalarBarActor()->SetTitle(aTitle.latin1());
3923 //=============================================================================
3927 //=============================================================================
3928 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
3933 QString Orientation,
3939 if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
3940 theScalarBar->BoldOn();
3942 theScalarBar->BoldOff();
3944 if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
3945 theScalarBar->ItalicOn();
3947 theScalarBar->ItalicOff();
3949 if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
3950 theScalarBar->ShadowOn();
3952 theScalarBar->ShadowOff();
3954 if (FontFamily.compare("Arial") == 0)
3955 theScalarBar->SetFontFamilyToArial();
3956 else if (FontFamily.compare("Courier") == 0)
3957 theScalarBar->SetFontFamilyToCourier();
3958 else if (FontFamily.compare("Times") == 0)
3959 theScalarBar->SetFontFamilyToTimes();
3961 theScalarBar->SetFontFamilyToArial();
3963 if (Orientation.isNull() || Orientation.isEmpty() ||
3964 (Orientation.compare("Vertical") == 0))
3965 theScalarBar->SetOrientationToVertical();
3967 theScalarBar->SetOrientationToHorizontal();
3969 theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
3970 theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
3972 theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
3973 theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
3976 //=============================================================================
3980 //=============================================================================
3981 void SMESHGUI::SetDisplaySettings()
3983 EmitSignalDeactivateDialog();
3984 SMESHGUI_Preferences_ColorDlg *aDlg =
3985 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
3988 QString SCr, SCg, SCb;
3989 SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
3990 SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
3991 SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
3992 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
3993 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
3994 else color = QColor(0, 170, 255);
3995 aDlg->SetColor(1, color);
3997 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
3998 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
3999 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
4000 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
4001 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
4002 else color = QColor(0, 170, 255);
4003 aDlg->SetColor(2, color);
4005 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4006 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4007 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4008 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
4009 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
4010 else color = Qt::red;
4011 aDlg->SetColor(3, color);
4013 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
4014 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
4015 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
4016 if (!SCr.isEmpty() && !SCg.isEmpty() && !SCb.isEmpty())
4017 color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
4018 else color = Qt::blue;
4019 aDlg->SetColor(4, color);
4021 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
4022 if (intValue.isEmpty()) intValue = "1";
4023 aDlg->SetIntValue(1, intValue.toInt());
4024 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
4025 if (intValue.isEmpty()) intValue = "3";
4026 aDlg->SetIntValue(2, intValue.toInt());
4027 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
4028 if (intValue.isEmpty()) intValue = "75";
4029 aDlg->SetIntValue(3, intValue.toInt());
4032 QColor colorFill = aDlg->GetColor(1);
4033 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
4034 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen", colorFill.green());
4035 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
4037 QColor colorOutline = aDlg->GetColor(2);
4038 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed", colorOutline.red());
4039 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen", colorOutline.green());
4040 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue", colorOutline.blue());
4042 QColor colorNode = aDlg->GetColor(3);
4043 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
4044 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen", colorNode.green());
4045 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
4047 QColor colorBackFace = aDlg->GetColor(4);
4048 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed", colorBackFace.red());
4049 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen", colorBackFace.green());
4050 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue", colorBackFace.blue());
4052 int width = aDlg->GetIntValue(1);
4053 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
4055 int nodes_size = aDlg->GetIntValue(2);
4056 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
4058 int shrink_coeff = aDlg->GetIntValue(3);
4059 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
4065 //=======================================================================
4066 // function : Parameter()
4067 // purpose : return a parameter (double) from a dialog box
4069 // aValue : is a double used as a default value displayed
4070 // aLabel : is the title for aValue1
4071 // aTitle : is the main title
4072 // bottom : maximum value to be entered
4073 // top : minimum value to be entered
4074 // decimals : number of decimals
4075 //=======================================================================
4076 double SMESHGUI::Parameter(Standard_Boolean & res,
4077 const double aValue,
4080 const double bottom, const double top, const int decimals)
4082 SMESHGUI_aParameterDlg *Dialog =
4083 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
4086 bottom, top, decimals,
4088 Dialog->setValue(aValue);
4090 res = (Dialog->exec() == QDialog::Accepted);
4092 X = Dialog->getDblValue();
4096 //=======================================================================
4097 // function : Parameter()
4098 // purpose : return a parameter (int) from a dialog box
4100 // aValue : is a int used as a default value displayed
4101 // aLabel : is the title for aValue1
4102 // aTitle : is the main title
4103 // bottom : maximum value to be entered
4104 // top : minimum value to be entered
4105 //=======================================================================
4106 int SMESHGUI::Parameter(Standard_Boolean & res,
4108 const char *aLabel, const char *aTitle, const int bottom, const int top)
4110 SMESHGUI_aParameterDlg *Dialog =
4111 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
4116 Dialog->setValue(aValue);
4118 res = (Dialog->exec() == QDialog::Accepted);
4120 X = Dialog->getIntValue();
4124 //=============================================================================
4128 //=============================================================================
4129 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility){}
4131 //=============================================================================
4135 //=============================================================================
4136 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh){}
4138 //=============================================================================
4142 //=============================================================================
4143 void SMESHGUI::Update(){
4144 if(VTKViewer_ViewFrame* aViewFrame = GetCurrentVtkView()){
4145 SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
4146 if(Sel->IObjectCount() == 0){
4147 vtkRenderer* aRenderer = aViewFrame->getRenderer();
4148 vtkActorCollection *aCollection = aRenderer->GetActors();
4149 aCollection->InitTraversal();
4150 while(vtkActor *anAct = aCollection->GetNextActor()){
4151 if(SMESH_Actor *anActor = dynamic_cast<SMESH_Actor*>(anAct)){
4152 if(anActor->hasIO()){
4153 Update(anActor->getIO());
4158 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4159 for(; It.More(); It.Next()){
4160 Handle(SALOME_InteractiveObject) IO = It.Value();
4164 ::RepaintCurrentView();
4168 //=============================================================================
4172 //=============================================================================
4173 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & theIO){
4174 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4175 TVisualObjPtr aVisualObj = ::GetVisualObj(anId,theIO->getEntry());
4176 aVisualObj->Update();
4177 ::UpdateView(eDisplay,theIO->getEntry());
4180 //=============================================================================
4184 //=============================================================================
4185 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
4187 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4190 mySimulationActors = vtkActorCollection::New();
4191 vtkRenderer *theRenderer =
4192 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4193 getRightFrame()->getViewFrame())->getRenderer();
4195 vtkUnstructuredGrid *ugrid =
4196 vtkUnstructuredGrid::SafeDownCast(Mactor->GetUnstructuredGrid());
4197 vtkIdList *IdCells = vtkIdList::New();
4198 ugrid->GetPointCells(idnode, IdCells);
4200 vtkPoints *Pts = vtkPoints::New();
4201 Pts = ugrid->GetPoints();
4203 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
4204 ugridSimulation->SetPoints(Pts);
4205 vtkIdList *IdPts = vtkIdList::New();
4206 for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
4208 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
4209 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
4213 vtkProperty *prop = vtkProperty::New();
4214 prop->SetColor(1., 0., 0.);
4215 prop->SetRepresentationToWireframe();
4217 int Edgewidth = (int)Mactor->GetLineWidth();
4220 prop->SetLineWidth(Edgewidth + 1);
4222 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4223 Mapper->SetInput(ugridSimulation);
4224 vtkActor *ac = vtkActor::New();
4225 ac->SetMapper(Mapper);
4226 ac->SetProperty(prop);
4228 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
4229 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
4231 mySimulationActors->AddItem(ac);
4232 theRenderer->AddActor(ac);
4234 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4240 //=============================================================================
4244 //=============================================================================
4245 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
4248 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4251 EraseSimulationActors();
4252 mySimulationActors = vtkActorCollection::New();
4253 vtkRenderer *theRenderer =
4254 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4255 getRightFrame()->getViewFrame())->getRenderer();
4256 Standard_Boolean result;
4257 SMESH_Actor *ac = FindActor(aMesh, result, true);
4261 vtkUnstructuredGrid *ugrid =
4262 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4263 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4265 vtkPoints *Pts = ugrid->GetPoints();
4266 vtkPoints *newPts = vtkPoints::New();
4267 int nbPts = Pts->GetNumberOfPoints();
4268 for (int i = 0; i < nbPts; i++)
4270 newPts->InsertPoint(i, Pts->GetPoint(i));
4273 newugrid->SetPoints(newPts);
4274 newugrid->GetPoints()->InsertNextPoint(x, y, z);
4276 vtkMaskPoints *verts = vtkMaskPoints::New();
4277 verts->SetInput(newugrid);
4278 verts->SetGenerateVertices(1);
4279 verts->SetOnRatio(1);
4281 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
4282 vertMapper->SetInput(verts->GetOutput());
4283 vertMapper->ScalarVisibilityOff();
4285 vtkActor *node = vtkActor::New();
4286 node->SetMapper(vertMapper);
4288 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
4289 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
4290 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
4291 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
4292 if (!nodecolor.isValid())
4293 // nodecolor = QColor(0.,1.,0.);
4294 nodecolor = QColor(0, 1, 0);
4296 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
4297 float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
4300 QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
4304 node->GetProperty()->SetPointSize(intValue);
4306 node->VisibilityOn();
4308 mySimulationActors->AddItem(node);
4309 theRenderer->AddActor(node);
4312 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4316 //=============================================================================
4320 //=============================================================================
4321 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
4324 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4327 vtkRenderer *theRenderer =
4328 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4329 getRightFrame()->getViewFrame())->getRenderer();
4330 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
4335 ac->GetMapper()->ImmediateModeRenderingOn();
4336 ac->GetProperty()->SetRepresentationToWireframe();
4338 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4343 //=============================================================================
4347 //=============================================================================
4348 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
4351 Standard_Boolean result;
4353 SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
4359 //=============================================================================
4363 //=============================================================================
4364 void SMESHGUI::ScalarVisibilityOff(){
4365 if(vtkRenderer *aRenderer = ::GetCurrentRenderer()){
4366 vtkActorCollection *actorList = aRenderer->GetActors();
4367 actorList->InitTraversal();
4368 while(vtkActor *ac = actorList->GetNextActor()){
4369 if(SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac)){
4370 anActor->GetMapper()->ScalarVisibilityOff();
4373 ::RepaintCurrentView();
4377 //=============================================================================
4381 //=============================================================================
4382 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
4383 const TColStd_MapOfInteger & MapIndex)
4385 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4388 EraseSimulationActors();
4389 mySimulationActors = vtkActorCollection::New();
4390 vtkRenderer *theRenderer =
4391 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4392 getRightFrame()->getViewFrame())->getRenderer();
4393 Standard_Boolean result;
4394 SMESH_Actor *ac = FindActor(aMesh, result, true);
4397 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4401 vtkIdList *Ids = vtkIdList::New();
4402 for (; ite.More(); ite.Next())
4404 idNodes[i] = ite.Key();
4408 Ids->InsertId(0, idNodes[0]);
4409 pts[0] = idNodes[0];
4410 Ids->InsertId(1, idNodes[1]);
4411 pts[1] = idNodes[1];
4413 vtkUnstructuredGrid *ugrid =
4414 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4415 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4416 newugrid->SetPoints(ugrid->GetPoints());
4417 newugrid->InsertNextCell(VTK_LINE, 2, pts);
4419 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4420 Mapper->SetInput(newugrid);
4423 vtkActor *edge = vtkActor::New();
4424 edge->SetMapper(Mapper);
4425 edge->SetProperty(ac->GetProperty());
4426 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
4427 edge->VisibilityOn();
4428 mySimulationActors->AddItem(edge);
4429 theRenderer->AddActor(edge);
4432 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4436 //=============================================================================
4440 //=============================================================================
4441 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
4442 const TColStd_MapOfInteger & MapIndex, bool reverse)
4444 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4447 EraseSimulationActors();
4448 mySimulationActors = vtkActorCollection::New();
4449 vtkRenderer *theRenderer =
4450 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4451 getRightFrame()->getViewFrame())->getRenderer();
4452 Standard_Boolean result;
4453 SMESH_Actor *ac = FindActor(aMesh, result, true);
4456 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4460 vtkIdList *Ids = vtkIdList::New();
4461 for (; ite.More(); ite.Next())
4463 idNodes[i] = ite.Key();
4469 Ids->InsertId(0, idNodes[2]);
4470 pts[0] = idNodes[2];
4471 Ids->InsertId(1, idNodes[1]);
4472 pts[1] = idNodes[1];
4473 Ids->InsertId(2, idNodes[0]);
4474 pts[2] = idNodes[0];
4478 Ids->InsertId(0, idNodes[0]);
4479 pts[0] = idNodes[0];
4480 Ids->InsertId(1, idNodes[1]);
4481 pts[1] = idNodes[1];
4482 Ids->InsertId(2, idNodes[2]);
4483 pts[2] = idNodes[2];
4485 vtkUnstructuredGrid *ugrid =
4486 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4487 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4488 newugrid->SetPoints(ugrid->GetPoints());
4489 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
4491 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4492 Mapper->SetInput(newugrid);
4495 vtkActor *tri = vtkActor::New();
4496 tri->SetMapper(Mapper);
4497 tri->SetProperty(ac->GetProperty());
4498 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
4499 tri->VisibilityOn();
4500 mySimulationActors->AddItem(tri);
4501 theRenderer->AddActor(tri);
4504 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4508 //=============================================================================
4512 //=============================================================================
4513 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
4514 const TColStd_MapOfInteger & MapIndex, bool reverse)
4516 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4519 EraseSimulationActors();
4520 mySimulationActors = vtkActorCollection::New();
4521 vtkRenderer *theRenderer =
4522 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4523 getRightFrame()->getViewFrame())->getRenderer();
4524 Standard_Boolean result;
4525 SMESH_Actor *ac = FindActor(aMesh, result, true);
4527 vtkUnstructuredGrid *ugrid =
4528 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4532 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4535 vtkIdList *Ids = vtkIdList::New();
4536 for (; ite.More(); ite.Next())
4538 idNodes[i] = ite.Key();
4542 float *p0 = ugrid->GetPoint(idNodes[0]);
4543 float *p1 = ugrid->GetPoint(idNodes[1]);
4544 float *p2 = ugrid->GetPoint(idNodes[2]);
4545 float *p3 = ugrid->GetPoint(idNodes[3]);
4547 gp_Pnt P0(p0[0], p0[1], p0[2]);
4549 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4550 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4551 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
4553 gp_Vec Cross1 = V1 ^ V2;
4554 gp_Vec Cross2 = V2 ^ V3;
4557 if (Cross1.Dot(Cross2) < 0)
4559 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4560 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4564 if (Cross1.Dot(Cross2) < 0)
4567 idNodes[2] = idNodes[3];
4573 idNodes[1] = idNodes[2];
4580 Ids->InsertId(0, idNodes[3]);
4581 Ids->InsertId(1, idNodes[2]);
4582 Ids->InsertId(2, idNodes[1]);
4583 Ids->InsertId(3, idNodes[0]);
4587 Ids->InsertId(0, idNodes[0]);
4588 Ids->InsertId(1, idNodes[1]);
4589 Ids->InsertId(2, idNodes[2]);
4590 Ids->InsertId(3, idNodes[3]);
4593 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->GetUnstructuredGrid() );
4594 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4595 newugrid->SetPoints(ugrid->GetPoints());
4596 newugrid->InsertNextCell(VTK_QUAD, Ids);
4598 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4599 Mapper->SetInput(newugrid);
4602 vtkActor *quad = vtkActor::New();
4603 quad->SetMapper(Mapper);
4604 quad->SetProperty(ac->GetProperty());
4605 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
4606 quad->VisibilityOn();
4607 mySimulationActors->AddItem(quad);
4608 theRenderer->AddActor(quad);
4610 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4614 //=============================================================================
4618 //=============================================================================
4619 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
4620 const TColStd_MapOfInteger & MapIndex)
4622 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4625 EraseSimulationActors();
4626 mySimulationActors = vtkActorCollection::New();
4627 vtkRenderer *theRenderer =
4628 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4629 getRightFrame()->getViewFrame())->getRenderer();
4630 Standard_Boolean result;
4631 SMESH_Actor *ac = FindActor(aMesh, result, true);
4634 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4637 vtkIdList *Ids = vtkIdList::New();
4638 for (; ite.More(); ite.Next())
4640 idNodes[i] = ite.Key();
4644 Ids->InsertId(0, idNodes[0]);
4645 Ids->InsertId(1, idNodes[1]);
4646 Ids->InsertId(2, idNodes[2]);
4647 Ids->InsertId(3, idNodes[3]);
4649 vtkUnstructuredGrid *ugrid =
4650 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4651 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4652 newugrid->SetPoints(ugrid->GetPoints());
4653 newugrid->InsertNextCell(VTK_TETRA, Ids);
4655 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4656 Mapper->SetInput(newugrid);
4659 vtkActor *tetra = vtkActor::New();
4660 tetra->SetMapper(Mapper);
4661 tetra->SetProperty(ac->GetProperty());
4662 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
4663 tetra->VisibilityOn();
4664 mySimulationActors->AddItem(tetra);
4665 theRenderer->AddActor(tetra);
4667 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4671 //=============================================================================
4675 //=============================================================================
4676 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
4677 const TColStd_MapOfInteger & MapIndex)
4679 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4682 EraseSimulationActors();
4683 mySimulationActors = vtkActorCollection::New();
4684 vtkRenderer *theRenderer =
4685 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4686 getRightFrame()->getViewFrame())->getRenderer();
4687 Standard_Boolean result;
4688 SMESH_Actor *ac = FindActor(aMesh, result, true);
4691 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4694 vtkIdList *Ids = vtkIdList::New();
4695 for (; ite.More(); ite.Next())
4697 idNodes[i] = ite.Key();
4701 Ids->InsertId(0, idNodes[0]);
4702 Ids->InsertId(1, idNodes[1]);
4703 Ids->InsertId(2, idNodes[2]);
4704 Ids->InsertId(3, idNodes[3]);
4705 Ids->InsertId(4, idNodes[4]);
4706 Ids->InsertId(5, idNodes[5]);
4707 Ids->InsertId(6, idNodes[6]);
4708 Ids->InsertId(7, idNodes[7]);
4710 vtkUnstructuredGrid *ugrid =
4711 vtkUnstructuredGrid::SafeDownCast(ac->GetUnstructuredGrid());
4712 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
4713 newugrid->SetPoints(ugrid->GetPoints());
4714 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
4716 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4717 Mapper->SetInput(newugrid);
4720 vtkActor *hexa = vtkActor::New();
4721 hexa->SetMapper(Mapper);
4722 hexa->SetProperty(ac->GetProperty());
4723 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
4724 hexa->VisibilityOn();
4725 mySimulationActors->AddItem(hexa);
4726 theRenderer->AddActor(hexa);
4728 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4732 //=============================================================================
4736 //=============================================================================
4737 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr theMesh,
4738 const TColStd_MapOfInteger & MapIndex,
4743 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4744 CORBA::String_var anEntry = aSobj->GetID();
4745 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4746 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4747 anArrayOfIdeces->length(MapIndex.Extent());
4748 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4749 for(int i = 0; ite.More(); ite.Next(), i++){
4750 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4753 if(MapIndex.Extent() == 4){
4755 TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
4756 for(int i = 0; ite1.More(); ite1.Next(), i++){
4757 idNodes[i] = ite1.Key();
4759 vtkUnstructuredGrid *ugrid = anActor->GetUnstructuredGrid();
4760 float *p0 = ugrid->GetPoint(idNodes[0]);
4761 float *p1 = ugrid->GetPoint(idNodes[1]);
4762 float *p2 = ugrid->GetPoint(idNodes[2]);
4763 float *p3 = ugrid->GetPoint(idNodes[3]);
4765 gp_Pnt P0(p0[0], p0[1], p0[2]);
4767 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4768 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4769 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
4771 gp_Vec Cross1 = V1 ^ V2;
4772 gp_Vec Cross2 = V2 ^ V3;
4774 if(Cross1.Dot(Cross2) < 0){
4775 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
4776 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
4780 if(Cross1.Dot(Cross2) < 0){
4781 tmp = anArrayOfIdeces[2];
4782 anArrayOfIdeces[2] = anArrayOfIdeces[3];
4783 anArrayOfIdeces[3] = tmp;
4785 tmp = anArrayOfIdeces[1];
4786 anArrayOfIdeces[1] = anArrayOfIdeces[2];
4787 anArrayOfIdeces[2] = tmp;
4792 for(int i = 0; i < (MapIndex.Extent() / 2); i++){
4793 tmp = anArrayOfIdeces[i];
4794 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
4795 anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
4798 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4799 aMeshEditor->AddFace(anArrayOfIdeces);
4800 if(myAutomaticUpdate){
4801 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4802 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4803 aVisualObj->Update(true);
4805 AddActorInSelection(anActor);
4808 }catch(SALOME::SALOME_Exception& exc) {
4809 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4810 }catch(const std::exception& exc){
4811 INFOS("Follow exception was cought:\n\t"<<exc.what());
4813 INFOS("Unknown exception was cought !!!");
4817 //=============================================================================
4821 //=============================================================================
4822 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr theMesh,
4823 const TColStd_MapOfInteger & MapIndex)
4827 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4828 CORBA::String_var anEntry = aSobj->GetID();
4829 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4830 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4831 anArrayOfIdeces->length(MapIndex.Extent());
4832 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4833 for(int i = 0; ite.More(); ite.Next(), i++){
4834 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4836 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4837 aMeshEditor->AddVolume(anArrayOfIdeces);
4838 if(myAutomaticUpdate){
4839 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4840 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4841 aVisualObj->Update(true);
4845 }catch(SALOME::SALOME_Exception& exc) {
4846 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4847 }catch(const std::exception& exc){
4848 INFOS("Follow exception was cought:\n\t"<<exc.what());
4850 INFOS("Unknown exception was cought !!!");
4853 //=============================================================================
4857 //=============================================================================
4858 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr theMesh,
4859 const TColStd_MapOfInteger & MapIndex)
4863 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4864 CORBA::String_var anEntry = aSobj->GetID();
4865 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4866 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4867 anArrayOfIdeces->length(MapIndex.Extent());
4868 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4869 for(int i = 0; ite.More(); ite.Next(), i++){
4870 anArrayOfIdeces[i] = anActor->GetNodeObjId(ite.Key());
4872 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4873 aMeshEditor->AddEdge(anArrayOfIdeces);
4874 if(myAutomaticUpdate){
4875 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4876 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4877 aVisualObj->Update(true);
4881 }catch(SALOME::SALOME_Exception& exc) {
4882 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4883 }catch(const std::exception& exc){
4884 INFOS("Follow exception was cought:\n\t"<<exc.what());
4886 INFOS("Unknown exception was cought !!!");
4889 //=============================================================================
4893 //=============================================================================
4894 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr theMesh,
4895 float x, float y, float z)
4899 SALOMEDS::SObject_var aSobj = myStudyAPI.FindObject(theMesh);
4900 CORBA::String_var anEntry = aSobj->GetID();
4901 if(SMESH_Actor* anActor = ::FindActorByEntry(anEntry.in())){
4902 SMESH::SMESH_MeshEditor_var aMeshEditor = theMesh->GetMeshEditor();
4903 aMeshEditor->AddNode(x, y, z);
4904 if(myAutomaticUpdate){
4905 CORBA::Long anId = smeshGUI->myStudy->StudyId();
4906 if(TVisualObjPtr aVisualObj = GetVisualObj(anId,anEntry.in())){
4907 aVisualObj->Update(true);
4911 }catch(SALOME::SALOME_Exception& exc) {
4912 INFOS("Follow exception was cought:\n\t"<<exc.details.text);
4913 }catch(const std::exception& exc){
4914 INFOS("Follow exception was cought:\n\t"<<exc.what());
4916 INFOS("Unknown exception was cought !!!");
4919 //=============================================================================
4923 //=============================================================================
4924 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
4926 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4929 EraseSimulationActors();
4930 mySimulationActors2D = vtkActor2DCollection::New();
4932 vtkRenderer *theRenderer =
4933 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4934 getRightFrame()->getViewFrame())->getRenderer();
4936 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
4937 gs2->SetGlyphTypeToTriangle();
4940 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
4941 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
4942 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
4944 legend->SetNumberOfEntries(4);
4945 legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
4946 legend->SetEntrySymbol(0, gs2->GetOutput());
4947 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
4948 legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
4949 legend->SetEntrySymbol(1, gs2->GetOutput());
4950 legend->SetEntryColor(1,
4951 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
4952 legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
4953 legend->SetEntrySymbol(2, gs2->GetOutput());
4954 legend->SetEntryColor(2,
4955 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
4956 legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
4957 legend->SetEntrySymbol(3, gs2->GetOutput());
4958 legend->SetEntryColor(3,
4959 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
4960 legend->SetPadding(5);
4961 // legend->GetProperty()->SetColor();
4963 mySimulationActors2D->AddItem(legend);
4964 theRenderer->AddActor2D(legend);
4967 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
4971 //===============================================================================
4972 // function : OnEditDelete()
4974 //===============================================================================
4975 void SMESHGUI::OnEditDelete()
4977 if (QAD_MessageBox::warn2
4978 (QAD_Application::getDesktop(),
4979 tr("SMESH_WRN_WARNING"),
4980 tr("SMESH_REALLY_DELETE"),
4981 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
4984 int nbSf = myActiveStudy->getStudyFramesCount();
4986 Standard_Boolean found;
4987 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
4988 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
4989 SALOMEDS::GenericAttribute_var anAttr;
4990 SALOMEDS::AttributeIOR_var anIOR;
4992 SALOME_Selection *Sel = SALOME_Selection::Selection(myActiveStudy->getSelection());
4993 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4994 for(; It.More(); It.Next()){
4995 Handle(SALOME_InteractiveObject) IObject = It.Value();
4996 if(IObject->hasEntry()){
4997 SALOMEDS::SObject_var SO = myStudy->FindObjectID(IObject->getEntry());
4999 /* Erase child graphical objects */
5000 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
5001 for(; it->More(); it->Next()){
5002 SALOMEDS::SObject_var CSO = it->Value();
5003 if(CSO->FindAttribute(anAttr, "AttributeIOR")){
5004 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
5006 for(int i = 0; i < nbSf; i++){
5007 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
5008 CORBA::String_var anEntry = CSO->GetID();
5009 if(SMESH_Actor* anActor = ::FindActorByEntry(sf,anEntry.in())){
5010 RemoveActor(sf,anActor);
5016 /* Erase main graphical object */
5017 for(int i = 0; i < nbSf; i++){
5018 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
5019 if(SMESH_Actor* anActor = ::FindActorByEntry(sf,IObject->getEntry())){
5020 RemoveActor(sf,anActor);
5024 // Remove object(s) from data structures
5025 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IObject->getEntry());
5026 if(!obj->_is_nil()){
5027 SMESH::SMESH_Group_var aGroup = SMESH::SMESH_Group ::_narrow(obj->GetObject());
5028 SMESH::SMESH_subMesh_var aSubMesh = SMESH::SMESH_subMesh::_narrow(obj->GetObject());
5030 if ( !aGroup->_is_nil() ) { // DELETE GROUP
5031 SMESH::SMESH_Mesh_var aMesh = aGroup->GetMesh();
5032 aMesh->RemoveGroup( aGroup );
5034 else if ( !aSubMesh->_is_nil() ) { // DELETE SUBMESH
5035 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
5036 aMesh->RemoveSubMesh( aSubMesh );
5038 else {// default action: remove SObject from the study
5039 // san - it's no use opening a transaction here until UNDO/REDO is provided in SMESH
5040 //QAD_Operation *op = new SALOMEGUI_ImportOperation(myActiveStudy);
5042 aStudyBuilder->RemoveObjectWithChildren( obj );
5047 } /* IObject->hasEntry() */
5050 /* Clear any previous selection */
5051 Sel->ClearIObjects();
5052 myActiveStudy->updateObjBrowser();
5055 //=======================================================================
5056 // name : SMESHGUI::GetFilterMgr
5057 // Purpose : Get filter manager
5058 //=======================================================================
5059 SMESH::FilterManager_ptr SMESHGUI::GetFilterMgr()