1 // SMESH SMESHGUI : GUI for SMESH component
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
24 // File : SMESHGUI.cxx
25 // Author : Nicolas REJNERI
31 #include "SMESHGUI_AddHypothesisDlg.h"
32 #include "SMESHGUI_AddAlgorithmDlg.h"
33 #include "SMESHGUI_InitMeshDlg.h"
34 #include "SMESHGUI_LocalLengthDlg.h"
35 #include "SMESHGUI_NbSegmentsDlg.h"
36 #include "SMESHGUI_AddSubMeshDlg.h"
37 #include "SMESHGUI_NodesDlg.h"
38 #include "SMESHGUI_TransparencyDlg.h"
39 #include "SMESHGUI_RemoveNodesDlg.h"
40 #include "SMESHGUI_RemoveElementsDlg.h"
41 #include "SMESHGUI_MeshInfosDlg.h"
42 #include "SMESHGUI_Preferences_ColorDlg.h"
43 #include "SMESHGUI_MaxElementAreaDlg.h"
44 #include "SMESHGUI_MaxElementVolumeDlg.h"
45 #include "SMESHGUI_Preferences_ScalarBarDlg.h"
46 #include "SMESHGUI_EditScalarBarDlg.h"
47 #include "SMESHGUI_aParameterDlg.h"
48 #include "SMESHGUI_ComputeScalarValue.h"
49 #include "SMESHGUI_MoveNodesDlg.h"
50 #include "SMESHGUI_OrientationElementsDlg.h"
51 #include "SMESHGUI_DiagonalInversionDlg.h"
52 #include "SMESHGUI_EdgesConnectivityDlg.h"
53 #include "SMESHGUI_AddFaceDlg.h"
54 #include "SMESHGUI_AddEdgeDlg.h"
55 #include "SMESHGUI_AddVolumeDlg.h"
56 #include "SMESHGUI_EditHypothesesDlg.h"
58 #include "SMESH_Grid.h"
61 #include "Utils_ORB_INIT.hxx"
62 #include "Utils_SINGLETON.hxx"
65 #include "QAD_Tools.h"
66 #include "QAD_Config.h"
67 #include "QAD_Settings.h"
68 #include "QAD_RightFrame.h"
69 #include "QAD_MessageBox.h"
70 #include "QAD_Resource.h"
71 #include "QAD_FileDlg.h"
72 #include "SALOMEGUI_Desktop.h"
73 #include "SALOMEGUI_NameDlg.h"
75 #include "OCCViewer_ViewPort.h"
76 #include "OCCViewer_ViewPort3d.h"
77 #include "OCCViewer_Viewer3d.h"
79 #include "GEOM_Client.hxx"
80 #include "GEOM_InteractiveObject.hxx"
82 #include "SALOME_NamingService.hxx"
83 #include "SALOME_ListIteratorOfListIO.hxx"
84 #include "SALOME_InteractiveObject.hxx"
86 #include "SALOMEGUI_ImportOperation.h"
87 #include "SALOMEGUI_QtCatchCorbaException.hxx"
88 #include "utilities.h"
90 #include "SMDS_Mesh.hxx"
91 #include "SMESHDS_Document.hxx"
92 #include "Document_Reader.h"
93 #include "Document_Writer.h"
94 #include "Mesh_Reader.h"
95 #include "Mesh_Writer.h"
97 #include "DriverDAT_R_SMESHDS_Document.h"
98 #include "DriverMED_R_SMESHDS_Document.h"
99 #include "DriverUNV_R_SMESHDS_Document.h"
100 #include "DriverDAT_W_SMESHDS_Document.h"
101 #include "DriverMED_W_SMESHDS_Document.h"
102 #include "DriverUNV_W_SMESHDS_Document.h"
103 #include "DriverDAT_R_SMESHDS_Mesh.h"
104 #include "DriverMED_R_SMESHDS_Mesh.h"
105 #include "DriverUNV_R_SMESHDS_Mesh.h"
106 #include "DriverDAT_W_SMESHDS_Mesh.h"
107 #include "DriverMED_W_SMESHDS_Mesh.h"
108 #include "DriverUNV_W_SMESHDS_Mesh.h"
111 #define INCLUDE_MENUITEM_DEF
112 #include <qapplication.h>
113 #include <qlineedit.h>
114 #include <qmenudata.h>
115 #include <qmenubar.h>
116 #include <qpopupmenu.h>
119 #include <qcheckbox.h>
120 #include <qcolordialog.h>
121 #include <qmessagebox.h>
122 #include <qspinbox.h>
126 #include <qradiobutton.h>
129 #include "VTKViewer_Common.h"
130 #include "VTKViewer_ViewFrame.h"
131 #include <vtkLegendBoxActor.h>
132 #include <vtkFeatureEdges.h>
133 #include <vtkDoubleArray.h>
135 // Open CASCADE Includes
136 #include <gp_Pnt.hxx>
137 #include <gp_Vec.hxx>
139 static GEOM_Client ShapeReader;
140 static SMESHGUI *smeshGUI = 0;
141 static CORBA::ORB_var _orb;
143 //=============================================================================
147 //=============================================================================
148 class CustomItem:public QCustomMenuItem
151 CustomItem(const QString & s, const QFont & f):string(s), font(f)
158 void paint(QPainter * p, const QColorGroup & /*cg */ , bool /*act */ ,
159 bool /*enabled */ , int x, int y, int w, int h)
162 p->drawText(x, y, w, h,
163 AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
168 return QFontMetrics(font).
169 size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
176 //=============================================================================
180 //=============================================================================
181 SMESHGUI::SMESHGUI():
186 //=============================================================================
190 //=============================================================================
191 SMESHGUI::~SMESHGUI()
195 //=============================================================================
199 //=============================================================================
200 SMESHGUI *SMESHGUI::GetSMESHGUI()
205 //=============================================================================
209 //=============================================================================
210 SMESHGUI *SMESHGUI::GetOrCreateSMESHGUI(QAD_Desktop * desktop)
215 smeshGUI = new SMESHGUI;
216 smeshGUI->myActiveDialogBox = 0;
217 smeshGUI->myState = -1;
218 smeshGUI->myDesktop = desktop;
219 smeshGUI->myActiveStudy = desktop->getActiveStudy();
221 Engines::Component_var comp =
222 desktop->getEngine("FactoryServer", "SMESH");
223 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
225 Engines::Component_var comp1 =
226 desktop->getEngine("FactoryServer", "GEOM");
227 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
229 /* GetCurrentStudy */
230 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
232 smeshGUI->myComponentGeom->GetCurrentStudy(smeshGUI->myStudyId);
233 // smeshGUI->myComponentGeom->NbLabels();
235 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
237 smeshGUI->myStudyAPI =
238 SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
240 smeshGUI->myDocument = new SMESHDS_Document(1); //NBU
242 smeshGUI->mySimulationActors = vtkActorCollection::New();
243 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
247 /* study may have changed */
248 smeshGUI->myActiveStudy = desktop->getActiveStudy();
249 smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
252 /* Automatic Update */
253 if (desktop->menuBar()->isItemChecked(1001))
254 smeshGUI->myAutomaticUpdate = true;
256 smeshGUI->myAutomaticUpdate = false;
261 //=============================================================================
265 //=============================================================================
266 void SMESHGUI::SetState(int aState)
268 this->myState = aState;
272 //=============================================================================
276 //=============================================================================
277 void SMESHGUI::ResetState()
283 //=============================================================================
287 //=============================================================================
288 void SMESHGUI::EmitSignalDeactivateDialog()
290 emit this->SignalDeactivateActiveDialog();
294 //=============================================================================
298 //=============================================================================
299 void SMESHGUI::EmitSignalCloseAllDialogs()
301 emit this->SignalCloseAllDialogs();
305 //=============================================================================
309 //=============================================================================
310 QDialog *SMESHGUI::GetActiveDialogBox()
312 return this->myActiveDialogBox;
315 //=============================================================================
319 //=============================================================================
320 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
322 this->myActiveDialogBox = (QDialog *) aDlg;
326 //=============================================================================
330 //=============================================================================
331 QAD_Study *SMESHGUI::GetActiveStudy()
333 return this->myActiveStudy;
336 //=============================================================================
340 //=============================================================================
341 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
343 return SALOMEDS::Study::_narrow(myStudy);
346 //=============================================================================
350 //=============================================================================
351 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
356 //=============================================================================
360 //=============================================================================
361 QAD_Desktop *SMESHGUI::GetDesktop()
363 return this->myDesktop;
366 //=============================================================================
370 //=============================================================================
371 vtkScalarBarActor *SMESHGUI::GetScalarBar()
373 vtkRenderer *aRenderer =
374 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
375 getRightFrame()->getViewFrame())->getRenderer();
376 vtkActor2DCollection *actor2DList = aRenderer->GetActors2D();
377 actor2DList->InitTraversal();
378 vtkActor2D *aActor2d = actor2DList->GetNextActor2D();
379 while (aActor2d != NULL)
381 if (aActor2d->IsA("vtkScalarBarActor"))
382 return vtkScalarBarActor::SafeDownCast(aActor2d);
383 actor2DList->GetNextActor2D();
388 //=============================================================================
392 //=============================================================================
393 void SMESHGUI::activeStudyChanged(QAD_Desktop * parent)
395 MESSAGE("SMESHGUI::activeStudyChanged init.")
396 /* Create or retrieve an object SMESHGUI */
397 SMESHGUI::GetOrCreateSMESHGUI(parent);
400 smeshGUI->EmitSignalCloseAllDialogs();
401 MESSAGE("Active study changed : SMESHGUI nullified" << endl);
405 //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
406 MESSAGE("SMESHGUI::activeStudyChanged done.") return;
409 //=============================================================================
413 //=============================================================================
414 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
416 /* Here the position is on the bottom right corner - 10 */
417 aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
418 QAD_Desktop *PP = QAD_Application::getDesktop();
419 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
420 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
424 //=============================================================================
428 //=============================================================================
429 void SMESHGUI::EraseSimulationActors()
431 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
433 vtkRenderer *theRenderer =
434 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
435 getRightFrame()->getViewFrame())->getRenderer();
436 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
438 if (mySimulationActors != NULL)
441 mySimulationActors->InitTraversal();
442 vtkActor *ac = mySimulationActors->GetNextActor();
443 while (!(ac == NULL))
445 theRenderer->RemoveActor(ac);
446 ac = mySimulationActors->GetNextActor();
448 mySimulationActors->RemoveAllItems();
450 if (mySimulationActors2D != NULL)
452 mySimulationActors2D->InitTraversal();
453 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
454 while (!(ac == NULL))
456 theRenderer->RemoveActor2D(ac);
457 ac = mySimulationActors2D->GetNextActor2D();
459 mySimulationActors2D->RemoveAllItems();
465 //=============================================================================
469 //=============================================================================
470 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh(GEOM::GEOM_Shape_ptr aShape,
475 if (!myComponentMesh->_is_nil() && !aShape->_is_nil())
477 SMESH::SMESH_Mesh_var aMesh =
478 myComponentMesh->Init(myComponentGeom, myStudyId, aShape);
480 if (!aMesh->_is_nil())
482 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh(aMesh);
483 myStudyAPI.SetName(SM, NameMesh);
485 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
486 // not after loading from file, so let's use more reliable way to retrieve SObject
487 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
488 SALOMEDS::SObject_var SObject =
489 myStudy->FindObjectIOR(ShapeIOR);
490 if (!SObject->_is_nil() && !SM->_is_nil())
492 myStudyAPI.SetShape(SM, SObject);
494 return SMESH::SMESH_Mesh::_narrow(aMesh);
498 catch(const SALOME::SALOME_Exception & S_ex)
500 QtCatchCorbaException(S_ex);
502 myActiveStudy->updateObjBrowser(true);
503 return SMESH::SMESH_Mesh::_nil();
506 //=============================================================================
510 //=============================================================================
511 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh(SMESH::SMESH_Mesh_ptr aMesh,
512 GEOM::GEOM_Shape_ptr aShape, QString NameMesh)
516 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
517 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
518 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
519 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
521 if (!SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() &&
522 !aSubMesh->_is_nil() && !aMesh->_is_nil())
524 SALOMEDS::SObject_var SO =
525 myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh,
526 aShape->ShapeType());
527 myStudyAPI.SetName(SO, NameMesh);
529 SMESH_Actor *amesh = SMESH_Actor::New();
530 Handle(SALOME_InteractiveObject) IO =
531 new SALOME_InteractiveObject(SO->GetID(), "MESH",
534 amesh->setName(strdup(NameMesh));
535 DisplayActor(amesh, false);
536 return SMESH::SMESH_subMesh::_narrow(aSubMesh);
539 catch(const SALOME::SALOME_Exception & S_ex)
541 QtCatchCorbaException(S_ex);
543 myActiveStudy->updateObjBrowser(true);
544 return SMESH::SMESH_subMesh::_nil();
547 //=============================================================================
551 //=============================================================================
552 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis(QString TypeHypothesis,
553 QString NameHypothesis)
555 SMESH::SMESH_Hypothesis_var Hyp;
558 Hyp = myComponentMesh->CreateHypothesis(TypeHypothesis, myStudyId);
561 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis(Hyp);
562 myStudyAPI.SetName(SHyp, NameHypothesis);
565 catch(const SALOME::SALOME_Exception & S_ex)
567 QtCatchCorbaException(S_ex);
570 return SMESH::SMESH_Hypothesis::_narrow(Hyp);
573 //=============================================================================
577 //=============================================================================
578 void SMESHGUI::AddHypothesisOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
579 SMESH::SMESH_Hypothesis_ptr aHyp)
581 if (!aMesh->_is_nil())
583 QApplication::setOverrideCursor(Qt::waitCursor);
584 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
585 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
588 bool res = aMesh->AddHypothesis(aShape, aHyp);
591 SALOMEDS::SObject_var SH =
592 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
593 if (!SM->_is_nil() && !SH->_is_nil())
595 myStudyAPI.SetHypothesis(SM, SH);
596 myStudyAPI.ModifiedMesh(SM, false);
598 QApplication::restoreOverrideCursor();
602 QApplication::restoreOverrideCursor();
603 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
604 tr("SMESH_WRN_WARNING"),
605 tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
606 tr("SMESH_BUT_YES"));
609 catch(const SALOME::SALOME_Exception & S_ex)
611 QtCatchCorbaException(S_ex);
614 myActiveStudy->updateObjBrowser(true);
615 QApplication::restoreOverrideCursor();
618 //=============================================================================
622 //=============================================================================
624 RemoveHypothesisOrAlgorithmOnMesh(const Handle(SALOME_InteractiveObject) &
627 if (IObject->hasReference())
629 SMESH::SMESH_Hypothesis_var anHyp;
630 SALOMEDS::SObject_var SO_Hypothesis =
631 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
632 SALOMEDS::GenericAttribute_var anAttr;
633 SALOMEDS::AttributeIOR_var anIOR;
635 if (!SO_Hypothesis->_is_nil())
637 QApplication::setOverrideCursor(Qt::waitCursor);
638 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR"))
640 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
642 SMESH::SMESH_Hypothesis::_narrow(_orb->
643 string_to_object(anIOR->Value()));
646 SALOMEDS::SObject_var SO_Applied_Hypothesis =
647 smeshGUI->myStudy->FindObjectID(IObject->getReference());
648 if (!SO_Applied_Hypothesis->_is_nil())
650 SALOMEDS::SObject_var MorSM =
651 smeshGUI->myStudyAPI.
652 GetMeshOrSubmesh(SO_Applied_Hypothesis);
653 if (!MorSM->_is_nil())
655 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
657 GEOM::GEOM_Shape_var aShape =
658 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
659 if (!aShape->_is_nil())
661 if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
663 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
664 SMESH::SMESH_Mesh_var aMesh =
665 SMESH::SMESH_Mesh::_narrow(_orb->
666 string_to_object(anIOR->Value()));
667 SMESH::SMESH_subMesh_var aSubMesh =
668 SMESH::SMESH_subMesh::_narrow(_orb->
669 string_to_object(anIOR->Value()));
670 if (!aMesh->_is_nil())
673 aMesh->RemoveHypothesis(aShape, anHyp);
676 QApplication::restoreOverrideCursor();
677 QAD_MessageBox::warn1(QAD_Application::
678 getDesktop(), tr("SMESH_WRN_WARNING"),
679 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
680 tr("SMESH_BUT_YES"));
683 else if (!aSubMesh->_is_nil())
685 aMesh = aSubMesh->GetFather();
686 if (!aMesh->_is_nil())
689 aMesh->RemoveHypothesis(aShape, anHyp);
692 QApplication::restoreOverrideCursor();
693 QAD_MessageBox::warn1(QAD_Application::
695 tr("SMESH_WRN_WARNING"),
696 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
697 tr("SMESH_BUT_YES"));
701 if (myAutomaticUpdate)
703 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
711 smeshGUI->ChangeRepresentation(Mesh,
712 Mesh->getDisplayMode());
718 smeshGUI->myStudyAPI.UnSetHypothesis(SO_Applied_Hypothesis);
722 else if (IObject->hasEntry())
724 MESSAGE("IObject entry " << IObject->getEntry())}
725 QApplication::restoreOverrideCursor();
728 //=============================================================================
732 //=============================================================================
733 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh(SALOMEDS::SObject_ptr MorSM,
734 SMESH::SMESH_Hypothesis_ptr anHyp)
736 SALOMEDS::SObject_var AHR, aRef;
737 SALOMEDS::GenericAttribute_var anAttr;
738 SALOMEDS::AttributeIOR_var anIOR;
740 if (!MorSM->_is_nil())
742 GEOM::GEOM_Shape_var aShape =
743 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
744 if (!aShape->_is_nil())
746 if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
748 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
749 SMESH::SMESH_Mesh_var aMesh =
750 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
752 SMESH::SMESH_subMesh_var aSubMesh =
753 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
755 if (!aMesh->_is_nil())
757 bool res = aMesh->RemoveHypothesis(aShape, anHyp);
760 QApplication::restoreOverrideCursor();
761 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
762 tr("SMESH_WRN_WARNING"),
763 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
764 tr("SMESH_BUT_YES"));
767 else if (!aSubMesh->_is_nil())
769 aMesh = aSubMesh->GetFather();
770 if (!aMesh->_is_nil())
772 bool res = aMesh->RemoveHypothesis(aShape, anHyp);
775 QApplication::restoreOverrideCursor();
776 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
777 tr("SMESH_WRN_WARNING"),
778 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
779 tr("SMESH_BUT_YES"));
783 if (myAutomaticUpdate)
785 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
793 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
799 if (MorSM->FindSubObject(2, AHR))
801 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
802 for (; it->More(); it->Next())
804 SALOMEDS::SObject_var Obj = it->Value();
805 if (Obj->ReferencedObject(aRef))
807 if (aRef->FindAttribute(anAttr, "AttributeIOR"))
809 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
810 if (strcmp(anIOR->Value(),
811 _orb->object_to_string(anHyp)) == 0)
813 smeshGUI->myStudyAPI.UnSetHypothesis(Obj);
820 if (MorSM->FindSubObject(3, AHR))
822 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
823 for (; it->More(); it->Next())
825 SALOMEDS::SObject_var Obj = it->Value();
826 if (Obj->ReferencedObject(aRef))
828 if (aRef->FindAttribute(anAttr, "AttributeIOR"))
830 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
831 if (strcmp(anIOR->Value(),
832 _orb->object_to_string(anHyp)) == 0)
834 smeshGUI->myStudyAPI.UnSetAlgorithm(Obj);
841 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
843 QApplication::restoreOverrideCursor();
846 //=============================================================================
850 //=============================================================================
851 void SMESHGUI::AddAlgorithmOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
852 SMESH::SMESH_Hypothesis_ptr aHyp)
854 if (!aMesh->_is_nil())
856 QApplication::setOverrideCursor(Qt::waitCursor);
857 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
858 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
861 bool res = aMesh->AddHypothesis(aShape, aHyp);
864 SALOMEDS::SObject_var SH =
865 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
866 if (!SM->_is_nil() && !SH->_is_nil())
868 myStudyAPI.SetAlgorithms(SM, SH);
869 myStudyAPI.ModifiedMesh(SM, false);
874 QApplication::restoreOverrideCursor();
875 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
876 tr("SMESH_WRN_WARNING"),
877 tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
878 tr("SMESH_BUT_YES"));
881 catch(const SALOME::SALOME_Exception & S_ex)
883 QtCatchCorbaException(S_ex);
886 myActiveStudy->updateObjBrowser(true);
887 QApplication::restoreOverrideCursor();
890 //=============================================================================
894 //=============================================================================
895 void SMESHGUI::AddHypothesisOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
896 SMESH::SMESH_Hypothesis_ptr aHyp)
898 if (!aSubMesh->_is_nil())
900 QApplication::setOverrideCursor(Qt::waitCursor);
903 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
904 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
905 GEOM::GEOM_Shape_var aShape =
906 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
907 if (!aMesh->_is_nil())
909 bool res = aMesh->AddHypothesis(aShape, aHyp);
912 SALOMEDS::SObject_var SH =
913 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
914 if (!SsubM->_is_nil() && !SH->_is_nil())
916 myStudyAPI.SetHypothesis(SsubM, SH);
917 myStudyAPI.ModifiedMesh(SsubM, false);
922 QApplication::restoreOverrideCursor();
923 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
924 tr("SMESH_WRN_WARNING"),
925 tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
926 tr("SMESH_BUT_YES"));
930 catch(const SALOME::SALOME_Exception & S_ex)
932 QtCatchCorbaException(S_ex);
935 myActiveStudy->updateObjBrowser(true);
936 QApplication::restoreOverrideCursor();
939 //=============================================================================
943 //=============================================================================
944 void SMESHGUI::AddAlgorithmOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
945 SMESH::SMESH_Hypothesis_ptr aHyp)
947 if (!aSubMesh->_is_nil())
949 QApplication::setOverrideCursor(Qt::waitCursor);
952 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
953 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
954 GEOM::GEOM_Shape_var aShape =
955 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
956 if (!aMesh->_is_nil())
958 bool res = aMesh->AddHypothesis(aShape, aHyp);
961 SALOMEDS::SObject_var SH =
962 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
963 if (!SsubM->_is_nil() && !SH->_is_nil())
965 myStudyAPI.SetAlgorithms(SsubM, SH);
966 myStudyAPI.ModifiedMesh(SsubM, false);
971 QApplication::restoreOverrideCursor();
972 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
973 tr("SMESH_WRN_WARNING"),
974 tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
975 tr("SMESH_BUT_YES"));
979 catch(const SALOME::SALOME_Exception & S_ex)
981 QtCatchCorbaException(S_ex);
984 myActiveStudy->updateObjBrowser(true);
985 QApplication::restoreOverrideCursor();
988 //=============================================================================
992 //=============================================================================
993 void SMESHGUI::CreateAlgorithm(QString TypeAlgo, QString NameAlgo)
995 SMESH::SMESH_Hypothesis_var Hyp;
998 if (TypeAlgo.compare("Regular_1D") == 0)
999 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1000 else if (TypeAlgo.compare("MEFISTO_2D") == 0)
1001 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1002 else if (TypeAlgo.compare("Quadrangle_2D") == 0)
1003 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1004 else if (TypeAlgo.compare("Hexa_3D") == 0)
1005 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1006 else if (TypeAlgo.compare("NETGEN_3D") == 0)
1007 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
1009 if (!Hyp->_is_nil())
1011 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms(Hyp);
1012 myStudyAPI.SetName(SHyp, NameAlgo);
1015 catch(const SALOME::SALOME_Exception & S_ex)
1017 QtCatchCorbaException(S_ex);
1019 myActiveStudy->updateObjBrowser(true);
1022 //=============================================================================
1026 //=============================================================================
1027 void SMESHGUI::CreateLocalLength(QString TypeHypothesis, QString NameHypothesis,
1030 QApplication::setOverrideCursor(Qt::waitCursor);
1033 SMESH::SMESH_Hypothesis_var Hyp =
1034 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1036 SMESH::SMESH_LocalLength_var LL =
1037 SMESH::SMESH_LocalLength::_narrow(Hyp);
1039 LL->SetLength(Length);
1041 catch(const SALOME::SALOME_Exception & S_ex)
1043 QtCatchCorbaException(S_ex);
1045 myActiveStudy->updateObjBrowser(true);
1046 QApplication::restoreOverrideCursor();
1049 //=============================================================================
1053 //=============================================================================
1054 void SMESHGUI::CreateMaxElementArea(QString TypeHypothesis,
1055 QString NameHypothesis, double MaxArea)
1057 QApplication::setOverrideCursor(Qt::waitCursor);
1060 SMESH::SMESH_Hypothesis_var Hyp =
1061 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1063 SMESH::SMESH_MaxElementArea_var MaxElArea =
1064 SMESH::SMESH_MaxElementArea::_narrow(Hyp);
1065 if (!MaxElArea->_is_nil())
1066 MaxElArea->SetMaxElementArea(MaxArea);
1068 catch(SALOME::SALOME_Exception & S_ex)
1070 QtCatchCorbaException(S_ex);
1073 myActiveStudy->updateObjBrowser(true);
1074 QApplication::restoreOverrideCursor();
1077 //=============================================================================
1081 //=============================================================================
1082 void SMESHGUI::CreateMaxElementVolume(QString TypeHypothesis,
1083 QString NameHypothesis, double MaxVolume)
1085 QApplication::setOverrideCursor(Qt::waitCursor);
1088 SMESH::SMESH_Hypothesis_var Hyp =
1089 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1091 SMESH::SMESH_MaxElementVolume_var MaxElVolume =
1092 SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
1093 if (!MaxElVolume->_is_nil())
1094 MaxElVolume->SetMaxElementVolume(MaxVolume);
1096 catch(const SALOME::SALOME_Exception & S_ex)
1098 QtCatchCorbaException(S_ex);
1100 myActiveStudy->updateObjBrowser(true);
1101 QApplication::restoreOverrideCursor();
1104 //=============================================================================
1108 //=============================================================================
1109 void SMESHGUI::CreateNbSegments(QString TypeHypothesis, QString NameHypothesis,
1112 QApplication::setOverrideCursor(Qt::waitCursor);
1115 SMESH::SMESH_Hypothesis_var Hyp =
1116 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1118 SMESH::SMESH_NumberOfSegments_var NbS =
1119 SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
1120 if (!NbS->_is_nil())
1121 NbS->SetNumberOfSegments(nbSegments);
1123 catch(const SALOME::SALOME_Exception & S_ex)
1125 QtCatchCorbaException(S_ex);
1127 myActiveStudy->updateObjBrowser(true);
1128 QApplication::restoreOverrideCursor();
1131 //=============================================================================
1135 //=============================================================================
1136 int SMESHGUI::GetNameOfSelectedIObjects(SALOME_Selection * Sel, QString & aName)
1138 int nbSel = Sel->IObjectCount();
1141 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1142 aName = IObject->getName();
1146 aName = tr("SMESH_OBJECTS_SELECTED").arg(nbSel);
1151 //=============================================================================
1155 //=============================================================================
1156 int SMESHGUI::GetNameOfSelectedNodes(SALOME_Selection * Sel, QString & aName)
1159 int nbSel = Sel->IObjectCount();
1162 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1163 if (!IObject->hasEntry())
1166 Standard_Boolean res;
1167 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1171 TColStd_MapOfInteger MapIndex;
1172 Sel->GetIndex(IObject, MapIndex);
1173 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1175 nbNodes = MapIndex.Extent();
1176 for (; ite.More(); ite.Next())
1179 aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) +
1190 //=============================================================================
1194 //=============================================================================
1195 int SMESHGUI::GetNameOfSelectedElements(SALOME_Selection * Sel, QString & aName)
1198 int nbSel = Sel->IObjectCount();
1201 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1202 if (!IObject->hasEntry())
1205 Standard_Boolean res;
1206 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1210 TColStd_MapOfInteger MapIndex;
1211 Sel->GetIndex(IObject, MapIndex);
1212 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1214 nbElements = MapIndex.Extent();
1215 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1216 for (; ite.More(); ite.Next())
1218 int idVTK = ite.Key();
1219 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1221 aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1231 //=============================================================================
1235 //=============================================================================
1236 int SMESHGUI::GetNameOfSelectedEdges(SALOME_Selection * Sel, QString & aName)
1239 int nbSel = Sel->IObjectCount();
1242 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1243 if (!IObject->hasEntry())
1246 Standard_Boolean res;
1247 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1251 TColStd_MapOfInteger MapIndex;
1252 Sel->GetIndex(IObject, MapIndex);
1253 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1255 nbElements = MapIndex.Extent();
1256 for (; ite.More(); ite.Next())
1258 aName = aName + QString("%1").arg(ite.Key()) + " ";
1268 //=============================================================================
1272 //=============================================================================
1273 SMESH_Actor *SMESHGUI::FindActorByEntry(QString entry,
1274 Standard_Boolean & testResult, bool onlyInActiveView)
1276 int nbSf = myActiveStudy->getStudyFramesCount();
1277 for (int i = 0; i < nbSf; i++)
1279 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
1280 if (sf->getTypeView() == VIEW_VTK)
1282 vtkRenderer *Renderer =
1283 ((VTKViewer_ViewFrame *) sf->getRightFrame()->getViewFrame())->
1285 vtkActorCollection *theActors = Renderer->GetActors();
1286 theActors->InitTraversal();
1287 vtkActor *ac = theActors->GetNextActor();
1288 while (!(ac == NULL))
1290 if (ac->IsA("SMESH_Actor"))
1292 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
1293 if (anActor->hasIO())
1295 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1296 if (strcmp(IO->getEntry(), entry) == 0)
1298 if (onlyInActiveView)
1300 if (sf == myActiveStudy->getActiveStudyFrame())
1314 ac = theActors->GetNextActor();
1319 MESSAGE(" Actor Not Found ") testResult = false;
1320 return SMESH_Actor::New();
1323 //=============================================================================
1327 //=============================================================================
1328 SMESH_Actor *SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1329 Standard_Boolean & testResult, bool onlyInActiveView)
1331 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
1334 MESSAGE(" Actor Not Found ") testResult = false;
1335 return SMESH_Actor::New();
1338 return FindActorByEntry(SM->GetID(), testResult, onlyInActiveView);
1341 //=============================================================================
1345 //=============================================================================
1346 SMESH::SMESH_Mesh_ptr SMESHGUI::
1347 ConvertIOinMesh(const Handle(SALOME_InteractiveObject) & IO,
1348 Standard_Boolean & testResult)
1350 SMESH::SMESH_Mesh_var aMesh;
1356 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1357 SALOMEDS::GenericAttribute_var anAttr;
1358 SALOMEDS::AttributeIOR_var anIOR;
1359 if (!obj->_is_nil())
1361 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1363 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1365 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
1367 if (!aMesh->_is_nil())
1370 return SMESH::SMESH_Mesh::_duplicate(aMesh);
1375 return SMESH::SMESH_Mesh::_nil();
1378 //=============================================================================
1382 //=============================================================================
1383 SMESH::SMESH_subMesh_ptr SMESHGUI::
1384 ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject) & IO,
1385 Standard_Boolean & testResult)
1387 SMESH::SMESH_subMesh_var aSubMesh;
1393 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1394 SALOMEDS::GenericAttribute_var anAttr;
1395 SALOMEDS::AttributeIOR_var anIOR;
1396 if (!obj->_is_nil())
1398 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1400 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1402 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
1404 if (!aSubMesh->_is_nil())
1407 return SMESH::SMESH_subMesh::_duplicate(aSubMesh);
1412 return SMESH::SMESH_subMesh::_nil();
1415 //=============================================================================
1419 //=============================================================================
1420 SMESH::SMESH_Hypothesis_ptr SMESHGUI::
1421 ConvertIOinSMESHHypothesis(const Handle(SALOME_InteractiveObject) & IO,
1422 Standard_Boolean & testResult)
1424 SMESH::SMESH_Hypothesis_var aHyp;
1430 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1431 SALOMEDS::GenericAttribute_var anAttr;
1432 SALOMEDS::AttributeIOR_var anIOR;
1433 if (!obj->_is_nil())
1435 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1437 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1439 SMESH::SMESH_Hypothesis::_narrow(_orb->
1440 string_to_object(anIOR->Value()));
1441 if (!aHyp->_is_nil())
1444 return SMESH::SMESH_Hypothesis::_duplicate(aHyp);
1449 return SMESH::SMESH_Hypothesis::_nil();
1452 //=============================================================================
1456 //=============================================================================
1457 GEOM::GEOM_Shape_ptr SMESHGUI::
1458 ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject) & IO,
1459 Standard_Boolean & testResult)
1461 GEOM::GEOM_Shape_var aShape;
1467 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1468 SALOMEDS::GenericAttribute_var anAttr;
1469 SALOMEDS::AttributeIOR_var anIOR;
1470 if (!obj->_is_nil())
1472 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1474 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1475 aShape = myComponentGeom->GetIORFromString(anIOR->Value());
1476 if (!aShape->_is_nil())
1479 return GEOM::GEOM_Shape::_duplicate(aShape);
1484 return GEOM::GEOM_Shape::_nil();
1487 //=============================================================================
1491 //=============================================================================
1492 void SMESHGUI::SetViewMode(int commandId)
1494 SALOME_Selection *Sel =
1495 SALOME_Selection::Selection(myActiveStudy->getSelection());
1496 int nbSel = Sel->IObjectCount();
1499 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1500 for (; It.More(); It.Next())
1502 Handle(SALOME_InteractiveObject) IObject = It.Value();
1503 if (IObject->hasEntry())
1505 Standard_Boolean res;
1507 FindActorByEntry(IObject->getEntry(), res, true);
1514 ChangeRepresentation(ac, 0);
1519 ChangeRepresentation(ac, 1);
1524 ChangeRepresentation(ac, 2);
1529 ChangeRepresentation(ac, 3);
1536 if (commandId == 1133)
1538 ChangeRepresentation(SMESH_Actor::New(), 4);
1543 //=============================================================================
1547 //=============================================================================
1548 void SMESHGUI::ChangeRepresentation(SMESH_Actor * ac, int type)
1550 if (ac->DataSource == NULL && type != 4)
1555 if (ac->getMapper() == NULL)
1564 QApplication::setOverrideCursor(Qt::waitCursor);
1565 if (ac->getDisplayMode() == 2)
1567 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1568 vtkDataSetMapper *meshMapper =
1569 (vtkDataSetMapper *) (ac->getMapper());
1570 meshMapper->SetInput(ac->DataSource);
1571 meshMapper->SetScalarVisibility(isColored); //SAL3899
1573 ac->setDisplayMode(0);
1574 ac->GetProperty()->SetRepresentationToWireframe();
1575 // ac->SetActorProperty( ac->GetProperty() );
1576 QApplication::restoreOverrideCursor();
1581 QApplication::setOverrideCursor(Qt::waitCursor);
1582 if (ac->getDisplayMode() == 2)
1584 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1585 vtkDataSetMapper *meshMapper =
1586 (vtkDataSetMapper *) (ac->getMapper());
1587 meshMapper->SetInput(ac->DataSource);
1588 meshMapper->SetScalarVisibility(isColored); //SAL3899
1590 ac->setDisplayMode(1);
1591 ac->GetProperty()->SetRepresentationToSurface();
1592 QApplication::restoreOverrideCursor();
1593 // ac->SetActorProperty( ac->GetProperty() );
1598 // if (!(ac->getDisplayMode()==2)) {
1599 // ChangeRepresentation(ac, 1);
1600 QApplication::setOverrideCursor(Qt::waitCursor);
1601 ac->setDisplayMode(2);
1602 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1603 vtkDataSetMapper *meshMapper = (vtkDataSetMapper *) (ac->getMapper());
1604 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1605 shrink->SetInput(ac->DataSource);
1606 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1608 meshMapper->SetInput(shrink->GetOutput());
1609 meshMapper->SetScalarVisibility(isColored); //SAL3899
1610 ac->SetMapper(meshMapper);
1611 QApplication::restoreOverrideCursor();
1619 float backfacecolor[3];
1621 ac->GetColor(color[0], color[1], color[2]);
1622 // QColor c(color[0]*255,color[1]*255,color[2]*255);
1623 int c0 = int (color[0] * 255);
1624 int c1 = int (color[1] * 255);
1625 int c2 = int (color[2] * 255);
1626 QColor c(c0, c1, c2);
1627 ac->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1628 // QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1629 c0 = int (edgecolor[0] * 255);
1630 c1 = int (edgecolor[1] * 255);
1631 c2 = int (edgecolor[2] * 255);
1632 QColor e(c0, c1, c2);
1633 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1634 // QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1635 c0 = int (backfacecolor[0] * 255);
1636 c1 = int (backfacecolor[1] * 255);
1637 c2 = int (backfacecolor[2] * 255);
1638 QColor b(c0, c1, c2);
1639 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1640 // QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1641 c0 = int (nodecolor[0] * 255);
1642 c1 = int (nodecolor[1] * 255);
1643 c2 = int (nodecolor[2] * 255);
1644 QColor n(c0, c1, c2);
1646 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1649 int intValue = ac->GetNodeSize();
1650 float Shrink = ac->GetShrinkFactor();
1652 SMESHGUI_Preferences_ColorDlg *aDlg =
1653 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),
1655 aDlg->SetColor(1, c);
1656 aDlg->SetColor(2, e);
1657 aDlg->SetColor(3, n);
1658 aDlg->SetColor(4, b);
1659 aDlg->SetIntValue(1, Edgewidth);
1660 aDlg->SetIntValue(2, intValue);
1661 aDlg->SetIntValue(3, int (Shrink * 100.));
1665 QApplication::setOverrideCursor(Qt::waitCursor);
1666 QColor color = aDlg->GetColor(1);
1667 QColor edgecolor = aDlg->GetColor(2);
1668 QColor nodecolor = aDlg->GetColor(3);
1669 QColor backfacecolor = aDlg->GetColor(4);
1670 /* actor color and backface color */
1671 ac->GetProperty()->SetColor(float (color.red()) / 255.,
1672 float (color.green()) / 255., float (color.blue()) / 255.);
1673 ac->SetColor(float (color.red()) / 255.,
1674 float (color.green()) / 255., float (color.blue()) / 255.);
1675 ac->GetBackfaceProperty()->SetColor(float (backfacecolor.red()) /
1676 255., float (backfacecolor.green()) / 255.,
1677 float (backfacecolor.blue()) / 255.);
1680 ac->EdgeDevice->GetProperty()->SetColor(float (edgecolor.red()) /
1681 255., float (edgecolor.green()) / 255.,
1682 float (edgecolor.blue()) / 255.);
1683 ac->EdgeShrinkDevice->GetProperty()->SetColor(float (edgecolor.
1684 red()) / 255., float (edgecolor.green()) / 255.,
1685 float (edgecolor.blue()) / 255.);
1686 ac->SetEdgeColor(float (edgecolor.red()) / 255.,
1687 float (edgecolor.green()) / 255.,
1688 float (edgecolor.blue()) / 255.);
1690 /* Shrink factor and size edges */
1691 ac->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
1692 ac->EdgeDevice->GetProperty()->SetLineWidth(aDlg->GetIntValue(1));
1693 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth(aDlg->
1696 /* Nodes color and size */
1697 ac->SetNodeColor(float (nodecolor.red()) / 255.,
1698 float (nodecolor.green()) / 255.,
1699 float (nodecolor.blue()) / 255.);
1700 ac->SetNodeSize(aDlg->GetIntValue(2));
1702 if (ac->getDisplayMode() == 2)
1704 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1705 vtkDataSetMapper *meshMapper =
1706 (vtkDataSetMapper *) (ac->getMapper());
1707 meshMapper->SetInput(ac->DataSource);
1708 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1709 shrink->SetInput(meshMapper->GetInput());
1710 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1712 meshMapper->SetInput(shrink->GetOutput());
1713 meshMapper->SetScalarVisibility(isColored); //SAL3899
1714 ac->SetMapper(meshMapper);
1718 QApplication::restoreOverrideCursor();
1723 EmitSignalDeactivateDialog();
1724 SALOME_Selection *Sel =
1725 SALOME_Selection::Selection(myActiveStudy->getSelection());
1726 SMESHGUI_TransparencyDlg *aDlg =
1727 new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(), "",
1733 QApplication::setOverrideCursor(Qt::waitCursor);
1734 ac->GetProperty()->SetRepresentationToPoints();
1735 QApplication::restoreOverrideCursor();
1740 QApplication::setOverrideCursor(Qt::waitCursor);
1741 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
1743 vtkRenderer *theRenderer =
1744 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1745 getRightFrame()->getViewFrame())->getRenderer();
1746 theRenderer->Render();
1748 QApplication::restoreOverrideCursor();
1751 //=============================================================================
1755 //=============================================================================
1756 void SMESHGUI::UpdateView()
1758 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1761 vtkRenderer *theRenderer =
1762 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1763 getRightFrame()->getViewFrame())->getRenderer();
1764 theRenderer->Render();
1767 //=============================================================================
1771 //=============================================================================
1772 void SMESHGUI::DisplayActor(SMESH_Actor * ac, bool visibility)
1774 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1777 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1779 vtkRenderer *theRenderer =
1780 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1781 getRightFrame()->getViewFrame())->getRenderer();
1782 vtkActorCollection *theActors = theRenderer->GetActors();
1783 theActors->InitTraversal();
1784 if (theActors->IsItemPresent(ac) == 0)
1786 vtkProperty *prop = vtkProperty::New();
1787 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1789 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1791 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1794 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
1796 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
1798 ac->SetProperty(prop);
1799 ac->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1801 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1803 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1806 // prop->BackfaceCullingOn();
1807 vtkProperty *backprop = vtkProperty::New();
1808 backprop->SetColor(QAD_CONFIG->
1809 getSetting("SMESH:SettingsBackFaceColorRed").toFloat() / 255.,
1810 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").
1812 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").
1814 ac->SetBackfaceProperty(backprop);
1817 QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1820 ac->SetShrinkFactor(intValue / 100.);
1822 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1823 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1825 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1826 if (DisplayMode.compare("Wireframe") == 0)
1828 ac->setDisplayMode(0);
1829 ChangeRepresentation(ac, 0);
1831 else if (DisplayMode.compare("Shading") == 0)
1833 ac->setDisplayMode(1);
1834 ChangeRepresentation(ac, 1);
1836 else if (DisplayMode.compare("Shrink") == 0)
1838 ac->setDisplayMode(2);
1839 ChangeRepresentation(ac, 2);
1841 theRenderer->AddActor(ac);
1845 if (ac->GetMapper())
1846 ac->GetMapper()->Update();
1849 // if ( visibility )
1850 ac->SetVisibility(visibility);
1851 // ac->VisibilityOn();
1853 // ac->VisibilityOff();
1855 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1859 //=============================================================================
1863 //=============================================================================
1864 void SMESHGUI::EraseActor(SMESH_Actor * ac)
1866 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1869 vtkRenderer *theRenderer =
1870 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1871 getRightFrame()->getViewFrame())->getRenderer();
1873 //NRI- : 02/12/2002 : Fixed bugId 882
1874 // ac->EdgeDevice->VisibilityOff();
1875 // ac->EdgeShrinkDevice->VisibilityOff();
1876 // ac->VisibilityOff();
1877 ac->SetVisibility(false);
1879 theRenderer->Render();
1882 //=============================================================================
1886 //=============================================================================
1887 bool SMESHGUI::AddActorInSelection(SMESH_Actor * ac)
1889 SALOME_Selection *Sel =
1890 SALOME_Selection::Selection(myActiveStudy->getSelection());
1891 Sel->ClearIObjects();
1893 return Sel->AddIObject(ac->getIO());
1898 //=============================================================================
1902 //=============================================================================
1903 QString SMESHGUI::CheckHomogeneousSelection()
1905 SALOME_Selection *Sel =
1906 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1909 SALOME_ListIteratorOfListIO Itinit(Sel->StoredIObjects());
1910 for (; Itinit.More(); Itinit.Next())
1912 List.Append(Itinit.Value());
1915 QString RefType = CheckTypeObject(Sel->firstIObject());
1916 SALOME_ListIteratorOfListIO It(List);
1917 for (; It.More(); It.Next())
1919 Handle(SALOME_InteractiveObject) IObject = It.Value();
1920 QString Type = CheckTypeObject(IObject);
1921 if (Type.compare(RefType) != 0)
1922 return "Heterogeneous Selection";
1925 Sel->ClearIObjects();
1926 SALOME_ListIteratorOfListIO It1(List);
1927 for (; It1.More(); It1.Next())
1929 int res = Sel->AddIObject(It1.Value());
1931 myActiveStudy->highlight(It1.Value(), false);
1933 myActiveStudy->highlight(It1.Value(), true);
1938 //=============================================================================
1942 //=============================================================================
1943 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject) & IO)
1945 SALOMEDS::SObject_var sobj =
1946 smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->
1948 if (!sobj->_is_nil())
1950 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1951 if (strcmp(scomp->GetID(), IO->getEntry()) == 0)
1952 { // component is selected
1957 SALOME_Selection *Sel =
1958 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1959 Sel->ClearIObjects();
1961 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter(HYPOTHESIS);
1962 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter(ALGORITHM);
1963 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter(MESH);
1964 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter(SUBMESH);
1965 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter =
1966 new SMESH_TypeFilter(MESHorSUBMESH);
1967 Handle(SMESH_TypeFilter) aSubMeshVextexFilter =
1968 new SMESH_TypeFilter(SUBMESH_VERTEX);
1969 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter =
1970 new SMESH_TypeFilter(SUBMESH_EDGE);
1971 Handle(SMESH_TypeFilter) aSubMeshFaceFilter =
1972 new SMESH_TypeFilter(SUBMESH_FACE);
1973 Handle(SMESH_TypeFilter) aSubMeshSolidFilter =
1974 new SMESH_TypeFilter(SUBMESH_SOLID);
1975 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter =
1976 new SMESH_TypeFilter(SUBMESH_COMPOUND);
1978 Sel->AddFilter(aHypFilter);
1979 if (Sel->AddIObject(IO) != -1)
1981 Sel->ClearFilters();
1982 return "Hypothesis";
1985 Sel->ClearFilters();
1986 Sel->AddFilter(anAlgoFilter);
1987 if (Sel->AddIObject(IO) != -1)
1989 Sel->ClearFilters();
1993 Sel->ClearFilters();
1994 Sel->AddFilter(aMeshFilter);
1995 if (Sel->AddIObject(IO) != -1)
1997 Sel->ClearFilters();
2001 Sel->ClearFilters();
2002 Sel->AddFilter(aSubMeshFilter);
2003 if (Sel->AddIObject(IO) != -1)
2005 Sel->ClearFilters();
2009 Sel->ClearFilters();
2010 Sel->AddFilter(aSubMeshVextexFilter);
2011 if (Sel->AddIObject(IO) != -1)
2013 Sel->ClearFilters();
2014 return "SubMeshVertex";
2017 Sel->ClearFilters();
2018 Sel->AddFilter(aSubMeshEdgeFilter);
2019 if (Sel->AddIObject(IO) != -1)
2021 Sel->ClearFilters();
2022 return "SubMeshEdge";
2025 Sel->ClearFilters();
2026 Sel->AddFilter(aSubMeshFaceFilter);
2027 if (Sel->AddIObject(IO) != -1)
2029 Sel->ClearFilters();
2030 return "SubMeshFace";
2033 Sel->ClearFilters();
2034 Sel->AddFilter(aSubMeshSolidFilter);
2035 if (Sel->AddIObject(IO) != -1)
2037 Sel->ClearFilters();
2038 return "SubMeshSolid";
2041 Sel->ClearFilters();
2042 Sel->AddFilter(aSubMeshCompoundFilter);
2043 if (Sel->AddIObject(IO) != -1)
2045 Sel->ClearFilters();
2046 return "SubMeshCompound";
2049 Sel->ClearFilters();
2050 Sel->AddIObject(IO);
2054 //=============================================================================
2058 //=============================================================================
2059 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
2061 /* Create or retrieve an object SMESHGUI */
2062 SMESHGUI::GetOrCreateSMESHGUI(parent);
2064 // NRI : Temporary added
2065 if (smeshGUI->myStudy->GetProperties()->IsLocked())
2071 // QAD_Viewer3d* v3d;
2072 OCCViewer_Viewer3d *v3d;
2074 Handle(AIS_InteractiveContext) ic;
2075 vtkRenderer *Renderer;
2076 vtkRenderWindow *RenWin;
2078 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2082 ((OCCViewer_ViewFrame *) smeshGUI->myActiveStudy->
2083 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2085 ic = v3d->getAISContext();
2087 else if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2091 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2092 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2094 RenWin = Renderer->GetRenderWindow();
2097 switch (theCommandID)
2100 smeshGUI->OnEditDelete();
2107 Import_Document(parent, theCommandID); //NBU
2108 //Import_Mesh(parent,theCommandID);
2112 case 122: // EXPORT MED
2116 Export_Mesh(parent, theCommandID);
2120 case 200: // SCALAR BAR
2122 smeshGUI->DisplayScalarBar(false);
2127 SMESHGUI_EditScalarBarDlg *aDlg =
2128 new SMESHGUI_EditScalarBarDlg(parent, "", false);
2134 smeshGUI->DisplayScalarBar(true);
2138 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
2144 smeshGUI->SetViewMode(theCommandID);
2156 SALOME_Selection *Sel =
2157 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2159 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2163 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2164 for (; It.More(); It.Next())
2166 Handle(SALOME_InteractiveObject) IOS = It.Value();
2167 if (IOS->hasEntry())
2169 Standard_Boolean res;
2171 smeshGUI->FindActorByEntry(IOS->getEntry(), res, true);
2173 smeshGUI->EraseActor(ac);
2177 Sel->ClearIObjects();
2178 smeshGUI->myActiveStudy->updateObjBrowser(true);
2181 case 301: // DISPLAY
2183 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2187 QApplication::setOverrideCursor(Qt::waitCursor);
2188 SALOMEDS::SObject_var fatherSF =
2189 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2190 getActiveStudyFrame()->entry());
2192 SALOME_Selection *Sel =
2193 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2195 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2197 for (; It.More(); It.Next())
2199 Handle(SALOME_InteractiveObject) IObject = It.Value();
2200 if (IObject->hasEntry())
2202 Standard_Boolean res;
2204 smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2208 smeshGUI->DisplayActor(ac, true);
2209 smeshGUI->DisplayEdges(ac);
2210 smeshGUI->ChangeRepresentation(ac,
2211 ac->getDisplayMode());
2215 QApplication::restoreOverrideCursor();
2220 case 302: // DISPLAY ONLY
2222 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2225 QApplication::setOverrideCursor(Qt::waitCursor);
2226 vtkActorCollection *theActors = Renderer->GetActors();
2227 theActors->InitTraversal();
2228 vtkActor *ac = theActors->GetNextActor();
2229 while (!(ac == NULL))
2231 if (ac->IsA("SMESH_Actor"))
2233 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
2234 if (!anActor->isHighlighted())
2236 //anActor->VisibilityOff();
2237 //NRI- : 02/12/2002 : Fixed bugId 882
2238 // anActor->EdgeDevice->VisibilityOff();
2239 // anActor->EdgeShrinkDevice->VisibilityOff();
2240 anActor->SetVisibility(false);
2243 ac = theActors->GetNextActor();
2246 // Display selection
2247 SALOMEDS::SObject_var fatherSF =
2248 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2249 getActiveStudyFrame()->entry());
2251 SALOME_Selection *Sel =
2252 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2254 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2256 for (; It.More(); It.Next())
2258 Handle(SALOME_InteractiveObject) IObject = It.Value();
2259 SALOMEDS::SObject_var obj =
2260 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2262 VTKViewer_RenderWindowInteractor *myRenderInter =
2263 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2264 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2266 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
2268 if (myRenderInter->isInViewer(IObject))
2270 if (IObject->hasEntry())
2272 Standard_Boolean res;
2274 smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2278 smeshGUI->DisplayActor(ac, true);
2279 smeshGUI->DisplayEdges(ac);
2280 smeshGUI->ChangeRepresentation(ac,
2281 ac->getDisplayMode());
2286 smeshGUI->myActiveStudy->updateObjBrowser(true);
2287 QApplication::restoreOverrideCursor();
2294 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2297 smeshGUI->EmitSignalDeactivateDialog();
2298 SALOME_Selection *Sel =
2299 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2301 Sel->ClearIObjects();
2302 smeshGUI->myDesktop->SetSelectionMode(1, true);
2303 parent->menuBar()->setItemChecked(9010, false);
2304 parent->menuBar()->setItemChecked(9011, false);
2305 smeshGUI->ViewNodes();
2306 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
2310 QApplication::restoreOverrideCursor();
2311 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2312 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2313 tr("SMESH_BUT_YES"));
2318 case 405: // MOVE NODE
2320 smeshGUI->myDesktop->SetSelectionMode(1, true);
2321 SALOME_Selection *Sel =
2322 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2324 SMESHGUI_MoveNodesDlg *aDlg =
2325 new SMESHGUI_MoveNodesDlg(parent, "", Sel);
2329 case 701: // COMPUTE MESH
2331 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2334 SALOME_Selection *Sel =
2335 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2337 int nbSel = Sel->IObjectCount();
2340 QApplication::restoreOverrideCursor();
2344 SMESH::SMESH_Mesh_var aM;
2345 SMESH::SMESH_subMesh_var aSubM;
2346 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2347 if (IObject->hasEntry())
2349 SALOMEDS::SObject_var aMorSM =
2350 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2351 SALOMEDS::GenericAttribute_var anAttr;
2352 SALOMEDS::AttributeIOR_var anIOR;
2353 if (!aMorSM->_is_nil())
2355 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
2357 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2358 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : IOR = "
2359 << anIOR->Value())CORBA::Object_var cobj;
2362 cobj = _orb->string_to_object(anIOR->Value());
2363 if (CORBA::is_nil(cobj))
2366 ("SMESHGUI::OnGUIEvent - Compute mesh : nil object")}
2368 catch(CORBA::COMM_FAILURE & ex)
2371 ("SMESHGUI::OnGUIEvent - Compute mesh : exception (1)")}
2372 aM = SMESH::SMESH_Mesh::_narrow(cobj);
2373 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
2375 SMESH::SMESH_subMesh::_narrow(_orb->
2376 string_to_object(anIOR->Value()));
2379 GEOM::GEOM_Shape_var refShape =
2380 smeshGUI->myStudyAPI.
2381 GetShapeOnMeshOrSubMesh(aMorSM);
2382 if (!refShape->_is_nil())
2385 smeshGUI->myComponentMesh->
2386 IsReadyToCompute(aM, refShape);
2389 QApplication::restoreOverrideCursor();
2390 QAD_MessageBox::warn1(QAD_Application::
2391 getDesktop(), tr("SMESH_WRN_WARNING"),
2392 tr("SMESH_WRN_MISSING_PARAMETERS"),
2393 tr("SMESH_BUT_YES"));
2398 smeshGUI->myComponentMesh->Compute(aM,
2400 smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2402 // TO Do : change icon of all submeshes
2404 catch(const SALOME::SALOME_Exception & S_ex)
2406 QtCatchCorbaException(S_ex);
2410 else if (!aSubM->_is_nil())
2412 aM = aSubM->GetFather();
2413 GEOM::GEOM_Shape_var refShape =
2414 smeshGUI->myStudyAPI.
2415 GetShapeOnMeshOrSubMesh(aMorSM);
2416 if (!refShape->_is_nil())
2419 smeshGUI->myComponentMesh->
2420 IsReadyToCompute(aM, refShape);
2423 QApplication::restoreOverrideCursor();
2424 QAD_MessageBox::warn1(QAD_Application::
2425 getDesktop(), tr("SMESH_WRN_WARNING"),
2426 tr("SMESH_WRN_MISSING_PARAMETERS"),
2427 tr("SMESH_BUT_YES"));
2432 smeshGUI->myComponentMesh->Compute(aM,
2434 smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2436 // TO Do : change icon of all submeshes
2438 catch(const SALOME::SALOME_Exception & S_ex)
2440 QtCatchCorbaException(S_ex);
2448 // Check whether the actor for the mesh exists at least in one view
2449 Standard_Boolean res;
2451 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2453 smeshGUI->InitActor(aM);
2456 // Check whether the actor belongs to the active view
2457 VTKViewer_RenderWindowInteractor *rwInter =
2458 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2459 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2462 // The actor belongs to inactive view -> create a copy and add it in the active view
2463 if (!rwInter->isInViewer(IObject))
2465 SMESH_Actor *acCopy = SMESH_Actor::New();
2466 acCopy->ShallowCopy(ac);
2468 smeshGUI->DisplayActor(acCopy, false);
2472 if (smeshGUI->myAutomaticUpdate)
2474 SMESH_Actor *Mesh = smeshGUI->ReadScript(aM);
2480 smeshGUI->DisplayActor(Mesh, true);
2481 smeshGUI->DisplayEdges(Mesh, true);
2482 smeshGUI->ChangeRepresentation(Mesh,
2483 Mesh->getDisplayMode());
2489 QApplication::restoreOverrideCursor();
2490 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2491 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2492 tr("SMESH_BUT_YES"));
2494 QApplication::restoreOverrideCursor();
2498 case 702: // ADD SUB MESH
2500 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2503 smeshGUI->EmitSignalDeactivateDialog();
2504 SALOME_Selection *Sel =
2505 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2507 SMESHGUI_AddSubMeshDlg *aDlg =
2508 new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
2512 QApplication::restoreOverrideCursor();
2513 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2514 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2515 tr("SMESH_BUT_YES"));
2520 case 703: // INIT MESH
2522 smeshGUI->EmitSignalDeactivateDialog();
2523 SALOME_Selection *Sel =
2524 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2526 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
2530 case 704: // EDIT Hypothesis
2532 smeshGUI->EmitSignalDeactivateDialog();
2533 SALOME_Selection *Sel =
2534 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2536 SMESHGUI_EditHypothesesDlg *aDlg =
2537 new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2541 case 705: // EDIT Global Hypothesis
2543 smeshGUI->EmitSignalDeactivateDialog();
2544 SALOME_Selection *Sel =
2545 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2547 SMESHGUI_EditHypothesesDlg *aDlg =
2548 new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2552 case 706: // EDIT Local Hypothesis
2554 smeshGUI->EmitSignalDeactivateDialog();
2555 SALOME_Selection *Sel =
2556 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2558 SMESHGUI_EditHypothesesDlg *aDlg =
2559 new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2563 case 806: // ORIENTATION ELEMENTS
2565 smeshGUI->EmitSignalDeactivateDialog();
2566 SALOME_Selection *Sel =
2567 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2569 smeshGUI->myDesktop->SetSelectionMode(3, true);
2570 SMESHGUI_OrientationElementsDlg *aDlg =
2571 new SMESHGUI_OrientationElementsDlg(parent, "", Sel);
2575 case 807: // DIAGONAL INVERSION
2577 smeshGUI->EmitSignalDeactivateDialog();
2578 SALOME_Selection *Sel =
2579 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2581 Sel->ClearIObjects();
2582 smeshGUI->myDesktop->SetSelectionMode(2, true);
2583 SMESHGUI_DiagonalInversionDlg *aDlg =
2584 new SMESHGUI_DiagonalInversionDlg(parent, "", Sel);
2588 case 900: // MESH INFOS
2590 smeshGUI->EmitSignalDeactivateDialog();
2591 SALOME_Selection *Sel =
2592 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2594 SMESHGUI_MeshInfosDlg *aDlg =
2595 new SMESHGUI_MeshInfosDlg(parent, "", Sel);
2599 case 1001: // AUTOMATIC UPDATE PREFERENCES
2601 parent->menuBar()->setItemChecked(1001,
2602 !parent->menuBar()->isItemChecked(1001));
2603 if (parent->menuBar()->isItemChecked(1001))
2605 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
2606 smeshGUI->myAutomaticUpdate = true;
2610 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
2611 smeshGUI->myAutomaticUpdate = false;
2616 case 1003: // MESH PREFERENCES
2618 smeshGUI->SetDisplaySettings();
2624 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2625 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2626 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2627 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2628 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2629 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2630 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2631 int NumberOfLabels =
2632 QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2633 int NumberOfColors =
2634 QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2640 if (NumberOfLabels == 0)
2642 if (NumberOfColors == 0)
2643 NumberOfColors = 64;
2645 SMESHGUI_Preferences_ScalarBarDlg *aDlg =
2646 new SMESHGUI_Preferences_ScalarBarDlg(parent, "", true);
2648 if (Bold.compare("true") == 0)
2649 aDlg->Bold->setChecked(true);
2651 aDlg->Bold->setChecked(false);
2652 if (Italic.compare("true") == 0)
2653 aDlg->Italic->setChecked(true);
2655 aDlg->Italic->setChecked(false);
2656 if (Shadow.compare("true") == 0)
2657 aDlg->Shadow->setChecked(true);
2659 aDlg->Shadow->setChecked(false);
2661 if (Orientation.compare("Horizontal") == 0)
2662 aDlg->RadioHoriz->setChecked(true);
2664 aDlg->RadioVert->setChecked(true);
2666 int NbItems = aDlg->ComboBox1->count();
2668 aDlg->ComboBox1->setCurrentItem(i);
2671 if (FontFamily.compare(aDlg->ComboBox1->text(i)) == 0)
2672 aDlg->ComboBox1->setCurrentItem(i);
2676 aDlg->LineEditWidth->setText(QString("%1").arg(Width));
2677 aDlg->LineEditHeight->setText(QString("%1").arg(Height));
2679 aDlg->SpinBoxLabels->setValue(NumberOfLabels);
2680 aDlg->SpinBoxColors->setValue(NumberOfColors);
2685 if (aDlg->RadioHoriz->isChecked())
2686 Orientation = "Horizontal";
2688 Orientation = "Vertical";
2689 if (aDlg->Bold->isChecked())
2693 if (aDlg->Italic->isChecked())
2697 if (aDlg->Shadow->isChecked())
2702 FontFamily = aDlg->ComboBox1->currentText();
2703 Width = aDlg->LineEditWidth->text().toFloat();
2704 Height = aDlg->LineEditHeight->text().toFloat();
2705 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2706 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2708 vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
2709 if (aScalarBar != NULL)
2711 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2712 FontFamily, Orientation,
2713 Width, Height, NumberOfColors, NumberOfLabels);
2716 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2717 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2718 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2719 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2720 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2721 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2722 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2723 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2724 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2729 case 1100: // EDIT HYPOTHESIS
2731 SALOME_Selection *Sel =
2732 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2734 int nbSel = Sel->IObjectCount();
2738 Standard_Boolean res;
2739 SMESH::SMESH_Hypothesis_var Hyp =
2740 smeshGUI->ConvertIOinSMESHHypothesis(Sel->firstIObject(), res);
2742 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2743 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2744 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2745 SALOMEDS::Study::ListOfSObject_var listSOmesh =
2746 smeshGUI->GetMeshesUsingAlgoOrHypothesis(Hyp);
2750 QString Name = Hyp->GetName();
2752 if (Name.compare("LocalLength") == 0)
2754 SMESH::SMESH_LocalLength_var LL =
2755 SMESH::SMESH_LocalLength::_narrow(Hyp);
2756 double beforeLength = LL->GetLength();
2757 double Length = smeshGUI->Parameter(res,
2759 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2762 if (res && Length != beforeLength)
2764 LL->SetLength(Length);
2765 for (int i = 0; i < listSOmesh->length(); i++)
2767 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2774 else if (Name.compare("NumberOfSegments") == 0)
2776 SMESH::SMESH_NumberOfSegments_var NOS =
2777 SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
2778 int beforeNbSeg = NOS->GetNumberOfSegments();
2779 int NbSeg = smeshGUI->Parameter(res,
2781 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2785 if (res && NbSeg != beforeNbSeg)
2787 NOS->SetNumberOfSegments(NbSeg);
2788 for (int i = 0; i < listSOmesh->length(); i++)
2790 SALOMEDS::SObject_var SO = listSOmesh[i];
2791 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2798 else if (Name.compare("MaxElementArea") == 0)
2800 SMESH::SMESH_MaxElementArea_var MEA =
2801 SMESH::SMESH_MaxElementArea::_narrow(Hyp);
2802 double beforeMaxArea = MEA->GetMaxElementArea();
2803 double MaxArea = smeshGUI->Parameter(res,
2805 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2808 if (res && MaxArea != beforeMaxArea)
2810 MEA->SetMaxElementArea(MaxArea);
2811 for (int i = 0; i < listSOmesh->length(); i++)
2813 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2820 else if (Name.compare("MaxElementVolume") == 0)
2822 SMESH::SMESH_MaxElementVolume_var MEV =
2823 SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
2824 double beforeMaxVolume = MEV->GetMaxElementVolume();
2825 double MaxVolume = smeshGUI->Parameter(res,
2827 tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"),
2830 if (res && MaxVolume != beforeMaxVolume)
2832 MEV->SetMaxElementVolume(MaxVolume);
2833 for (int i = 0; i < listSOmesh->length(); i++)
2835 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2842 else if (Name.compare("Regular_1D") == 0)
2845 else if (Name.compare("MEFISTO_2D") == 0)
2857 case 1101: // RENAME
2859 SALOME_Selection *Sel =
2860 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2862 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2863 for (; It.More(); It.Next())
2865 Handle(SALOME_InteractiveObject) IObject = It.Value();
2867 SALOMEDS::SObject_var obj =
2868 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2869 SALOMEDS::GenericAttribute_var anAttr;
2870 SALOMEDS::AttributeName_var aName;
2871 if (!obj->_is_nil())
2873 if (obj->FindAttribute(anAttr, "AttributeName"))
2875 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2876 QString newName = QString(aName->Value());
2878 SALOMEGUI_NameDlg::getName(QAD_Application::
2879 getDesktop(), newName);
2880 if (!newName.isEmpty())
2882 QApplication::setOverrideCursor(Qt::waitCursor);
2883 smeshGUI->myActiveStudy->renameIObject(IObject,
2886 QApplication::restoreOverrideCursor();
2893 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2895 QApplication::setOverrideCursor(Qt::waitCursor);
2896 SALOME_Selection *Sel =
2897 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2899 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2900 for (int i = 0; It.More(); It.Next(), i++)
2902 Handle(SALOME_InteractiveObject) IObject = It.Value();
2903 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh(IObject);
2905 Sel->ClearIObjects();
2906 smeshGUI->myActiveStudy->updateObjBrowser(true);
2907 QApplication::restoreOverrideCursor();
2911 case 401: // GEOM::EDGE
2913 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2916 smeshGUI->EmitSignalDeactivateDialog();
2917 SALOME_Selection *Sel =
2918 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2920 Sel->ClearIObjects();
2921 smeshGUI->myDesktop->SetSelectionMode(1, true);
2922 parent->menuBar()->setItemChecked(9010, false);
2923 parent->menuBar()->setItemChecked(9011, false);
2924 smeshGUI->ViewNodes();
2925 SMESHGUI_AddEdgeDlg *aDlg =
2926 new SMESHGUI_AddEdgeDlg(parent, "", Sel);
2930 QApplication::restoreOverrideCursor();
2931 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2932 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2933 tr("SMESH_BUT_YES"));
2937 case 4021: // TRIANGLE
2939 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2942 smeshGUI->EmitSignalDeactivateDialog();
2943 SALOME_Selection *Sel =
2944 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2946 Sel->ClearIObjects();
2947 smeshGUI->myDesktop->SetSelectionMode(1, true);
2948 parent->menuBar()->setItemChecked(9010, false);
2949 parent->menuBar()->setItemChecked(9011, false);
2950 smeshGUI->ViewNodes();
2951 SMESHGUI_AddFaceDlg *aDlg =
2952 new SMESHGUI_AddFaceDlg(parent, "", Sel, 3);
2956 QApplication::restoreOverrideCursor();
2957 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2958 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2959 tr("SMESH_BUT_YES"));
2965 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2968 smeshGUI->EmitSignalDeactivateDialog();
2969 SALOME_Selection *Sel =
2970 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2972 Sel->ClearIObjects();
2973 smeshGUI->myDesktop->SetSelectionMode(1, true);
2974 parent->menuBar()->setItemChecked(9010, false);
2975 parent->menuBar()->setItemChecked(9011, false);
2976 smeshGUI->ViewNodes();
2977 SMESHGUI_AddFaceDlg *aDlg =
2978 new SMESHGUI_AddFaceDlg(parent, "", Sel, 4);
2982 QApplication::restoreOverrideCursor();
2983 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2984 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2985 tr("SMESH_BUT_YES"));
2991 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2994 smeshGUI->EmitSignalDeactivateDialog();
2995 SALOME_Selection *Sel =
2996 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2998 Sel->ClearIObjects();
2999 smeshGUI->myDesktop->SetSelectionMode(1, true);
3000 parent->menuBar()->setItemChecked(9010, false);
3001 parent->menuBar()->setItemChecked(9011, false);
3002 smeshGUI->ViewNodes();
3003 SMESHGUI_AddVolumeDlg *aDlg =
3004 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 4);
3008 QApplication::restoreOverrideCursor();
3009 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3010 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3011 tr("SMESH_BUT_YES"));
3017 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3020 smeshGUI->EmitSignalDeactivateDialog();
3021 SALOME_Selection *Sel =
3022 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3024 Sel->ClearIObjects();
3025 smeshGUI->myDesktop->SetSelectionMode(1, true);
3026 parent->menuBar()->setItemChecked(9010, false);
3027 parent->menuBar()->setItemChecked(9011, false);
3028 smeshGUI->ViewNodes();
3029 SMESHGUI_AddVolumeDlg *aDlg =
3030 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 8);
3034 QApplication::restoreOverrideCursor();
3035 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3036 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3037 tr("SMESH_BUT_YES"));
3042 case 4041: // REMOVES NODES
3044 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3047 smeshGUI->EmitSignalDeactivateDialog();
3048 SALOME_Selection *Sel =
3049 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3051 Sel->ClearIObjects();
3052 smeshGUI->myDesktop->SetSelectionMode(1, true);
3053 parent->menuBar()->setItemChecked(9010, false);
3054 parent->menuBar()->setItemChecked(9011, false);
3055 smeshGUI->ViewNodes();
3056 SMESHGUI_RemoveNodesDlg *aDlg =
3057 new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
3061 QApplication::restoreOverrideCursor();
3062 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3063 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3064 tr("SMESH_BUT_YES"));
3068 case 4042: // REMOVES ELEMENTS
3070 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3073 smeshGUI->EmitSignalDeactivateDialog();
3074 SALOME_Selection *Sel =
3075 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3077 Sel->ClearIObjects();
3078 smeshGUI->myDesktop->SetSelectionMode(3, true);
3079 SMESHGUI_RemoveElementsDlg *aDlg =
3080 new SMESHGUI_RemoveElementsDlg(parent, "", Sel);
3084 QApplication::restoreOverrideCursor();
3085 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3086 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3087 tr("SMESH_BUT_YES"));
3092 case 5000: // HYPOTHESIS - ALGO
3094 smeshGUI->CreateAlgorithm("Regular_1D", "Wire Discretisation");
3099 smeshGUI->CreateAlgorithm("MEFISTO_2D", "Triangle (Mefisto)");
3104 smeshGUI->CreateAlgorithm("Quadrangle_2D", "Quadrangle (Mapping)");
3109 smeshGUI->CreateAlgorithm("Hexa_3D", "Hexahedron (i,j,k)");
3114 smeshGUI->CreateAlgorithm("NETGEN_3D", "Tetrahedron (Netgen)");
3118 case 5030: // HYPOTHESIS - LOCAL LENGTH
3120 smeshGUI->EmitSignalDeactivateDialog();
3121 SALOME_Selection *Sel =
3122 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3124 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg(parent, "");
3127 case 5031: // HYPOTHESIS - NB SEGMENTS
3129 smeshGUI->EmitSignalDeactivateDialog();
3130 SALOME_Selection *Sel =
3131 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3133 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg(parent, "");
3137 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
3139 smeshGUI->EmitSignalDeactivateDialog();
3140 SALOME_Selection *Sel =
3141 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3143 SMESHGUI_MaxElementAreaDlg *aDlg =
3144 new SMESHGUI_MaxElementAreaDlg(parent, "");
3148 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
3150 smeshGUI->EmitSignalDeactivateDialog();
3151 SALOME_Selection *Sel =
3152 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3154 SMESHGUI_MaxElementVolumeDlg *aDlg =
3155 new SMESHGUI_MaxElementVolumeDlg(parent, "");
3159 case 6016: // CONTROLS
3167 SALOME_Selection *Sel =
3168 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3170 int nbSel = Sel->IObjectCount();
3173 smeshGUI->Control(theCommandID);
3179 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3182 SALOME_Selection *Sel =
3183 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3185 SMESHGUI_EdgesConnectivityDlg *Dlg =
3186 new SMESHGUI_EdgesConnectivityDlg(parent, "", Sel);
3190 QApplication::restoreOverrideCursor();
3191 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3192 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3193 tr("SMESH_BUT_YES"));
3200 if (!parent->menuBar()->isItemChecked(9010))
3202 QApplication::setOverrideCursor(Qt::waitCursor);
3203 parent->menuBar()->setItemChecked(9011, false);
3205 smeshGUI->EraseSimulationActors();
3206 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3208 SALOME_Selection *Sel =
3209 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3211 int nbSel = Sel->IObjectCount();
3214 Standard_Boolean res;
3215 SMESH_Actor *MeshActor =
3216 smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3220 parent->menuBar()->setItemChecked(9010,
3221 !parent->menuBar()->isItemChecked(9010));
3223 // It's necessary to display SMDS IDs instead of VTK ones, so
3224 // vtkIdFilter is unacceptable here. We have to do it manually :(
3225 vtkUnstructuredGrid *ptGrid = vtkUnstructuredGrid::New();
3226 ptGrid->CopyStructure(MeshActor->DataSource);
3228 int numPts = MeshActor->DataSource->GetNumberOfPoints();
3230 // Loop over points and generate ids
3231 vtkIntArray *ptIds = vtkIntArray::New();
3232 ptIds->SetNumberOfValues(numPts);
3234 for (int id = 0; id < numPts; id++)
3236 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
3237 ptIds->SetValue(id, idSMDS);
3240 // mpv porting vtk4.2.2
3241 // vtkScalars* newScalars = vtkScalars::New();
3242 // newScalars->SetData(ptIds);
3243 // ptGrid->GetPointData()->SetScalars(newScalars);
3244 ptGrid->GetPointData()->SetScalars(ptIds);
3245 // newScalars->Delete();
3249 vtkMaskPoints *mask = vtkMaskPoints::New();
3250 mask->SetInput(ptGrid);
3251 mask->SetOnRatio(1);
3252 // mask->SetMaximumNumberOfPoints( 50 );
3253 // mask->RandomModeOn();
3255 vtkSelectVisiblePoints *visPts =
3256 vtkSelectVisiblePoints::New();
3257 visPts->SetInput(mask->GetOutput());
3258 visPts->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3259 myActiveStudy->getActiveStudyFrame()->
3260 getRightFrame()->getViewFrame())->getRenderer());
3261 //visPts->SetSelectInvisible(1);
3262 visPts->SelectInvisibleOff();
3263 visPts->SetTolerance(0.1);
3265 vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3266 ldm->SetInput(visPts->GetOutput());
3267 ldm->SetLabelFormat("%g");
3268 ldm->SetLabelModeToLabelScalars();
3269 //ldm->SetLabelModeToLabelFieldData();
3271 ldm->SetFontFamilyToTimes();
3272 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3277 vtkActor2D *pointLabels = vtkActor2D::New();
3278 pointLabels->SetMapper(ldm);
3279 pointLabels->GetProperty()->SetColor(0, 1, 0);
3283 smeshGUI->mySimulationActors2D->AddItem(pointLabels);
3284 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3285 getActiveStudyFrame()->getRightFrame()->
3286 getViewFrame())->getRenderer()->AddActor2D(pointLabels);
3292 QApplication::setOverrideCursor(Qt::waitCursor);
3293 parent->menuBar()->setItemChecked(9010,
3294 !parent->menuBar()->isItemChecked(9010));
3295 smeshGUI->EraseSimulationActors();
3296 smeshGUI->ScalarVisibilityOff();
3298 QApplication::restoreOverrideCursor();
3303 if (!parent->menuBar()->isItemChecked(9011))
3305 QApplication::setOverrideCursor(Qt::waitCursor);
3306 parent->menuBar()->setItemChecked(9010, false);
3308 smeshGUI->EraseSimulationActors();
3309 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3311 SALOME_Selection *Sel =
3312 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3314 int nbSel = Sel->IObjectCount();
3317 Standard_Boolean res;
3318 SMESH_Actor *MeshActor =
3319 smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3323 parent->menuBar()->setItemChecked(9011,
3324 !parent->menuBar()->isItemChecked(9011));
3326 // It's necessary to display SMDS IDs instead of VTK ones, so
3327 // vtkIdFilter is unacceptable here. We have to do it manually :(
3328 vtkUnstructuredGrid *elGrid = vtkUnstructuredGrid::New();
3329 elGrid->CopyStructure(MeshActor->DataSource);
3331 int numCells = MeshActor->DataSource->GetNumberOfCells();
3333 // Loop over points and generate ids
3334 vtkIntArray *cellIds = vtkIntArray::New();
3335 cellIds->SetNumberOfValues(numCells);
3337 for (int id = 0; id < numCells; id++)
3339 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
3340 cellIds->SetValue(id, idSMDS);
3343 // mpv porting vk4.2.2
3344 // vtkScalars* newScalars = vtkScalars::New();
3345 // newScalars->SetData(cellIds);
3346 elGrid->GetCellData()->SetScalars(cellIds);
3347 // elGrid->GetCellData()->SetScalars(newScalars);
3348 // newScalars->Delete();
3353 vtkCellCenters *cc = vtkCellCenters::New();
3354 cc->SetInput(elGrid);
3356 vtkSelectVisiblePoints *visCells =
3357 vtkSelectVisiblePoints::New();
3358 visCells->SetInput(cc->GetOutput());
3359 visCells->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3360 myActiveStudy->getActiveStudyFrame()->
3361 getRightFrame()->getViewFrame())->getRenderer());
3362 visCells->SelectInvisibleOff();
3363 visCells->SetTolerance(0.1);
3364 // visCells->SetSelectInvisible(1);
3366 vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3367 ldm->SetInput(visCells->GetOutput());
3368 ldm->SetLabelFormat("%g");
3369 ldm->SetLabelModeToLabelScalars();
3371 ldm->SetFontFamilyToTimes();
3372 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3377 vtkActor2D *cellLabels = vtkActor2D::New();
3378 cellLabels->SetMapper(ldm);
3379 cellLabels->GetProperty()->SetColor(1, 0, 0);
3384 smeshGUI->mySimulationActors2D->AddItem(cellLabels);
3385 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3386 getActiveStudyFrame()->getRightFrame()->
3387 getViewFrame())->getRenderer()->AddActor2D(cellLabels);
3393 QApplication::setOverrideCursor(Qt::waitCursor);
3394 parent->menuBar()->setItemChecked(9011,
3395 !parent->menuBar()->isItemChecked(9011));
3396 smeshGUI->EraseSimulationActors();
3397 smeshGUI->ScalarVisibilityOff();
3399 QApplication::restoreOverrideCursor();
3403 case 10001: // DISPLAY MODE PREFERENCE
3405 parent->menuBar()->setItemChecked(10001,
3406 !parent->menuBar()->isItemChecked(10001));
3407 parent->menuBar()->setItemChecked(10002, false);
3408 parent->menuBar()->setItemChecked(10003, false);
3409 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
3414 parent->menuBar()->setItemChecked(10002,
3415 !parent->menuBar()->isItemChecked(10002));
3416 parent->menuBar()->setItemChecked(10001, false);
3417 parent->menuBar()->setItemChecked(10003, false);
3418 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3423 parent->menuBar()->setItemChecked(10003,
3424 !parent->menuBar()->isItemChecked(10003));
3425 parent->menuBar()->setItemChecked(10002, false);
3426 parent->menuBar()->setItemChecked(10001, false);
3427 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
3433 smeshGUI->myActiveStudy->updateObjBrowser(true);
3437 //=============================================================================
3438 /*! function : GetMeshesUsingAlgoOrHypothesis()
3439 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
3440 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
3442 //=============================================================================
3443 SALOMEDS::Study::ListOfSObject *
3444 SMESHGUI::GetMeshesUsingAlgoOrHypothesis(SMESH::
3445 SMESH_Hypothesis_ptr AlgoOrHyp)
3447 SALOMEDS::Study::ListOfSObject_var listSOmesh =
3448 new SALOMEDS::Study::ListOfSObject;
3449 listSOmesh->length(0);
3450 unsigned int index = 0;
3451 if (!AlgoOrHyp->_is_nil())
3453 SALOMEDS::SObject_var SO_Hypothesis =
3454 smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms(AlgoOrHyp);
3455 if (!SO_Hypothesis->_is_nil())
3457 SALOMEDS::Study::ListOfSObject_var listSO =
3458 smeshGUI->myStudy->FindDependances(SO_Hypothesis);
3459 for (unsigned int i = 0; i < listSO->length(); i++)
3461 SALOMEDS::SObject_var SO = listSO[i];
3464 SALOMEDS::SObject_var SOfatherFather =
3465 SO->GetFather()->GetFather();
3466 if (!SOfatherFather->_is_nil())
3469 listSOmesh->length(index);
3470 listSOmesh[index - 1] = SOfatherFather;
3476 return listSOmesh._retn();
3479 //=============================================================================
3483 //=============================================================================
3484 void SMESHGUI::Import_Mesh(QAD_Desktop * parent, int theCommandID)
3488 Mesh_Reader *myReader;
3490 if (theCommandID == 113)
3492 filter = tr("MED files (*.med)");
3493 myExtension = string("MED");
3494 myReader = new DriverMED_R_SMESHDS_Mesh;
3496 else if (theCommandID == 112)
3498 filter = tr("IDEAS files (*.unv)");
3499 myExtension = string("UNV");
3501 else if (theCommandID == 111)
3503 filter = tr("DAT files (*.dat)");
3504 myExtension = string("MED");
3505 myReader = new DriverDAT_R_SMESHDS_Mesh;
3508 QString filename = QAD_FileDlg::getFileName(parent,
3513 if (!filename.isEmpty())
3515 QApplication::setOverrideCursor(Qt::waitCursor);
3516 string myClass = string("SMESHDS_Mesh");
3517 // Mesh_Reader* myReader = SMESHDriver::GetMeshReader(myExtension, myClass);
3519 int myMeshId = (smeshGUI->myDocument)->NewMesh();
3520 SMDS_Mesh *myMesh = (smeshGUI->myDocument)->GetMesh(myMeshId);
3522 myReader->SetFile(string(filename.latin1()));
3523 myReader->SetMesh(myMesh);
3524 myReader->SetMeshId(myMeshId);
3527 QApplication::restoreOverrideCursor();
3531 //=============================================================================
3535 //=============================================================================
3536 void SMESHGUI::Export_Mesh(QAD_Desktop * parent, int theCommandID)
3538 SALOME_Selection *Sel =
3539 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3540 int nbSel = Sel->IObjectCount();
3543 Standard_Boolean res;
3544 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3545 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(IObject, res);
3548 if (theCommandID == 122)
3550 QString filename = QAD_FileDlg::getFileName(parent,
3552 tr("MED files (*.med)"),
3555 if (!filename.isEmpty())
3557 QApplication::setOverrideCursor(Qt::waitCursor);
3558 aMesh->ExportMED(filename.latin1());
3559 QApplication::restoreOverrideCursor();
3562 else if (theCommandID == 121)
3564 QString filename = QAD_FileDlg::getFileName(parent,
3566 tr("DAT files (*.dat)"),
3569 if (!filename.isEmpty())
3571 QApplication::setOverrideCursor(Qt::waitCursor);
3572 aMesh->ExportDAT(filename.latin1());
3573 QApplication::restoreOverrideCursor();
3576 else if (theCommandID == 123)
3578 QString filename = QAD_FileDlg::getFileName(parent,
3580 tr("IDEAS files (*.unv)"),
3583 if (!filename.isEmpty())
3585 QApplication::setOverrideCursor(Qt::waitCursor);
3586 aMesh->ExportUNV(filename.latin1());
3587 QApplication::restoreOverrideCursor();
3590 aMesh->ExportDAT(filename.latin1());
3592 QApplication::restoreOverrideCursor();
3594 if (IObject->hasEntry())
3597 SALOMEDS::SObject_var SO =
3598 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
3599 SALOMEDS::GenericAttribute_var anAttr;
3600 SALOMEDS::AttributeComment_var aFileName;
3601 SALOMEDS::StudyBuilder_var aStudyBuilder =
3602 smeshGUI->myStudy->NewBuilder();
3604 aStudyBuilder->FindOrCreateAttribute(SO,
3605 "AttributeComment");
3606 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
3607 aFileName->SetValue(filename.latin1());
3614 //=============================================================================
3618 //=============================================================================
3619 void SMESHGUI::Import_Document(QAD_Desktop * parent, int theCommandID)
3623 Document_Reader *myReader;
3625 if (theCommandID == 113)
3627 filter = tr("MED files (*.med)");
3628 myExtension = string("MED");
3629 myReader = new DriverMED_R_SMESHDS_Document;
3631 else if (theCommandID == 112)
3633 filter = tr("IDEAS files (*.unv)");
3634 myExtension = string("UNV");
3635 myReader = new DriverUNV_R_SMESHDS_Document;
3637 else if (theCommandID == 111)
3639 filter = tr("DAT files (*.dat)");
3640 myExtension = string("DAT");
3641 myReader = new DriverDAT_R_SMESHDS_Document;
3644 QString filename = QAD_FileDlg::getFileName(parent,
3647 tr("Import document"),
3649 if (!filename.isEmpty())
3651 QApplication::setOverrideCursor(Qt::waitCursor);
3652 string myClass = string("SMESHDS_Document");
3653 // Document_Reader* myReader = SMESHDriver::GetDocumentReader(myExtension, myClass);
3654 SMESHDS_Document *newDocument = new SMESHDS_Document(1);
3656 myReader->SetFile(string(filename.latin1()));
3657 myReader->SetDocument(smeshGUI->myDocument);
3659 QApplication::restoreOverrideCursor();
3663 void SMESHGUI::Export_Document(QAD_Desktop * parent, int theCommandID)
3666 Document_Writer *myWriter;
3669 if (theCommandID == 122)
3671 filter = tr("MED files (*.med)");
3672 myExtension = string("MED");
3673 myWriter = new DriverMED_W_SMESHDS_Document;
3675 else if (theCommandID == 121)
3677 filter = tr("DAT files (*.dat)");
3678 myExtension = string("DAT");
3679 myWriter = new DriverDAT_W_SMESHDS_Document;
3681 else if (theCommandID == 123)
3683 filter = tr("IDEAS files (*.unv)");
3684 myExtension = string("UNV");
3685 myWriter = new DriverUNV_W_SMESHDS_Document;
3688 QString filename = QAD_FileDlg::getFileName(parent,
3691 tr("Export document"),
3693 if (!filename.isEmpty())
3695 QApplication::setOverrideCursor(Qt::waitCursor);
3696 string myClass = string("SMESHDS_Document");
3697 //Document_Writer* myWriter = SMESHDriver::GetDocumentWriter(myExtension, myClass);
3699 myWriter->SetFile(string(filename.latin1()));
3700 myWriter->SetDocument(smeshGUI->myDocument);
3702 //StudyContextStruct* myStudyContext = _impl.GetStudyContext(myStudyId);
3703 //Handle(SMESHDS_Document) myDocument = myStudyContext->myDocument;
3704 //myWriter->SetDocument(myDocument);
3707 QApplication::restoreOverrideCursor();
3711 //=============================================================================
3715 //=============================================================================
3716 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3717 QAD_StudyFrame * studyFrame)
3719 SMESHGUI::GetOrCreateSMESHGUI(parent);
3723 //=============================================================================
3727 //=============================================================================
3728 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3729 QAD_StudyFrame * studyFrame)
3731 SMESHGUI::GetOrCreateSMESHGUI(parent);
3736 //=============================================================================
3740 //=============================================================================
3741 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3742 QAD_StudyFrame * studyFrame)
3744 SMESHGUI::GetOrCreateSMESHGUI(parent);
3749 //=============================================================================
3753 //=============================================================================
3754 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3756 SMESHGUI::GetOrCreateSMESHGUI(parent);
3759 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3760 if (DisplayMode.compare("") == 0)
3762 DisplayMode = "Shading";
3763 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3766 if (DisplayMode.compare("Wireframe") == 0)
3768 parent->menuBar()->setItemChecked(10003, false);
3769 parent->menuBar()->setItemChecked(10002, false);
3770 parent->menuBar()->setItemChecked(10001, true);
3772 else if (DisplayMode.compare("Shading") == 0)
3774 parent->menuBar()->setItemChecked(10003, false);
3775 parent->menuBar()->setItemChecked(10002, true);
3776 parent->menuBar()->setItemChecked(10001, false);
3778 else if (DisplayMode.compare("Shrink") == 0)
3780 parent->menuBar()->setItemChecked(10003, true);
3781 parent->menuBar()->setItemChecked(10002, false);
3782 parent->menuBar()->setItemChecked(10001, false);
3785 /* Automatic Update */
3786 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3787 if (AutoUpdate.compare("true") == 0)
3789 parent->menuBar()->setItemChecked(1001, true);
3790 smeshGUI->myAutomaticUpdate = true;
3794 parent->menuBar()->setItemChecked(1001, false);
3795 smeshGUI->myAutomaticUpdate = false;
3799 parent->menuBar()->setItemEnabled(11, false); // IMPORT
3804 //=============================================================================
3808 //=============================================================================
3809 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent,
3810 QString & theObject)
3812 /* Create or retrieve an object SMESHGUI */
3813 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3815 // NRI : Temporary added
3816 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3817 // theObject = "NothingSelected";
3818 // theContext = "NothingSelected";
3822 SALOME_Selection *Sel =
3823 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3824 int nbSel = Sel->IObjectCount();
3827 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3830 vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
3831 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1))
3833 theObject = "ScalarBar";
3838 theObject = "NothingSelected";
3839 theContext = "NothingSelected";
3844 theObject = "NothingSelected";
3845 theContext = "NothingSelected";
3848 else if (nbSel == 1)
3850 theObject = smeshGUI->CheckTypeObject(Sel->firstIObject());
3855 theObject = smeshGUI->CheckHomogeneousSelection();
3860 //=============================================================================
3864 //=============================================================================
3865 bool SMESHGUI::CustomPopup(QAD_Desktop * parent,
3867 const QString & theContext,
3868 const QString & theParent, const QString & theObject)
3870 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3871 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3873 /* Create or retrieve an object SMESHGUI */
3874 SMESHGUI::GetOrCreateSMESHGUI(parent);
3876 // NRI : Temporary added
3877 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3882 SALOME_Selection *Sel =
3883 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3884 QAD_StudyFrame *studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3885 int nbSel = Sel->IObjectCount();
3889 if (studyFrame->getTypeView() != VIEW_VTK)
3893 else if (nbSel == 1)
3895 QString parentComp =
3896 ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3897 // First check type of active viewer (VTK required)
3898 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3899 parent->getActiveComponent())
3901 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3904 int id = popup->idAt(0);
3905 if (id <= QAD_TopLabel_Popup_ID)
3906 popup->removeItemAt(0);
3910 if (theObject.compare("Component") == 0)
3912 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3917 // Remove common popup items for Submesh, Hypothesis and Algorithm
3918 if (theObject.compare("SubMesh") == 0 ||
3919 theObject.compare("Hypothesis") == 0 ||
3920 theObject.compare("Algorithm") == 0)
3922 popup->removeItem(QAD_Display_Popup_ID);
3923 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3924 popup->removeItem(QAD_Erase_Popup_ID);
3925 int id = popup->idAt(popup->count() - 1); // last item
3926 if (id < 0 && id != -1)
3927 popup->removeItem(id); // separator
3930 if (theObject.compare("Component") == 0)
3932 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3936 int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3937 QFont f = QApplication::font();
3940 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3942 if (theParent.compare("Viewer") == 0)
3944 if (popup->idAt(0) == id)
3946 popup->removeItem(id);
3947 popup->insertItem(new CustomItem(QString(IObject->getName()),
3951 Standard_Boolean res;
3953 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3954 if (res && studyFrame->getTypeView() == VIEW_VTK)
3956 VTKViewer_RenderWindowInteractor *myRenderInter =
3957 ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3958 getViewFrame())->getRWInteractor();
3959 if (myRenderInter->isVisible(IObject))
3961 popup->removeItem(QAD_Display_Popup_ID);
3965 popup->removeItem(QAD_Erase_Popup_ID);
3970 popup->removeItem(QAD_Erase_Popup_ID);
3972 { // mesh not computed -> can't display it
3973 popup->removeItem(QAD_Display_Popup_ID);
3974 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3975 popup->removeItemAt(popup->count() - 1); //separator
3979 else if (theParent.compare("ObjectBrowser") == 0)
3981 if (theObject.compare("Mesh") == 0 ||
3982 theObject.compare("SubMesh") == 0 ||
3983 theObject.compare("Hypothesis") == 0 ||
3984 theObject.compare("Algorithm") == 0)
3986 popup->removeItemAt(0);
3990 if (popup->idAt(0) == id)
3992 popup->removeItem(id);
3993 popup->removeItemAt(0); //separator
3997 Standard_Boolean res;
3999 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
4000 if (res && studyFrame->getTypeView() == VIEW_VTK)
4002 VTKViewer_RenderWindowInteractor *myRenderInter =
4003 ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
4004 getViewFrame())->getRWInteractor();
4005 if (myRenderInter->isVisible(IObject))
4007 popup->removeItem(QAD_Display_Popup_ID);
4011 popup->removeItem(QAD_Erase_Popup_ID);
4016 if (theObject.compare("Mesh") == 0 ||
4017 theObject.compare("SubMesh") == 0 ||
4018 theObject.compare("Hypothesis") == 0 ||
4019 theObject.compare("Algorithm") == 0)
4024 popup->removeItem(QAD_Erase_Popup_ID);
4026 { // mesh not computed -> can't display it
4027 popup->removeItem(QAD_Display_Popup_ID);
4028 popup->removeItem(QAD_DisplayOnly_Popup_ID);
4029 popup->removeItemAt(popup->count() - 1); //separator
4037 QString parentComp =
4038 ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
4039 QAD_StudyFrame *studyFrame =
4040 smeshGUI->myActiveStudy->getActiveStudyFrame();
4041 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
4042 parent->getActiveComponent())
4044 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
4047 int id = popup->idAt(0);
4048 if (id <= QAD_TopLabel_Popup_ID && id != -1)
4049 popup->removeItemAt(0);
4053 if (parentComp.isNull())
4054 { // objects from several components are selected
4055 popup->removeItem(QAD_DisplayOnly_Popup_ID);
4056 popup->removeItem(QAD_Display_Popup_ID);
4057 popup->removeItem(QAD_Erase_Popup_ID);
4058 int id = popup->idAt(popup->count() - 1); // last item
4059 if (id < 0 && id != -1)
4060 popup->removeItem(id); // separator
4065 QString type = smeshGUI->CheckHomogeneousSelection();
4066 if (type.compare("Heterogeneous Selection") != 0)
4068 int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
4069 QFont f = QApplication::font();
4071 popup->removeItem(id);
4072 popup->insertItem(new CustomItem(QString("%1 ").arg(nbSel) + type +
4073 " (s) ", f), id, 0);
4079 //=============================================================================
4080 /*! Method: BuildPresentation(const Handle(SALOME_InteractiveObject)& theIO)
4081 * Purpose: ensures that the actor for the given <theIO> exists in the active VTK view
4083 //=============================================================================
4084 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
4086 /* Create or retrieve an object SMESHGUI */
4087 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
4089 QAD_StudyFrame *activeFrame =
4090 smeshGUI->myActiveStudy->getActiveStudyFrame();
4091 if (activeFrame->getTypeView() == VIEW_VTK)
4094 SALOMEDS::SObject_var fatherSF =
4095 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
4097 SALOME_Selection *Sel =
4098 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
4100 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4102 // for(;It.More();It.Next()) {
4103 // Handle(SALOME_InteractiveObject) IObject = It.Value();
4104 Handle(SALOME_InteractiveObject) IObject = theIO;
4105 if (IObject->hasEntry())
4107 // Look for the actor in all views
4108 Standard_Boolean res;
4110 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
4112 // Actor not found at all -> mesh is not computed -> do nothing!!!
4115 /*SMESH::SMESH_Mesh_var aM;
4116 * SALOMEDS::SObject_var aMorSM = smeshGUI->myStudy->FindObjectID( IObject->getEntry() );
4117 * SALOMEDS::SObject_var father = aMorSM->GetFather();
4118 * SALOMEDS::SObject_var fatherComp = aMorSM->GetFatherComponent();
4120 * // Non-displayable objects (Hypo, Algo) have tags < 3 or have a father different from component
4121 * if (aMorSM->Tag() < 3 || strcmp(father->GetID(), fatherComp->GetID()) != 0)
4124 * SALOMEDS::GenericAttribute_var anAttr;
4125 * SALOMEDS::AttributeIOR_var anIOR;
4126 * if ( !aMorSM->_is_nil() ) {
4127 * if (aMorSM->FindAttribute(anAttr, "AttributeIOR") ) {
4128 * anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4129 * aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
4133 * if (!aM->_is_nil()) {
4134 * smeshGUI->InitActor(aM);
4135 * ac = smeshGUI->ReadScript(aM);
4139 * smeshGUI->DisplayActor( ac, true );
4140 * smeshGUI->DisplayEdges( ac );
4141 * smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
4146 { // The actor exists in some view
4147 // Check whether the actor belongs to the active view
4148 VTKViewer_RenderWindowInteractor *rwInter =
4149 ((VTKViewer_ViewFrame *) activeFrame->getRightFrame()->
4150 getViewFrame())->getRWInteractor();
4152 // The actor belongs to inactive view -> create a copy and display it in the active view
4153 if (!rwInter->isInViewer(IObject))
4155 if(ac->GetMapper()==NULL)
4157 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(theIO, res);
4158 ac=smeshGUI->ReadScript(aMesh);
4160 SMESH_Actor *acCopy = SMESH_Actor::New();
4161 acCopy->ShallowCopy(ac);
4164 smeshGUI->DisplayActor(ac, false);
4165 smeshGUI->DisplayEdges(ac);
4166 smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
4174 ("BuildPresentation() must not be called while non-VTK view is active")}
4177 //=============================================================================
4181 //=============================================================================
4182 void SMESHGUI::setOrb()
4186 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
4187 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
4191 INFOS("internal error : orb not found");
4194 ASSERT(!CORBA::is_nil(_orb));
4197 //=============================================================================
4201 //=============================================================================
4202 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
4204 SMESH_Actor *MeshActor;
4205 if (!aMesh->_is_nil())
4207 Standard_Boolean result;
4208 MeshActor = FindActor(aMesh, result, false);
4211 SMESH::log_array_var aSeq = aMesh->GetLog(true);
4213 if (aSeq->length() == 0)
4215 MESSAGE("ReadScript(): log is empty") return MeshActor;
4218 for (unsigned int ind = 0; ind < aSeq->length(); ind++)
4220 switch (aSeq[ind].commandType)
4222 case SMESH::ADD_NODE:
4224 AddNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4228 case SMESH::ADD_EDGE:
4230 // AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
4233 case SMESH::ADD_TRIANGLE:
4235 AddTriangles(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4239 case SMESH::ADD_QUADRANGLE:
4241 AddQuadrangles(MeshActor, aSeq[ind].number,
4242 aSeq[ind].coords, aSeq[ind].indexes);
4245 case SMESH::ADD_TETRAHEDRON:
4247 AddTetras(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4251 case SMESH::ADD_PYRAMID:
4255 case SMESH::ADD_PRISM:
4259 case SMESH::ADD_HEXAHEDRON:
4261 AddHexaedres(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4265 case SMESH::REMOVE_NODE:
4267 RemoveNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4271 case SMESH::REMOVE_ELEMENT:
4273 RemoveElements(MeshActor, aSeq[ind].number,
4274 aSeq[ind].coords, aSeq[ind].indexes);
4285 //=============================================================================
4289 //=============================================================================
4290 void SMESHGUI::Dump(SMESH_Actor * Mactor)
4292 vtkUnstructuredGrid *ugrid =
4293 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
4294 vtkPoints *Pts = ugrid->GetPoints();
4295 int nbPts = Pts->GetNumberOfPoints();
4296 int nbCells = ugrid->GetNumberOfCells();
4300 In = fopen("/tmp/dumpMesh", "w+");
4301 fprintf(In, "%d %d\n", nbPts, nbCells);
4302 for (int i = 0; i < nbPts; i++)
4304 float *p = ugrid->GetPoint(i);
4305 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
4308 for (int i = 0; i < nbCells; i++)
4310 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
4311 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
4312 for (j = 0; j < Id->GetNumberOfIds(); j++)
4314 fprintf(In, " %d", Id->GetId(j));
4321 //=============================================================================
4325 //=============================================================================
4326 void SMESHGUI::AddNodes(SMESH_Actor * Mactor, int number,
4327 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4329 QApplication::setOverrideCursor(Qt::waitCursor);
4330 if (Mactor->GetMapper() == NULL)
4332 vtkPoints *Pts = vtkPoints::New();
4333 SMESH_Grid *ugrid = SMESH_Grid::New();
4341 Pts->InsertNextPoint(coords[j - 1], coords[j], coords[j + 1]);
4342 //Mactor->AddNode( indexes[i-1], idVTK );
4343 ugrid->AddNode(indexes[i - 1], idVTK);
4347 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4348 ugrid->SetPoints(Pts);
4349 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4350 PtsMapper->SetInput(ugrid);
4351 Mactor->DataSource = PtsMapper->GetInput();
4352 Mactor->SetMapper(PtsMapper);
4356 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4357 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4363 ugrid->GetPoints()->InsertNextPoint(coords[j - 1], coords[j],
4365 ugrid->AddNode(indexes[i - 1], idVTK);
4369 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4370 PtsMapper->SetInput(ugrid);
4371 Mactor->DataSource = PtsMapper->GetInput();
4372 Mactor->SetMapper(PtsMapper);
4374 QApplication::restoreOverrideCursor();
4377 //=============================================================================
4381 //=============================================================================
4382 void SMESHGUI::AddNode(SMESH_Actor * Mactor, int idnode, float x, float y,
4385 QApplication::setOverrideCursor(Qt::waitCursor);
4386 MESSAGE("SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" <<
4387 z) if (Mactor->GetMapper() == NULL)
4389 vtkPoints *Pts = vtkPoints::New();
4390 int idVTK = Pts->InsertNextPoint(x, y, z);
4391 //Mactor->AddNode( idnode, idVTK );
4392 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4393 SMESH_Grid *ugrid = SMESH_Grid::New();
4395 ugrid->AddNode(idnode, idVTK);
4396 ugrid->SetPoints(Pts);
4397 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4398 PtsMapper->SetInput(ugrid);
4399 Mactor->DataSource = PtsMapper->GetInput();
4400 Mactor->SetMapper(PtsMapper);
4404 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4405 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4406 int idVTK = ugrid->GetPoints()->InsertNextPoint(x, y, z);
4407 //Mactor->AddNode( idnode, idVTK );
4408 ugrid->AddNode(idnode, idVTK);
4409 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4410 PtsMapper->SetInput(ugrid);
4411 Mactor->DataSource = PtsMapper->GetInput();
4412 Mactor->SetMapper(PtsMapper);
4414 QApplication::restoreOverrideCursor();
4417 //=============================================================================
4421 //=============================================================================
4422 void SMESHGUI::RemoveNode(SMESH_Actor * Mactor, int idnode)
4424 MESSAGE(" OLD RemoveNode method ")
4425 // int id = Mactor->GetIdVTKNode( idnode );
4426 // MESSAGE ( " RemoveNode id VTK " << id )
4427 // if ( Mactor->GetMapper() != NULL ) {
4428 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4429 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4430 // vtkPoints *Pts = ugrid->GetPoints();
4431 // vtkPoints *newPts = vtkPoints::New();
4432 // int nbPts = Pts->GetNumberOfPoints();
4433 // bool findPt = false;
4434 // for ( int i = 0; i < nbPts; i++ ) {
4437 // newPts->InsertPoint(i, Pts->GetPoint(i) );
4439 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
4442 // Mactor->RemoveNode( idnode );
4445 // newUgrid->SetPoints(newPts);
4446 // int nbCells = ugrid->GetNumberOfCells();
4447 // for ( int i = 0; i < nbCells; i++ ) {
4448 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4449 // vtkIdList *newIds = vtkIdList::New();
4450 // int nbIds = Ids->GetNumberOfIds();
4451 // newIds->SetNumberOfIds(nbIds);
4452 // for ( int j = 0; j < nbIds; j++ ) {
4453 // int theid = Ids->GetId(j);
4454 // if ( theid > id ) {
4455 // newIds->SetId( j, theid-1 );
4457 // newIds->SetId( j, theid );
4459 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
4460 // Mactor->RemoveElement( idSMDSel, false );
4461 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
4462 // Mactor->AddElement( idSMDSel, idVTKel );
4464 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4465 // Mapper->SetInput( newUgrid );
4466 // Mactor->DataSource = Mapper->GetInput();
4467 // Mactor->SetMapper(Mapper);
4472 //=============================================================================
4476 //=============================================================================
4477 void SMESHGUI::RemoveNodes(SMESH_Actor * Mactor, int number,
4478 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4480 QApplication::setOverrideCursor(Qt::waitCursor);
4484 Mactor->RemoveNode(indexes[i - 1]);
4488 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
4489 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
4490 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
4492 if (Mactor->GetMapper() != NULL)
4494 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4495 SMESH_Grid *newUgrid = SMESH_Grid::New();
4496 newUgrid->CopyMaps(ugrid);
4498 vtkPoints *Pts = ugrid->GetPoints();
4499 vtkPoints *newPts = vtkPoints::New();
4500 int nbPts = Pts->GetNumberOfPoints();
4502 for (int i = 0; i < nbPts; i++)
4504 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
4505 if (idSMESHDSNode != -1)
4507 newPts->InsertPoint(j, Pts->GetPoint(i));
4509 newMapVTKNodes.Bind(j, idSMESHDSNode);
4510 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
4512 MapOldNodesToNewNodes.Bind(i, j);
4517 newUgrid->SetIdsVTKNode(newMapVTKNodes);
4518 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
4519 newUgrid->SetPoints(newPts);
4521 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4522 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4524 int nbCells = ugrid->GetNumberOfCells();
4525 for (int i = 0; i < nbCells; i++)
4527 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4528 vtkIdList *newIds = vtkIdList::New();
4529 int nbIds = Ids->GetNumberOfIds();
4530 newIds->SetNumberOfIds(nbIds);
4532 for (int j = 0; j < nbIds; j++)
4534 int theid = Ids->GetId(j);
4535 if (MapOldNodesToNewNodes.IsBound(theid))
4537 newIds->SetId(j, MapOldNodesToNewNodes.Find(theid));
4546 // Filtering out cells based on non-existing nodes
4549 int idSMDSel = Mactor->GetIdSMESHDSElement(i);
4551 newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4554 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
4555 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
4559 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4560 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4562 // Copy new data to the old DatSource: keep the single DataSource for all actors
4563 ugrid->DeepCopy(newUgrid);
4565 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4566 Mapper->SetInput(ugrid);
4567 Mactor->SetMapper(Mapper);
4569 // Commented to avoid multiple viewer updates when called by ReadScript()
4573 QApplication::restoreOverrideCursor();
4576 //=============================================================================
4580 //=============================================================================
4581 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh,
4582 const TColStd_MapOfInteger & MapIndex)
4584 QApplication::setOverrideCursor(Qt::waitCursor);
4585 Standard_Boolean result;
4586 SMESH_Actor *ac = FindActor(aMesh, result, true);
4589 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4590 anArrayOfIdeces->length(MapIndex.Extent());
4591 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4593 for (; ite.More(); ite.Next())
4595 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
4596 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
4599 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4600 aMeshEditor->RemoveNodes(anArrayOfIdeces);
4603 if (myAutomaticUpdate)
4605 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4608 smeshGUI->DisplayActor(Mesh);
4609 smeshGUI->DisplayEdges(Mesh);
4610 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4611 AddActorInSelection(Mesh);
4614 QApplication::restoreOverrideCursor();
4617 //=============================================================================
4621 //=============================================================================
4622 void SMESHGUI::RemoveElement(SMESH_Actor * Mactor, int idelement)
4624 MESSAGE(" OLD RemoveElement method ")
4625 // int id = Mactor->GetIdVTKElement( idelement );
4626 // MESSAGE ( " RemoveElement id VTK : " << id )
4627 // if ( Mactor->GetMapper() != NULL ) {
4628 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4629 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4630 // int nbCells = ugrid->GetNumberOfCells();
4631 // for ( int i = 0; i < nbCells; i++ ) {
4633 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
4634 // ugrid->GetCell(i)->GetPointIds() );
4636 // Mactor->RemoveElement( idelement );
4638 // newUgrid->SetPoints(ugrid->GetPoints());
4639 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4640 // Mapper->SetInput( newUgrid );
4641 // Mactor->DataSource = Mapper->GetInput();
4642 // Mactor->SetMapper(Mapper);
4647 //=============================================================================
4651 //=============================================================================
4652 void SMESHGUI::RemoveElements(SMESH_Actor * Mactor, int number,
4653 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4655 QApplication::setOverrideCursor(Qt::waitCursor);
4659 Mactor->RemoveElement(indexes[i - 1]);
4662 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4663 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4665 if (Mactor->GetMapper() != NULL)
4667 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4668 SMESH_Grid *newUgrid = SMESH_Grid::New();
4669 newUgrid->CopyMaps(ugrid);
4671 int nbCells = ugrid->GetNumberOfCells();
4672 for (int i = 0; i < nbCells; i++)
4674 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
4675 if (idSMESHDSElement != -1)
4678 newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4679 ugrid->GetCell(i)->GetPointIds());
4680 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
4681 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
4685 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4686 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4688 newUgrid->SetPoints(ugrid->GetPoints());
4690 // Copy new data to the old DatSource: keep the single DataSource for all actors
4691 ugrid->DeepCopy(newUgrid);
4693 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4694 Mapper->SetInput(ugrid);
4695 Mactor->SetMapper(Mapper);
4697 // Commented to avoid multiple viewer updates when called by ReadScript()
4700 QApplication::restoreOverrideCursor();
4703 //=============================================================================
4707 //=============================================================================
4708 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh,
4709 const TColStd_MapOfInteger & MapIndex)
4711 QApplication::setOverrideCursor(Qt::waitCursor);
4712 Standard_Boolean result;
4713 SMESH_Actor *ac = FindActor(aMesh, result, true);
4716 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4717 anArrayOfIdeces->length(MapIndex.Extent());
4718 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4720 for (; ite.More(); ite.Next())
4722 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
4723 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
4727 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4728 aMeshEditor->RemoveElements(anArrayOfIdeces);
4731 if (myAutomaticUpdate)
4733 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4736 smeshGUI->DisplayActor(Mesh);
4737 smeshGUI->DisplayEdges(Mesh);
4738 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4739 AddActorInSelection(Mesh);
4745 QApplication::restoreOverrideCursor();
4748 //=============================================================================
4752 //=============================================================================
4753 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
4754 const TColStd_MapOfInteger & MapIndex)
4756 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4759 vtkRenderer *theRenderer =
4760 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4761 getRightFrame()->getViewFrame())->getRenderer();
4762 Standard_Boolean result;
4763 SMESH_Actor *ac = FindActor(aMesh, result, true);
4766 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4767 SMESH_Grid *UGrid = SMESH_Grid::New();
4768 SMESH_Grid *oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
4769 UGrid->CopyMaps(oldGrid);
4771 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4772 gf->SetInput(ac->DataSource);
4774 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4775 Mapper->SetInput(gf->GetOutput());
4778 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4779 for (; ite.More(); ite.Next())
4781 Mapper->GetInput()->ReverseCell(ite.Key());
4784 UGrid->SetPoints(Mapper->GetInput()->GetPoints());
4785 int nbCells = Mapper->GetInput()->GetNumberOfCells();
4786 for (int i = 0; i < nbCells; i++)
4788 UGrid->InsertNextCell(Mapper->GetInput()->GetCellType(i),
4789 Mapper->GetInput()->GetCell(i)->GetPointIds());
4792 // Copy new data to the old DatSource: keep the single DataSource for all actors
4793 oldGrid->DeepCopy(UGrid);
4795 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4796 //NewMapper->SetInput( UGrid );
4797 NewMapper->SetInput(oldGrid);
4798 NewMapper->Update();
4800 //ac->DataSource = NewMapper->GetInput();
4801 ac->SetMapper(NewMapper);
4803 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4805 QApplication::restoreOverrideCursor();
4808 //=============================================================================
4812 //=============================================================================
4813 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
4814 const TColStd_MapOfInteger & MapIndex)
4816 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4819 QApplication::setOverrideCursor(Qt::waitCursor);
4820 vtkRenderer *theRenderer =
4821 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4822 getRightFrame()->getViewFrame())->getRenderer();
4823 Standard_Boolean result;
4825 SMESH_Actor *ac = FindActor(aMesh, result, true);
4828 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4829 SMESH_Grid *UGrid = SMESH_Grid::New();
4830 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4831 gf->SetInput(ac->DataSource);
4833 vtkExtractEdges *edges = vtkExtractEdges::New();
4834 edges->SetInput(ac->DataSource);
4836 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4837 Mapper->SetInput(edges->GetOutput());
4840 int nb = Mapper->GetInput()->GetNumberOfCells();
4841 //MESSAGE ( "nb : " << nb )
4843 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4844 for (; ite.More(); ite.Next())
4846 vtkCell *StartEdge = Mapper->GetInput()->GetCell(ite.Key());
4847 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
4848 int CellType = StartEdge->GetCellType();
4849 //MESSAGE( "DCQ : Cell Type = " << CellType)
4850 int nbPoints = StartEdge->GetNumberOfPoints();
4852 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4855 vtkUnstructuredGrid *StartUGrid =
4856 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
4858 vtkIdList *IdCells = vtkIdList::New();
4859 vtkIdList *IdPoints = StartEdge->GetPointIds();
4863 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),
4865 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),
4868 int idp1 = StartUGrid->FindPoint(p1);
4869 int idp2 = StartUGrid->FindPoint(p2);
4871 StartUGrid->GetPointCells(idp1, IdCells);
4873 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4874 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4876 //MESSAGE ( " pt 0 : " << idp1 )
4877 //MESSAGE ( " pt 1 : " << idp2 )
4879 vtkIdList *IdPts = vtkIdList::New();
4880 if (IdCells->GetNumberOfIds() >= 2)
4882 int nbCells = IdCells->GetNumberOfIds();
4883 //MESSAGE ( " nbCells : " << nbCells )
4884 for (int j = 0; j < nbCells; j++)
4886 StartUGrid->GetCellPoints(IdCells->GetId(j), IdPts);
4887 if (IdPts->IsId(idp2) == -1)
4889 IdCells->DeleteId(IdCells->GetId(j));
4893 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4895 vtkIdList *IdPts0 = vtkIdList::New();
4896 vtkIdList *IdPts1 = vtkIdList::New();
4898 if (IdCells->GetNumberOfIds() == 2)
4900 StartUGrid->GetCellPoints(IdCells->GetId(0), IdPts0);
4901 StartUGrid->GetCellPoints(IdCells->GetId(1), IdPts1);
4904 TColStd_MapOfInteger EndMapIndex;
4905 for (int j = 0; j < 3; j++)
4907 if (IdPts0->GetId(j) != idp1 &&
4908 IdPts0->GetId(j) != idp2)
4910 EndMapIndex.Add(IdPts0->GetId(j));
4912 if (IdPts1->GetId(j) != idp1 &&
4913 IdPts1->GetId(j) != idp2)
4915 EndMapIndex.Add(IdPts1->GetId(j));
4919 bool MyAU = myAutomaticUpdate;
4920 myAutomaticUpdate = false;
4922 EndMapIndex.Add(idp1);
4923 TColStd_MapIteratorOfMapOfInteger ite1(EndMapIndex);
4927 if (ite1.Key() == idp1)
4932 bool reverse1 = (i == 2);
4933 this->AddFace(aMesh, EndMapIndex, reverse1);
4935 EndMapIndex.Remove(idp1);
4936 EndMapIndex.Add(idp2);
4937 TColStd_MapIteratorOfMapOfInteger ite2(EndMapIndex);
4941 if (ite2.Key() == idp2)
4946 bool reverse2 = (i == 2);
4947 this->AddFace(aMesh, EndMapIndex,
4948 !(reverse1 == reverse2));
4950 myAutomaticUpdate = MyAU;
4951 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4954 TColStd_MapOfInteger StartMapIndex;
4955 StartMapIndex.Add(IdCells->GetId(0));
4956 StartMapIndex.Add(IdCells->GetId(1));
4957 this->RemoveElements(aMesh, StartMapIndex);
4965 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4966 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4967 // for ( int i = 0; i < nbCells; i++ ) {
4968 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4971 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4972 // NewMapper->SetInput( UGrid );
4973 // NewMapper->Update();
4975 // ac->DataSource = NewMapper->GetInput();
4976 // ac->SetMapper( NewMapper );
4978 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4980 QApplication::restoreOverrideCursor();
4983 //=============================================================================
4987 //=============================================================================
4988 void SMESHGUI::AddEdges(SMESH_Actor * Mactor, int number,
4989 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4991 QApplication::setOverrideCursor(Qt::waitCursor);
4992 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4993 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4998 vtkIdList *Ids = vtkIdList::New();
4999 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5000 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5001 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
5002 Mactor->AddElement(indexes[j - 1], id);
5006 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
5007 EdgeMapper->SetInput(ugrid);
5008 Mactor->DataSource = EdgeMapper->GetInput();
5009 Mactor->SetMapper(EdgeMapper);
5010 QApplication::restoreOverrideCursor();
5013 //=============================================================================
5017 //=============================================================================
5018 void SMESHGUI::AddEdge(SMESH_Actor * Mactor, int idedge, int idnode1,
5021 QApplication::setOverrideCursor(Qt::waitCursor);
5022 MESSAGE("SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" <<
5023 idnode2) vtkIdList *Ids = vtkIdList::New();
5024 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5025 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5027 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5028 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5029 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
5030 Mactor->AddElement(idedge, id);
5032 MESSAGE(" Edge VTK id " << id)
5033 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
5034 EdgeMapper->SetInput(ugrid);
5035 Mactor->DataSource = EdgeMapper->GetInput();
5036 Mactor->SetMapper(EdgeMapper);
5037 QApplication::restoreOverrideCursor();
5040 //=============================================================================
5044 //=============================================================================
5045 void SMESHGUI::AddTriangles(SMESH_Actor * Mactor, int number,
5046 const SMESH::double_array & coords, const SMESH::long_array & indexes)
5048 QApplication::setOverrideCursor(Qt::waitCursor);
5049 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5050 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5055 vtkIdList *Ids = vtkIdList::New();
5056 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5057 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5058 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5059 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
5060 Mactor->AddElement(indexes[j - 1], id);
5064 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
5065 TriMapper->SetInput(ugrid);
5066 Mactor->DataSource = TriMapper->GetInput();
5067 Mactor->SetMapper(TriMapper);
5068 QApplication::restoreOverrideCursor();
5070 void SMESHGUI::AddTriangle(SMESH_Actor * Mactor, int idtri, int idnode1,
5071 int idnode2, int idnode3)
5073 QApplication::setOverrideCursor(Qt::waitCursor);
5074 vtkIdList *Ids = vtkIdList::New();
5075 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5076 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5077 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5079 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5080 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5081 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
5082 Mactor->AddElement(idtri, id);
5084 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
5085 TriMapper->SetInput(ugrid);
5086 Mactor->DataSource = TriMapper->GetInput();
5087 Mactor->SetMapper(TriMapper);
5088 QApplication::restoreOverrideCursor();
5091 //=============================================================================
5095 //=============================================================================
5096 void SMESHGUI::AddQuadrangles(SMESH_Actor * Mactor, int number,
5097 const SMESH::double_array & coords, const SMESH::long_array & indexes)
5099 QApplication::setOverrideCursor(Qt::waitCursor);
5100 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5101 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5106 vtkIdList *Ids = vtkIdList::New();
5107 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5108 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5109 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5110 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5111 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5112 Mactor->AddElement(indexes[j - 1], id);
5116 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5117 QuadMapper->SetInput(ugrid);
5118 Mactor->DataSource = QuadMapper->GetInput();
5119 Mactor->SetMapper(QuadMapper);
5120 QApplication::restoreOverrideCursor();
5123 //=============================================================================
5127 //=============================================================================
5128 void SMESHGUI::AddQuadrangle(SMESH_Actor * Mactor, int idquad, int idnode1,
5129 int idnode2, int idnode3, int idnode4)
5131 QApplication::setOverrideCursor(Qt::waitCursor);
5132 vtkIdList *Ids = vtkIdList::New();
5133 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5134 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5135 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5136 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5138 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5139 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5140 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5141 Mactor->AddElement(idquad, id);
5143 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5144 QuadMapper->SetInput(ugrid);
5145 Mactor->DataSource = QuadMapper->GetInput();
5146 Mactor->SetMapper(QuadMapper);
5147 QApplication::restoreOverrideCursor();
5150 //=============================================================================
5154 //=============================================================================
5155 void SMESHGUI::AddTetras(SMESH_Actor * Mactor, int number,
5156 const SMESH::double_array & coords, const SMESH::long_array & indexes)
5158 QApplication::setOverrideCursor(Qt::waitCursor);
5159 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5160 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5165 vtkIdList *Ids = vtkIdList::New();
5166 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5167 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5168 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5169 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5170 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5171 Mactor->AddElement(indexes[j - 1], id);
5175 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5176 TetraMapper->SetInput(ugrid);
5177 Mactor->DataSource = TetraMapper->GetInput();
5178 Mactor->SetMapper(TetraMapper);
5179 QApplication::restoreOverrideCursor();
5182 //=============================================================================
5186 //=============================================================================
5187 void SMESHGUI::AddTetra(SMESH_Actor * Mactor, int idtetra, int idnode1,
5188 int idnode2, int idnode3, int idnode4)
5190 QApplication::setOverrideCursor(Qt::waitCursor);
5191 MESSAGE("SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" <<
5192 idnode2 << ";" << idnode3 << ";" << idnode4) vtkIdList *Ids =
5194 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5195 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5196 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5197 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5199 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5200 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5201 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5202 Mactor->AddElement(idtetra, id);
5204 MESSAGE(" Tetra VTK id " << id)
5205 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5206 TetraMapper->SetInput(ugrid);
5207 Mactor->DataSource = TetraMapper->GetInput();
5208 Mactor->SetMapper(TetraMapper);
5209 QApplication::restoreOverrideCursor();
5212 //=============================================================================
5216 //=============================================================================
5217 void SMESHGUI::AddHexaedres(SMESH_Actor * Mactor, int number,
5218 const SMESH::double_array & coords, const SMESH::long_array & indexes)
5220 QApplication::setOverrideCursor(Qt::waitCursor);
5221 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5222 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5227 vtkIdList *Ids = vtkIdList::New();
5228 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5229 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5230 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5231 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5232 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 4]));
5233 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 5]));
5234 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 6]));
5235 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 7]));
5236 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5237 Mactor->AddElement(indexes[j - 1], id);
5241 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5242 HexaMapper->SetInput(ugrid);
5243 Mactor->DataSource = HexaMapper->GetInput();
5244 Mactor->SetMapper(HexaMapper);
5245 QApplication::restoreOverrideCursor();
5248 //=============================================================================
5252 //=============================================================================
5253 void SMESHGUI::AddHexaedre(SMESH_Actor * Mactor, int idhexa, int idnode1,
5254 int idnode2, int idnode3, int idnode4, int idnode5, int idnode6,
5255 int idnode7, int idnode8)
5257 QApplication::setOverrideCursor(Qt::waitCursor);
5258 MESSAGE("SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" <<
5259 idnode2 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" <<
5260 idnode6 << ";" << idnode7 << ";" << idnode8) vtkIdList *Ids =
5262 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5263 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5264 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5265 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5266 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode5));
5267 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode6));
5268 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode7));
5269 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode8));
5271 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5272 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5273 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5274 Mactor->AddElement(idhexa, id);
5276 MESSAGE(" Hexa VTK id " << id)
5277 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5278 HexaMapper->SetInput(ugrid);
5279 Mactor->DataSource = HexaMapper->GetInput();
5280 Mactor->SetMapper(HexaMapper);
5281 QApplication::restoreOverrideCursor();
5284 //=====================================================================================
5286 //=====================================================================================
5289 bool OnGUIEvent(int theCommandID, QAD_Desktop * parent)
5291 return SMESHGUI::OnGUIEvent(theCommandID, parent);
5294 bool OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
5295 QAD_StudyFrame * studyFrame)
5297 return SMESHGUI::OnKeyPress(pe, parent, studyFrame);
5300 bool OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
5301 QAD_StudyFrame * studyFrame)
5303 return SMESHGUI::OnMousePress(pe, parent, studyFrame);
5306 bool OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
5307 QAD_StudyFrame * studyFrame)
5309 return SMESHGUI::OnMouseMove(pe, parent, studyFrame);
5312 bool SetSettings(QAD_Desktop * parent)
5314 return SMESHGUI::SetSettings(parent);
5317 bool customPopup(QAD_Desktop * parent, QPopupMenu * popup,
5318 const QString & theContext, const QString & theParent,
5319 const QString & theObject)
5321 return SMESHGUI::CustomPopup(parent, popup, theContext, theParent,
5325 void definePopup(QString & theContext, QString & theParent,
5326 QString & theObject)
5328 SMESHGUI::DefinePopup(theContext, theParent, theObject);
5331 bool activeStudyChanged(QAD_Desktop * parent)
5333 SMESHGUI::activeStudyChanged(parent);
5336 void buildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
5338 SMESHGUI::BuildPresentation(theIO);
5341 void supportedViewType(int *buffer, int bufferSize)
5343 if (!buffer || !bufferSize)
5345 buffer[0] = (int)VIEW_VTK;
5350 //=============================================================================
5354 //=============================================================================
5355 void SMESHGUI::ViewNodes()
5357 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5360 EraseSimulationActors();
5361 mySimulationActors = vtkActorCollection::New();
5362 vtkRenderer *theRenderer =
5363 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5364 getRightFrame()->getViewFrame())->getRenderer();
5365 vtkActorCollection *theActors = theRenderer->GetActors();
5366 theActors->InitTraversal();
5367 vtkActor *ac = theActors->GetNextActor();
5368 while (!(ac == NULL))
5370 if (ac->IsA("SMESH_Actor"))
5372 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5373 if (anActor->GetVisibility() == 1)
5375 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5376 gf->SetInput(anActor->DataSource);
5377 vtkMaskPoints *verts = vtkMaskPoints::New();
5378 verts->SetInput(gf->GetOutput());
5379 verts->GenerateVerticesOn();
5380 verts->SetOnRatio(1);
5382 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
5383 vertMapper->SetInput(verts->GetOutput());
5384 vertMapper->ScalarVisibilityOff();
5386 vtkActor *vertActor = vtkActor::New();
5387 vertActor->SetMapper(vertMapper);
5390 anActor->GetNodeColor(r, g, b);
5391 vertActor->GetProperty()->SetColor(r, g, b);
5393 vertActor->GetProperty()->SetPointSize(anActor->GetNodeSize());
5395 vertActor->PickableOff();
5397 mySimulationActors->AddItem(vertActor);
5398 theRenderer->AddActor(vertActor);
5401 ac = theActors->GetNextActor();
5404 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5408 //=============================================================================
5412 //=============================================================================
5413 void SMESHGUI::Control(int theCommandID)
5415 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5418 QApplication::setOverrideCursor(Qt::waitCursor);
5419 DisplayScalarBar(false);
5421 vtkDoubleArray *scalars = vtkDoubleArray::New();
5422 scalars->SetNumberOfComponents(1);
5424 vtkDataSetMapper *meshMapper = 0;
5425 SALOME_Selection *Sel =
5426 SALOME_Selection::Selection(myActiveStudy->getSelection());
5427 int nbSel = Sel->IObjectCount();
5428 Standard_Boolean result;
5429 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5430 SMESH_Actor *MeshActor =
5431 FindActorByEntry(IObject->getEntry(), result, true);
5433 // Mesh may be not updated after Compute
5434 if (!MeshActor->DataSource || !MeshActor->GetMapper())
5436 QApplication::restoreOverrideCursor();
5440 vtkDataSet *aDataSet = MeshActor->DataSource;
5441 typedef double (*TScalarFun) (vtkCell * theCell);
5442 TScalarFun aScalarFun;
5446 switch (theCommandID)
5450 type = tr("SMESH_CONTROL_LENGTH_EDGES");
5451 aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
5452 aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
5453 MESSAGE(" init minimum length " << aDataSet->GetNumberOfCells());
5454 if (MeshActor->getDisplayMode() != 0)
5455 ChangeRepresentation(MeshActor, 1); // limitation; in Wireframe, colored edges are not visible
5460 type = tr("SMESH_CONTROL_AREA_ELEMENTS");
5461 aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
5462 if (MeshActor->getDisplayMode() != 1)
5463 ChangeRepresentation(MeshActor, 1);
5468 type = tr("SMESH_CONTROL_TAPER_ELEMENTS");
5469 aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
5474 type = tr("SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
5475 aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
5476 if (MeshActor->getDisplayMode() != 1)
5477 ChangeRepresentation(MeshActor, 1);
5482 type = tr("SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
5483 aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
5484 if (MeshActor->getDisplayMode() != 1)
5485 ChangeRepresentation(MeshActor, 1);
5490 type = tr("SMESH_CONTROL_WARP_ELEMENTS");
5491 aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
5496 type = tr("SMESH_CONTROL_SKEW_ELEMENTS");
5497 aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
5502 for (int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
5503 scalars->InsertTuple1(i, aScalarFun(aDataSet->GetCell(i)));
5506 scalars->GetRange(range);
5508 vtkLookupTable *wat = vtkLookupTable::New();
5509 wat->SetRange(range);
5512 scalars->SetLookupTable(wat);
5515 meshMapper = (vtkDataSetMapper *) (MeshActor->getMapper());
5516 meshMapper->SetScalarModeToUseCellData();
5517 MeshActor->DataSource->GetCellData()->SetScalars(scalars);
5518 meshMapper->SetScalarRange(range);
5519 meshMapper->ScalarVisibilityOn();
5521 vtkScalarBarActor *aScalarBar = GetScalarBar();
5522 if (aScalarBar == NULL)
5524 aScalarBar = vtkScalarBarActor::New();
5525 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
5526 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
5527 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
5528 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
5529 QString Orientation =
5530 QAD_CONFIG->getSetting("ScalarBar:Orientation");
5531 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
5532 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
5533 int NumberOfLabels =
5534 QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
5535 int NumberOfColors =
5536 QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
5538 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily,
5539 Orientation, Width, Height, NumberOfColors, NumberOfLabels);
5540 vtkRenderer *theRenderer =
5541 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5542 getRightFrame()->getViewFrame())->getRenderer();
5543 theRenderer->AddActor2D(aScalarBar);
5545 aScalarBar->SetLookupTable(wat);
5546 aScalarBar->SetTitle(type.latin1());
5550 DisplayScalarBar(true);
5552 QApplication::restoreOverrideCursor();
5555 //=============================================================================
5559 //=============================================================================
5560 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
5561 QString Bold, QString Italic,
5562 QString Shadow, QString FontFamily,
5563 QString Orientation, float Width, float Height, int NbColors, int NbLabels)
5565 if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
5566 theScalarBar->BoldOn();
5568 theScalarBar->BoldOff();
5570 if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
5571 theScalarBar->ItalicOn();
5573 theScalarBar->ItalicOff();
5575 if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
5576 theScalarBar->ShadowOn();
5578 theScalarBar->ShadowOff();
5580 if (FontFamily.compare("Arial") == 0)
5581 theScalarBar->SetFontFamilyToArial();
5582 else if (FontFamily.compare("Courier") == 0)
5583 theScalarBar->SetFontFamilyToCourier();
5584 else if (FontFamily.compare("Times") == 0)
5585 theScalarBar->SetFontFamilyToTimes();
5587 theScalarBar->SetFontFamilyToArial();
5589 if (Orientation.isNull() || Orientation.isEmpty() ||
5590 (Orientation.compare("Vertical") == 0))
5591 theScalarBar->SetOrientationToVertical();
5593 theScalarBar->SetOrientationToHorizontal();
5595 theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
5596 theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
5598 theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
5599 theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
5602 //=============================================================================
5606 //=============================================================================
5607 void SMESHGUI::DisplayScalarBar(bool visibility)
5609 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5612 vtkRenderer *theRenderer =
5613 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5614 getRightFrame()->getViewFrame())->getRenderer();
5615 vtkScalarBarActor *aScalarBar = GetScalarBar();
5617 if (aScalarBar == NULL)
5619 MESSAGE("myScalarBar is NULL");
5624 aScalarBar->VisibilityOn();
5627 aScalarBar->VisibilityOff();
5628 //Turn off mesh coloring (influences on all views)
5629 vtkActorCollection *actorList = theRenderer->GetActors();
5630 actorList->InitTraversal();
5631 vtkActor *ac = actorList->GetNextActor();
5634 if (ac->GetMapper() != NULL)
5636 ac->GetMapper()->ScalarVisibilityOff();
5638 ac = actorList->GetNextActor();
5640 // Turn off ScalarBar in all views
5641 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
5642 * for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
5643 * if (aFrame->getTypeView() == VIEW_VTK) {
5644 * vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
5645 * vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
5646 * actor2DList->InitTraversal();
5647 * vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
5648 * while (aActor2d != NULL) {
5649 * if (aActor2d->IsA("vtkScalarBarActor")) {
5650 * aActor2d->VisibilityOff();
5653 * actor2DList->GetNextActor2D();
5658 myActiveStudy->update3dViewers();
5661 //=============================================================================
5665 //=============================================================================
5666 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
5668 vtkScalarBarActor *aScalarBar = GetScalarBar();
5669 if (aScalarBar == NULL)
5671 MESSAGE("myScalarBar is NULL");
5674 DisplayScalarBar(false);
5676 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
5677 vtkRenderer *aRenderer =
5678 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5679 getRightFrame()->getViewFrame())->getRenderer();
5680 vtkActorCollection *aActorList = aRenderer->GetActors();
5681 aActorList->InitTraversal();
5682 vtkActor *aActor = aActorList->GetNextActor();
5683 while (aActor != NULL)
5685 if (aActor->IsA("SMESH_Actor"))
5687 SMESH_Actor *aMeshActor = SMESH_Actor::SafeDownCast(aActor);
5688 vtkDataSetMapper *aMeshMapper =
5689 (vtkDataSetMapper *) (aMeshActor->getMapper());
5690 if ((aMeshMapper != NULL))
5692 aMeshMapper->SetScalarRange(MinRange, MaxRange);
5693 aMeshMapper->ScalarVisibilityOn();
5696 aActor = aActorList->GetNextActor();
5698 DisplayScalarBar(true);
5701 //=============================================================================
5705 //=============================================================================
5706 void SMESHGUI::SetDisplaySettings()
5708 EmitSignalDeactivateDialog();
5709 SMESHGUI_Preferences_ColorDlg *aDlg =
5710 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
5712 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
5713 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
5714 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
5715 QColor color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5716 aDlg->SetColor(1, color);
5718 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
5719 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
5720 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
5721 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5722 aDlg->SetColor(2, color);
5724 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5725 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5726 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5727 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5728 aDlg->SetColor(3, color);
5730 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
5731 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
5732 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
5733 color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
5734 aDlg->SetColor(4, color);
5736 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
5737 aDlg->SetIntValue(1, intValue.toInt());
5738 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
5739 aDlg->SetIntValue(2, intValue.toInt());
5740 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
5741 aDlg->SetIntValue(3, intValue.toInt());
5745 QColor colorFill = aDlg->GetColor(1);
5746 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
5747 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen",
5749 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
5751 QColor colorOutline = aDlg->GetColor(2);
5752 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed",
5753 colorOutline.red());
5754 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen",
5755 colorOutline.green());
5756 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue",
5757 colorOutline.blue());
5759 QColor colorNode = aDlg->GetColor(3);
5760 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
5761 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen",
5763 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
5765 QColor colorBackFace = aDlg->GetColor(4);
5766 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed",
5767 colorBackFace.red());
5768 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen",
5769 colorBackFace.green());
5770 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue",
5771 colorBackFace.blue());
5773 int width = aDlg->GetIntValue(1);
5774 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
5776 int nodes_size = aDlg->GetIntValue(2);
5777 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
5779 int shrink_coeff = aDlg->GetIntValue(3);
5780 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
5786 //=======================================================================
5787 // function : Parameter()
5788 // purpose : return a parameter (double) from a dialog box
5790 // aValue : is a double used as a default value displayed
5791 // aLabel : is the title for aValue1
5792 // aTitle : is the main title
5793 // bottom : maximum value to be entered
5794 // top : minimum value to be entered
5795 // decimals : number of decimals
5796 //=======================================================================
5797 double SMESHGUI::Parameter(Standard_Boolean & res,
5798 const double aValue,
5801 const double bottom, const double top, const int decimals)
5803 SMESHGUI_aParameterDlg *Dialog =
5804 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5807 bottom, top, decimals,
5809 Dialog->setValue(aValue);
5811 res = (Dialog->exec() == QDialog::Accepted);
5813 X = Dialog->getDblValue();
5817 //=======================================================================
5818 // function : Parameter()
5819 // purpose : return a parameter (int) from a dialog box
5821 // aValue : is a int used as a default value displayed
5822 // aLabel : is the title for aValue1
5823 // aTitle : is the main title
5824 // bottom : maximum value to be entered
5825 // top : minimum value to be entered
5826 //=======================================================================
5827 int SMESHGUI::Parameter(Standard_Boolean & res,
5829 const char *aLabel, const char *aTitle, const int bottom, const int top)
5831 SMESHGUI_aParameterDlg *Dialog =
5832 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5837 Dialog->setValue(aValue);
5839 res = (Dialog->exec() == QDialog::Accepted);
5841 X = Dialog->getIntValue();
5845 //=============================================================================
5849 //=============================================================================
5850 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility)
5852 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5854 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5857 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5858 gf->SetInput(ac->DataSource);
5859 vtkFeatureEdges *edges = vtkFeatureEdges::New();
5860 edges->SetInput(gf->GetOutput());
5861 edges->BoundaryEdgesOn();
5862 edges->ManifoldEdgesOn();
5864 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5865 edgeMapper->SetInput(edges->GetOutput());
5866 edgeMapper->ScalarVisibilityOff();
5868 vtkRenderer *theRenderer =
5869 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5870 getRightFrame()->getViewFrame())->getRenderer();
5871 vtkActorCollection *actorList = theRenderer->GetActors();
5873 int test = actorList->IsItemPresent(ac->EdgeDevice);
5876 vtkProperty *prop = vtkProperty::New();
5877 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5879 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5881 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5883 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5885 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5887 ac->EdgeDevice->SetProperty(prop);
5888 ac->SetEdgeColor(QAD_CONFIG->
5889 getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5890 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5892 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5894 ac->EdgeDevice->SetMapper(edgeMapper);
5896 theRenderer->AddActor(ac->EdgeDevice);
5900 ac->EdgeDevice->SetMapper(edgeMapper);
5901 edgeMapper->Update();
5904 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5905 shrink->SetInput(ac->DataSource);
5906 shrink->SetShrinkFactor(ac->GetShrinkFactor());
5907 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5908 Shrinkgf->SetInput(shrink->GetOutput());
5909 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5910 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5911 ShrinkEdges->BoundaryEdgesOn();
5912 ShrinkEdges->ManifoldEdgesOn();
5914 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5915 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5916 ShrinkEdgeMapper->ScalarVisibilityOff();
5918 test = actorList->IsItemPresent(ac->EdgeShrinkDevice);
5921 vtkProperty *prop = vtkProperty::New();
5922 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5924 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5926 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5928 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5930 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5932 ac->EdgeShrinkDevice->SetProperty(prop);
5933 ac->SetEdgeColor(QAD_CONFIG->
5934 getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5935 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5937 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5939 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5941 theRenderer->AddActor(ac->EdgeShrinkDevice);
5945 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5946 ShrinkEdgeMapper->Update();
5949 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5953 //=============================================================================
5957 //=============================================================================
5958 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5960 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh(aMesh);
5961 SALOMEDS::GenericAttribute_var anAttr;
5962 SALOMEDS::AttributeName_var aName;
5963 if (!aSO_M->_is_nil())
5965 if (aSO_M->FindAttribute(anAttr, "AttributeName"))
5967 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5968 Standard_Boolean result;
5969 SMESH_Actor *MeshActor =
5970 smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5973 SMESH_Actor *amesh = SMESH_Actor::New();
5974 Handle(SALOME_InteractiveObject) IO =
5975 new SALOME_InteractiveObject(aSO_M->GetID(), "MESH",
5978 amesh->setName(aName->Value());
5979 DisplayActor(amesh, false);
5985 //=============================================================================
5989 //=============================================================================
5990 void SMESHGUI::Update()
5992 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
5994 vtkRenderer *theRenderer =
5995 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5996 getRightFrame()->getViewFrame())->getRenderer();
5998 SALOME_Selection *Sel =
5999 SALOME_Selection::Selection(myActiveStudy->getSelection());
6000 int nbSel = Sel->IObjectCount();
6003 vtkActorCollection *actorList = theRenderer->GetActors();
6004 actorList->InitTraversal();
6005 vtkActor *ac = actorList->GetNextActor();
6006 while (!(ac == NULL))
6008 if (ac->IsA("SMESH_Actor"))
6010 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
6011 if (anActor->hasIO())
6013 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
6017 ac = actorList->GetNextActor();
6022 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
6023 for (; It.More(); It.Next())
6025 Handle(SALOME_InteractiveObject) IO = It.Value();
6029 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6032 QApplication::restoreOverrideCursor();
6035 //=============================================================================
6039 //=============================================================================
6040 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & IO)
6042 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6047 Standard_Boolean res;
6048 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh(IO, res);
6051 SMESH_Actor *ac = FindActorByEntry(IO->getEntry(), res, false);
6054 // Check whether the actor belongs to the active view
6055 VTKViewer_RenderWindowInteractor *rwInter =
6056 ((VTKViewer_ViewFrame *) myActiveStudy->
6057 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
6060 ac = ReadScript(aMesh);
6061 // The actor belongs to inactive view -> create a copy and display it in the active view
6062 if (!rwInter->isInViewer(IO))
6064 SMESH_Actor *acCopy = SMESH_Actor::New();
6065 acCopy->ShallowCopy(ac);
6076 smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
6083 //=============================================================================
6087 //=============================================================================
6088 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
6090 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6093 mySimulationActors = vtkActorCollection::New();
6094 vtkRenderer *theRenderer =
6095 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6096 getRightFrame()->getViewFrame())->getRenderer();
6098 vtkUnstructuredGrid *ugrid =
6099 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
6100 vtkIdList *IdCells = vtkIdList::New();
6101 ugrid->GetPointCells(idnode, IdCells);
6103 vtkPoints *Pts = vtkPoints::New();
6104 Pts = ugrid->GetPoints();
6106 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
6107 ugridSimulation->SetPoints(Pts);
6108 vtkIdList *IdPts = vtkIdList::New();
6109 for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
6111 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
6112 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
6116 vtkProperty *prop = vtkProperty::New();
6117 prop->SetColor(1., 0., 0.);
6118 prop->SetRepresentationToWireframe();
6120 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
6123 prop->SetLineWidth(Edgewidth + 1);
6125 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6126 Mapper->SetInput(ugridSimulation);
6127 vtkActor *ac = vtkActor::New();
6128 ac->SetMapper(Mapper);
6129 ac->SetProperty(prop);
6131 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
6132 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
6134 mySimulationActors->AddItem(ac);
6135 theRenderer->AddActor(ac);
6137 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6143 //=============================================================================
6147 //=============================================================================
6148 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
6151 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6154 EraseSimulationActors();
6155 mySimulationActors = vtkActorCollection::New();
6156 vtkRenderer *theRenderer =
6157 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6158 getRightFrame()->getViewFrame())->getRenderer();
6159 Standard_Boolean result;
6160 SMESH_Actor *ac = FindActor(aMesh, result, true);
6164 vtkUnstructuredGrid *ugrid =
6165 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6166 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6168 vtkPoints *Pts = ugrid->GetPoints();
6169 vtkPoints *newPts = vtkPoints::New();
6170 int nbPts = Pts->GetNumberOfPoints();
6171 for (int i = 0; i < nbPts; i++)
6173 newPts->InsertPoint(i, Pts->GetPoint(i));
6176 newugrid->SetPoints(newPts);
6177 newugrid->GetPoints()->InsertNextPoint(x, y, z);
6179 vtkMaskPoints *verts = vtkMaskPoints::New();
6180 verts->SetInput(newugrid);
6181 verts->SetGenerateVertices(1);
6182 verts->SetOnRatio(1);
6184 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
6185 vertMapper->SetInput(verts->GetOutput());
6186 vertMapper->ScalarVisibilityOff();
6188 vtkActor *node = vtkActor::New();
6189 node->SetMapper(vertMapper);
6191 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
6192 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
6193 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
6194 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
6195 if (!nodecolor.isValid())
6196 // nodecolor = QColor(0.,1.,0.);
6197 nodecolor = QColor(0, 1, 0);
6199 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
6200 float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
6203 QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
6207 node->GetProperty()->SetPointSize(intValue);
6209 node->VisibilityOn();
6211 mySimulationActors->AddItem(node);
6212 theRenderer->AddActor(node);
6215 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6219 //=============================================================================
6223 //=============================================================================
6224 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
6227 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6230 vtkRenderer *theRenderer =
6231 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6232 getRightFrame()->getViewFrame())->getRenderer();
6233 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
6238 ac->GetMapper()->ImmediateModeRenderingOn();
6239 ac->GetProperty()->SetRepresentationToWireframe();
6241 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6246 //=============================================================================
6250 //=============================================================================
6251 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
6254 Standard_Boolean result;
6256 SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
6262 //=============================================================================
6266 //=============================================================================
6267 void SMESHGUI::ScalarVisibilityOff()
6269 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6272 vtkRenderer *theRenderer =
6273 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6274 getRightFrame()->getViewFrame())->getRenderer();
6275 vtkActorCollection *actorList = theRenderer->GetActors();
6277 actorList->InitTraversal();
6278 vtkActor *ac = actorList->GetNextActor();
6279 while (!(ac == NULL))
6281 if (ac->IsA("SMESH_Actor"))
6283 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
6284 if (anActor->GetVisibility() == 1)
6286 vtkDataSetMapper *meshMapper =
6287 (vtkDataSetMapper *) (anActor->getMapper());
6288 meshMapper->ScalarVisibilityOff();
6289 meshMapper->SetInput(anActor->DataSource);
6290 ChangeRepresentation(anActor, anActor->getDisplayMode());
6293 ac = actorList->GetNextActor();
6296 theRenderer->Render();
6299 //=============================================================================
6303 //=============================================================================
6304 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
6305 const TColStd_MapOfInteger & MapIndex)
6307 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6310 EraseSimulationActors();
6311 mySimulationActors = vtkActorCollection::New();
6312 vtkRenderer *theRenderer =
6313 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6314 getRightFrame()->getViewFrame())->getRenderer();
6315 Standard_Boolean result;
6316 SMESH_Actor *ac = FindActor(aMesh, result, true);
6319 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6323 vtkIdList *Ids = vtkIdList::New();
6324 for (; ite.More(); ite.Next())
6326 idNodes[i] = ite.Key();
6330 Ids->InsertId(0, idNodes[0]);
6331 pts[0] = idNodes[0];
6332 Ids->InsertId(1, idNodes[1]);
6333 pts[1] = idNodes[1];
6335 vtkUnstructuredGrid *ugrid =
6336 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6337 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6338 newugrid->SetPoints(ugrid->GetPoints());
6339 newugrid->InsertNextCell(VTK_LINE, 2, pts);
6341 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6342 Mapper->SetInput(newugrid);
6345 vtkActor *edge = vtkActor::New();
6346 edge->SetMapper(Mapper);
6347 edge->SetProperty(ac->GetProperty());
6348 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
6349 edge->VisibilityOn();
6350 mySimulationActors->AddItem(edge);
6351 theRenderer->AddActor(edge);
6354 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6358 //=============================================================================
6362 //=============================================================================
6363 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
6364 const TColStd_MapOfInteger & MapIndex, bool reverse)
6366 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6369 EraseSimulationActors();
6370 mySimulationActors = vtkActorCollection::New();
6371 vtkRenderer *theRenderer =
6372 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6373 getRightFrame()->getViewFrame())->getRenderer();
6374 Standard_Boolean result;
6375 SMESH_Actor *ac = FindActor(aMesh, result, true);
6378 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6382 vtkIdList *Ids = vtkIdList::New();
6383 for (; ite.More(); ite.Next())
6385 idNodes[i] = ite.Key();
6391 Ids->InsertId(0, idNodes[2]);
6392 pts[0] = idNodes[2];
6393 Ids->InsertId(1, idNodes[1]);
6394 pts[1] = idNodes[1];
6395 Ids->InsertId(2, idNodes[0]);
6396 pts[2] = idNodes[0];
6400 Ids->InsertId(0, idNodes[0]);
6401 pts[0] = idNodes[0];
6402 Ids->InsertId(1, idNodes[1]);
6403 pts[1] = idNodes[1];
6404 Ids->InsertId(2, idNodes[2]);
6405 pts[2] = idNodes[2];
6407 vtkUnstructuredGrid *ugrid =
6408 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6409 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6410 newugrid->SetPoints(ugrid->GetPoints());
6411 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
6413 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6414 Mapper->SetInput(newugrid);
6417 vtkActor *tri = vtkActor::New();
6418 tri->SetMapper(Mapper);
6419 tri->SetProperty(ac->GetProperty());
6420 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
6421 tri->VisibilityOn();
6422 mySimulationActors->AddItem(tri);
6423 theRenderer->AddActor(tri);
6426 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6430 //=============================================================================
6434 //=============================================================================
6435 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
6436 const TColStd_MapOfInteger & MapIndex, bool reverse)
6438 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6441 EraseSimulationActors();
6442 mySimulationActors = vtkActorCollection::New();
6443 vtkRenderer *theRenderer =
6444 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6445 getRightFrame()->getViewFrame())->getRenderer();
6446 Standard_Boolean result;
6447 SMESH_Actor *ac = FindActor(aMesh, result, true);
6449 vtkUnstructuredGrid *ugrid =
6450 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6454 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6457 vtkIdList *Ids = vtkIdList::New();
6458 for (; ite.More(); ite.Next())
6460 idNodes[i] = ite.Key();
6464 float *p0 = ugrid->GetPoint(idNodes[0]);
6465 float *p1 = ugrid->GetPoint(idNodes[1]);
6466 float *p2 = ugrid->GetPoint(idNodes[2]);
6467 float *p3 = ugrid->GetPoint(idNodes[3]);
6469 gp_Pnt P0(p0[0], p0[1], p0[2]);
6471 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6472 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6473 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6475 gp_Vec Cross1 = V1 ^ V2;
6476 gp_Vec Cross2 = V2 ^ V3;
6479 if (Cross1.Dot(Cross2) < 0)
6481 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6482 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6486 if (Cross1.Dot(Cross2) < 0)
6489 idNodes[2] = idNodes[3];
6495 idNodes[1] = idNodes[2];
6502 Ids->InsertId(0, idNodes[3]);
6503 Ids->InsertId(1, idNodes[2]);
6504 Ids->InsertId(2, idNodes[1]);
6505 Ids->InsertId(3, idNodes[0]);
6509 Ids->InsertId(0, idNodes[0]);
6510 Ids->InsertId(1, idNodes[1]);
6511 Ids->InsertId(2, idNodes[2]);
6512 Ids->InsertId(3, idNodes[3]);
6515 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
6516 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6517 newugrid->SetPoints(ugrid->GetPoints());
6518 newugrid->InsertNextCell(VTK_QUAD, Ids);
6520 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6521 Mapper->SetInput(newugrid);
6524 vtkActor *quad = vtkActor::New();
6525 quad->SetMapper(Mapper);
6526 quad->SetProperty(ac->GetProperty());
6527 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
6528 quad->VisibilityOn();
6529 mySimulationActors->AddItem(quad);
6530 theRenderer->AddActor(quad);
6532 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6536 //=============================================================================
6540 //=============================================================================
6541 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
6542 const TColStd_MapOfInteger & MapIndex)
6544 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6547 EraseSimulationActors();
6548 mySimulationActors = vtkActorCollection::New();
6549 vtkRenderer *theRenderer =
6550 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6551 getRightFrame()->getViewFrame())->getRenderer();
6552 Standard_Boolean result;
6553 SMESH_Actor *ac = FindActor(aMesh, result, true);
6556 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6559 vtkIdList *Ids = vtkIdList::New();
6560 for (; ite.More(); ite.Next())
6562 idNodes[i] = ite.Key();
6566 Ids->InsertId(0, idNodes[0]);
6567 Ids->InsertId(1, idNodes[1]);
6568 Ids->InsertId(2, idNodes[2]);
6569 Ids->InsertId(3, idNodes[3]);
6571 vtkUnstructuredGrid *ugrid =
6572 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6573 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6574 newugrid->SetPoints(ugrid->GetPoints());
6575 newugrid->InsertNextCell(VTK_TETRA, Ids);
6577 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6578 Mapper->SetInput(newugrid);
6581 vtkActor *tetra = vtkActor::New();
6582 tetra->SetMapper(Mapper);
6583 tetra->SetProperty(ac->GetProperty());
6584 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
6585 tetra->VisibilityOn();
6586 mySimulationActors->AddItem(tetra);
6587 theRenderer->AddActor(tetra);
6589 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6593 //=============================================================================
6597 //=============================================================================
6598 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
6599 const TColStd_MapOfInteger & MapIndex)
6601 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6604 EraseSimulationActors();
6605 mySimulationActors = vtkActorCollection::New();
6606 vtkRenderer *theRenderer =
6607 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6608 getRightFrame()->getViewFrame())->getRenderer();
6609 Standard_Boolean result;
6610 SMESH_Actor *ac = FindActor(aMesh, result, true);
6613 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6616 vtkIdList *Ids = vtkIdList::New();
6617 for (; ite.More(); ite.Next())
6619 idNodes[i] = ite.Key();
6623 Ids->InsertId(0, idNodes[0]);
6624 Ids->InsertId(1, idNodes[1]);
6625 Ids->InsertId(2, idNodes[2]);
6626 Ids->InsertId(3, idNodes[3]);
6627 Ids->InsertId(4, idNodes[4]);
6628 Ids->InsertId(5, idNodes[5]);
6629 Ids->InsertId(6, idNodes[6]);
6630 Ids->InsertId(7, idNodes[7]);
6632 vtkUnstructuredGrid *ugrid =
6633 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6634 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6635 newugrid->SetPoints(ugrid->GetPoints());
6636 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
6638 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6639 Mapper->SetInput(newugrid);
6642 vtkActor *hexa = vtkActor::New();
6643 hexa->SetMapper(Mapper);
6644 hexa->SetProperty(ac->GetProperty());
6645 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
6646 hexa->VisibilityOn();
6647 mySimulationActors->AddItem(hexa);
6648 theRenderer->AddActor(hexa);
6650 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6654 //=============================================================================
6658 //=============================================================================
6659 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr aMesh,
6660 const TColStd_MapOfInteger & MapIndex, bool reverse)
6662 QApplication::setOverrideCursor(Qt::waitCursor);
6663 Standard_Boolean result;
6664 SMESH_Actor *ac = FindActor(aMesh, result, true);
6667 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6668 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6669 anArrayOfIdeces->length(MapIndex.Extent());
6672 for (; ite.More(); ite.Next())
6674 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6679 if (MapIndex.Extent() == 4)
6683 TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
6684 for (; ite1.More(); ite1.Next())
6686 idNodes[i] = ite1.Key();
6690 vtkUnstructuredGrid *ugrid =
6691 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6692 float *p0 = ugrid->GetPoint(idNodes[0]);
6693 float *p1 = ugrid->GetPoint(idNodes[1]);
6694 float *p2 = ugrid->GetPoint(idNodes[2]);
6695 float *p3 = ugrid->GetPoint(idNodes[3]);
6697 gp_Pnt P0(p0[0], p0[1], p0[2]);
6699 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6700 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6701 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6703 gp_Vec Cross1 = V1 ^ V2;
6704 gp_Vec Cross2 = V2 ^ V3;
6706 if (Cross1.Dot(Cross2) < 0)
6709 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6710 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6714 if (Cross1.Dot(Cross2) < 0)
6716 tmp = anArrayOfIdeces[2];
6717 anArrayOfIdeces[2] = anArrayOfIdeces[3];
6718 anArrayOfIdeces[3] = tmp;
6722 tmp = anArrayOfIdeces[1];
6723 anArrayOfIdeces[1] = anArrayOfIdeces[2];
6724 anArrayOfIdeces[2] = tmp;
6732 for (i = 0; i < (MapIndex.Extent() / 2); i++)
6734 tmp = anArrayOfIdeces[i];
6735 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
6736 anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
6739 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6740 aMeshEditor->AddFace(anArrayOfIdeces);
6742 if (myAutomaticUpdate)
6744 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6747 smeshGUI->DisplayActor(Mesh);
6748 smeshGUI->DisplayEdges(Mesh);
6749 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6750 AddActorInSelection(Mesh);
6753 QApplication::restoreOverrideCursor();
6756 //=============================================================================
6760 //=============================================================================
6761 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr aMesh,
6762 const TColStd_MapOfInteger & MapIndex)
6764 QApplication::setOverrideCursor(Qt::waitCursor);
6765 Standard_Boolean result;
6766 SMESH_Actor *ac = FindActor(aMesh, result, true);
6769 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6770 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6771 anArrayOfIdeces->length(MapIndex.Extent());
6774 for (; ite.More(); ite.Next())
6776 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6780 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6781 aMeshEditor->AddVolume(anArrayOfIdeces);
6783 if (myAutomaticUpdate)
6785 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6788 smeshGUI->DisplayActor(Mesh);
6789 smeshGUI->DisplayEdges(Mesh);
6790 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6791 AddActorInSelection(Mesh);
6794 QApplication::restoreOverrideCursor();
6797 //=============================================================================
6801 //=============================================================================
6802 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr aMesh,
6803 const TColStd_MapOfInteger & MapIndex)
6805 QApplication::setOverrideCursor(Qt::waitCursor);
6806 Standard_Boolean result;
6807 SMESH_Actor *ac = FindActor(aMesh, result, true);
6810 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6811 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6812 anArrayOfIdeces->length(MapIndex.Extent());
6815 for (; ite.More(); ite.Next())
6817 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6821 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6822 aMeshEditor->AddEdge(anArrayOfIdeces);
6824 if (myAutomaticUpdate)
6826 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6829 smeshGUI->DisplayActor(Mesh);
6830 smeshGUI->DisplayEdges(Mesh);
6831 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6832 AddActorInSelection(Mesh);
6835 QApplication::restoreOverrideCursor();
6838 //=============================================================================
6842 //=============================================================================
6843 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
6845 QApplication::setOverrideCursor(Qt::waitCursor);
6846 Standard_Boolean result;
6847 SMESH_Actor *ac = FindActor(aMesh, result, true);
6850 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6851 aMeshEditor->AddNode(x, y, z);
6853 if (myAutomaticUpdate)
6855 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6858 smeshGUI->DisplayActor(Mesh);
6859 smeshGUI->DisplayEdges(Mesh);
6860 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6861 AddActorInSelection(Mesh);
6865 QApplication::restoreOverrideCursor();
6868 //=============================================================================
6872 //=============================================================================
6873 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
6875 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6878 EraseSimulationActors();
6879 mySimulationActors2D = vtkActor2DCollection::New();
6881 vtkRenderer *theRenderer =
6882 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6883 getRightFrame()->getViewFrame())->getRenderer();
6885 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
6886 gs2->SetGlyphTypeToTriangle();
6889 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
6890 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
6891 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
6893 legend->SetNumberOfEntries(4);
6894 legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
6895 legend->SetEntrySymbol(0, gs2->GetOutput());
6896 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
6897 legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
6898 legend->SetEntrySymbol(1, gs2->GetOutput());
6899 legend->SetEntryColor(1,
6900 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
6901 legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
6902 legend->SetEntrySymbol(2, gs2->GetOutput());
6903 legend->SetEntryColor(2,
6904 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
6905 legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
6906 legend->SetEntrySymbol(3, gs2->GetOutput());
6907 legend->SetEntryColor(3,
6908 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
6909 legend->SetPadding(5);
6910 // legend->GetProperty()->SetColor();
6912 mySimulationActors2D->AddItem(legend);
6913 theRenderer->AddActor2D(legend);
6916 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
6920 //===============================================================================
6921 // function : OnEditDelete()
6923 //===============================================================================
6924 void SMESHGUI::OnEditDelete()
6926 if (QAD_MessageBox::warn2
6927 (QAD_Application::getDesktop(),
6928 tr("SMESH_WRN_WARNING"),
6929 tr("SMESH_REALLY_DELETE"),
6930 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
6933 int nbSf = myActiveStudy->getStudyFramesCount();
6935 Standard_Boolean found;
6936 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
6937 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
6938 SALOMEDS::GenericAttribute_var anAttr;
6939 SALOMEDS::AttributeIOR_var anIOR;
6941 SALOME_Selection *Sel =
6942 SALOME_Selection::Selection(myActiveStudy->getSelection());
6943 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
6944 for (; It.More(); It.Next())
6946 Handle(SALOME_InteractiveObject) IObject = It.Value();
6947 if (IObject->hasEntry())
6949 SALOMEDS::SObject_var SO =
6950 myStudy->FindObjectID(IObject->getEntry());
6952 /* Erase child graphical objects */
6953 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
6954 for (; it->More(); it->Next())
6956 SALOMEDS::SObject_var CSO = it->Value();
6957 if (CSO->FindAttribute(anAttr, "AttributeIOR"))
6959 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6961 for (int i = 0; i < nbSf; i++)
6963 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6964 if (sf->getTypeView() == VIEW_VTK)
6966 vtkRenderer *Renderer =
6967 ((VTKViewer_ViewFrame *) smeshGUI->
6968 myActiveStudy->getActiveStudyFrame()->
6969 getRightFrame()->getViewFrame())->getRenderer();
6971 smeshGUI->FindActorByEntry(CSO->GetID(), found,
6975 Renderer->RemoveActor(ac->EdgeDevice);
6976 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6977 Renderer->RemoveActor(ac);
6984 /* Erase main graphical object */
6985 for (int i = 0; i < nbSf; i++)
6987 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6988 if (sf->getTypeView() == VIEW_VTK)
6990 vtkRenderer *Renderer =
6991 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
6992 getActiveStudyFrame()->getRightFrame()->
6993 getViewFrame())->getRenderer();
6994 VTKViewer_RenderWindowInteractor *myRenderInter =
6995 ((VTKViewer_ViewFrame *) sf->getRightFrame()->
6996 getViewFrame())->getRWInteractor();
6998 smeshGUI->FindActorByEntry(IObject->getEntry(), found,
7002 Renderer->RemoveActor(ac->EdgeDevice);
7003 Renderer->RemoveActor(ac->EdgeShrinkDevice);
7005 myRenderInter->Remove(IObject);
7009 /* Erase objects in Study */
7010 SALOMEDS::SObject_var obj =
7011 myStudy->FindObjectID(IObject->getEntry());
7012 if (!obj->_is_nil())
7015 new SALOMEGUI_ImportOperation(myActiveStudy);
7017 aStudyBuilder->RemoveObject(obj);
7021 } /* IObject->hasEntry() */
7024 /* Clear any previous selection */
7025 Sel->ClearIObjects();
7026 myActiveStudy->updateObjBrowser();