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"
91 #define INCLUDE_MENUITEM_DEF
92 #include <qapplication.h>
93 #include <qlineedit.h>
94 #include <qmenudata.h>
96 #include <qpopupmenu.h>
99 #include <qcheckbox.h>
100 #include <qcolordialog.h>
101 #include <qmessagebox.h>
102 #include <qspinbox.h>
106 #include <qradiobutton.h>
109 #include "VTKViewer_Common.h"
110 #include "VTKViewer_ViewFrame.h"
111 #include <vtkLegendBoxActor.h>
112 #include <vtkFeatureEdges.h>
113 #include <vtkDoubleArray.h>
115 // Open CASCADE Includes
116 #include <gp_Pnt.hxx>
117 #include <gp_Vec.hxx>
119 static GEOM_Client ShapeReader;
120 static SMESHGUI *smeshGUI = 0;
121 static CORBA::ORB_var _orb;
123 //=============================================================================
127 //=============================================================================
128 class CustomItem:public QCustomMenuItem
131 CustomItem(const QString & s, const QFont & f):string(s), font(f)
138 void paint(QPainter * p, const QColorGroup & /*cg */ , bool /*act */ ,
139 bool /*enabled */ , int x, int y, int w, int h)
142 p->drawText(x, y, w, h,
143 AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
148 return QFontMetrics(font).
149 size(AlignHCenter | AlignVCenter | ShowPrefix | DontClip, string);
156 //=============================================================================
160 //=============================================================================
161 SMESHGUI::SMESHGUI():
166 //=============================================================================
170 //=============================================================================
171 SMESHGUI::~SMESHGUI()
175 //=============================================================================
179 //=============================================================================
180 SMESHGUI *SMESHGUI::GetSMESHGUI()
185 //=============================================================================
189 //=============================================================================
190 SMESHGUI *SMESHGUI::GetOrCreateSMESHGUI(QAD_Desktop * desktop)
195 smeshGUI = new SMESHGUI;
196 smeshGUI->myActiveDialogBox = 0;
197 smeshGUI->myState = -1;
198 smeshGUI->myDesktop = desktop;
199 smeshGUI->myActiveStudy = desktop->getActiveStudy();
201 Engines::Component_var comp =
202 desktop->getEngine("FactoryServer", "SMESH");
203 smeshGUI->myComponentMesh = SMESH::SMESH_Gen::_narrow(comp);
205 Engines::Component_var comp1 =
206 desktop->getEngine("FactoryServer", "GEOM");
207 smeshGUI->myComponentGeom = GEOM::GEOM_Gen::_narrow(comp1);
209 /* GetCurrentStudy */
210 smeshGUI->myStudyId = smeshGUI->myActiveStudy->getStudyId();
212 smeshGUI->myComponentGeom->GetCurrentStudy(smeshGUI->myStudyId);
213 // smeshGUI->myComponentGeom->NbLabels();
215 smeshGUI->myStudy = smeshGUI->myActiveStudy->getStudyDocument();
217 smeshGUI->myStudyAPI =
218 SMESHGUI_StudyAPI(smeshGUI->myStudy, smeshGUI->myComponentMesh);
220 smeshGUI->mySimulationActors = vtkActorCollection::New();
221 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
225 /* study may have changed */
226 smeshGUI->myActiveStudy = desktop->getActiveStudy();
227 smeshGUI->myStudyAPI.Update(smeshGUI->myComponentMesh);
230 /* Automatic Update */
231 if (desktop->menuBar()->isItemChecked(1001))
232 smeshGUI->myAutomaticUpdate = true;
234 smeshGUI->myAutomaticUpdate = false;
239 //=============================================================================
243 //=============================================================================
244 void SMESHGUI::SetState(int aState)
246 this->myState = aState;
250 //=============================================================================
254 //=============================================================================
255 void SMESHGUI::ResetState()
261 //=============================================================================
265 //=============================================================================
266 void SMESHGUI::EmitSignalDeactivateDialog()
268 emit this->SignalDeactivateActiveDialog();
272 //=============================================================================
276 //=============================================================================
277 void SMESHGUI::EmitSignalCloseAllDialogs()
279 emit this->SignalCloseAllDialogs();
283 //=============================================================================
287 //=============================================================================
288 QDialog *SMESHGUI::GetActiveDialogBox()
290 return this->myActiveDialogBox;
293 //=============================================================================
297 //=============================================================================
298 void SMESHGUI::SetActiveDialogBox(QDialog * aDlg)
300 this->myActiveDialogBox = (QDialog *) aDlg;
304 //=============================================================================
308 //=============================================================================
309 QAD_Study *SMESHGUI::GetActiveStudy()
311 return this->myActiveStudy;
314 //=============================================================================
318 //=============================================================================
319 SALOMEDS::Study_ptr SMESHGUI::GetStudy()
321 return SALOMEDS::Study::_narrow(myStudy);
324 //=============================================================================
328 //=============================================================================
329 SMESHGUI_StudyAPI SMESHGUI::GetStudyAPI()
334 //=============================================================================
338 //=============================================================================
339 QAD_Desktop *SMESHGUI::GetDesktop()
341 return this->myDesktop;
344 //=============================================================================
348 //=============================================================================
349 vtkScalarBarActor *SMESHGUI::GetScalarBar()
351 vtkRenderer *aRenderer =
352 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
353 getRightFrame()->getViewFrame())->getRenderer();
354 vtkActor2DCollection *actor2DList = aRenderer->GetActors2D();
355 actor2DList->InitTraversal();
356 vtkActor2D *aActor2d = actor2DList->GetNextActor2D();
357 while (aActor2d != NULL)
359 if (aActor2d->IsA("vtkScalarBarActor"))
360 return vtkScalarBarActor::SafeDownCast(aActor2d);
361 actor2DList->GetNextActor2D();
366 //=============================================================================
370 //=============================================================================
371 void SMESHGUI::activeStudyChanged(QAD_Desktop * parent)
373 MESSAGE("SMESHGUI::activeStudyChanged init.")
374 /* Create or retrieve an object SMESHGUI */
375 SMESHGUI::GetOrCreateSMESHGUI(parent);
378 smeshGUI->EmitSignalCloseAllDialogs();
379 MESSAGE("Active study changed : SMESHGUI nullified" << endl);
383 //smeshGUI->SetSettings( parent ); //DCQ : Pb. Multi-Etudes
384 MESSAGE("SMESHGUI::activeStudyChanged done.") return;
387 //=============================================================================
391 //=============================================================================
392 bool SMESHGUI::DefineDlgPosition(QWidget * aDlg, int &x, int &y)
394 /* Here the position is on the bottom right corner - 10 */
395 aDlg->resize(QSize().expandedTo(aDlg->minimumSizeHint()));
396 QAD_Desktop *PP = QAD_Application::getDesktop();
397 x = abs(PP->x() + PP->size().width() - aDlg->size().width() - 10);
398 y = abs(PP->y() + PP->size().height() - aDlg->size().height() - 10);
402 //=============================================================================
406 //=============================================================================
407 void SMESHGUI::EraseSimulationActors()
409 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
411 vtkRenderer *theRenderer =
412 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
413 getRightFrame()->getViewFrame())->getRenderer();
414 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
416 if (mySimulationActors != NULL)
419 mySimulationActors->InitTraversal();
420 vtkActor *ac = mySimulationActors->GetNextActor();
421 while (!(ac == NULL))
423 theRenderer->RemoveActor(ac);
424 ac = mySimulationActors->GetNextActor();
426 mySimulationActors->RemoveAllItems();
428 if (mySimulationActors2D != NULL)
430 mySimulationActors2D->InitTraversal();
431 vtkActor2D *ac = mySimulationActors2D->GetNextActor2D();
432 while (!(ac == NULL))
434 theRenderer->RemoveActor2D(ac);
435 ac = mySimulationActors2D->GetNextActor2D();
437 mySimulationActors2D->RemoveAllItems();
443 //=============================================================================
447 //=============================================================================
448 SMESH::SMESH_Mesh_ptr SMESHGUI::InitMesh(GEOM::GEOM_Shape_ptr aShape,
453 if (!myComponentMesh->_is_nil() && !aShape->_is_nil())
455 SMESH::SMESH_Mesh_var aMesh =
456 myComponentMesh->Init(myComponentGeom, myStudyId, aShape);
458 if (!aMesh->_is_nil())
460 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh(aMesh);
461 myStudyAPI.SetName(SM, NameMesh);
463 // GEOM::GEOM_Shape has non-empty StudyShapeId only after AddInStudy operation,
464 // not after loading from file, so let's use more reliable way to retrieve SObject
465 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
466 SALOMEDS::SObject_var SObject =
467 myStudy->FindObjectIOR(ShapeIOR);
468 if (!SObject->_is_nil() && !SM->_is_nil())
470 myStudyAPI.SetShape(SM, SObject);
472 return SMESH::SMESH_Mesh::_narrow(aMesh);
476 catch(const SALOME::SALOME_Exception & S_ex)
478 QtCatchCorbaException(S_ex);
480 myActiveStudy->updateObjBrowser(true);
481 return SMESH::SMESH_Mesh::_nil();
484 //=============================================================================
488 //=============================================================================
489 SMESH::SMESH_subMesh_ptr SMESHGUI::AddSubMesh(SMESH::SMESH_Mesh_ptr aMesh,
490 GEOM::GEOM_Shape_ptr aShape, QString NameMesh)
494 SMESH::SMESH_subMesh_var aSubMesh = aMesh->GetElementsOnShape(aShape);
495 SALOMEDS::SObject_var SO_Mesh = myStudyAPI.FindMesh(aMesh);
496 Standard_CString ShapeIOR = _orb->object_to_string(aShape);
497 SALOMEDS::SObject_var SO_GeomShape = myStudy->FindObjectIOR(ShapeIOR);
499 if (!SO_GeomShape->_is_nil() && !SO_Mesh->_is_nil() &&
500 !aSubMesh->_is_nil() && !aMesh->_is_nil())
502 SALOMEDS::SObject_var SO =
503 myStudyAPI.AddSubMeshOnShape(SO_Mesh, SO_GeomShape, aSubMesh,
504 aShape->ShapeType());
505 myStudyAPI.SetName(SO, NameMesh);
507 SMESH_Actor *amesh = SMESH_Actor::New();
508 Handle(SALOME_InteractiveObject) IO =
509 new SALOME_InteractiveObject(SO->GetID(), "MESH",
512 amesh->setName(strdup(NameMesh));
513 DisplayActor(amesh, false);
514 return SMESH::SMESH_subMesh::_narrow(aSubMesh);
517 catch(const SALOME::SALOME_Exception & S_ex)
519 QtCatchCorbaException(S_ex);
521 myActiveStudy->updateObjBrowser(true);
522 return SMESH::SMESH_subMesh::_nil();
525 //=============================================================================
529 //=============================================================================
530 SMESH::SMESH_Hypothesis_ptr SMESHGUI::CreateHypothesis(QString TypeHypothesis,
531 QString NameHypothesis)
533 SMESH::SMESH_Hypothesis_var Hyp;
536 Hyp = myComponentMesh->CreateHypothesis(TypeHypothesis, myStudyId);
539 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewHypothesis(Hyp);
540 myStudyAPI.SetName(SHyp, NameHypothesis);
543 catch(const SALOME::SALOME_Exception & S_ex)
545 QtCatchCorbaException(S_ex);
548 return SMESH::SMESH_Hypothesis::_narrow(Hyp);
551 //=============================================================================
555 //=============================================================================
556 void SMESHGUI::AddHypothesisOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
557 SMESH::SMESH_Hypothesis_ptr aHyp)
559 if (!aMesh->_is_nil())
561 QApplication::setOverrideCursor(Qt::waitCursor);
562 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
563 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
566 bool res = aMesh->AddHypothesis(aShape, aHyp);
569 SALOMEDS::SObject_var SH =
570 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
571 if (!SM->_is_nil() && !SH->_is_nil())
573 myStudyAPI.SetHypothesis(SM, SH);
574 myStudyAPI.ModifiedMesh(SM, false);
576 QApplication::restoreOverrideCursor();
580 QApplication::restoreOverrideCursor();
581 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
582 tr("SMESH_WRN_WARNING"),
583 tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
584 tr("SMESH_BUT_YES"));
587 catch(const SALOME::SALOME_Exception & S_ex)
589 QtCatchCorbaException(S_ex);
592 myActiveStudy->updateObjBrowser(true);
593 QApplication::restoreOverrideCursor();
596 //=============================================================================
600 //=============================================================================
602 RemoveHypothesisOrAlgorithmOnMesh(const Handle(SALOME_InteractiveObject) &
605 if (IObject->hasReference())
607 SMESH::SMESH_Hypothesis_var anHyp;
608 SALOMEDS::SObject_var SO_Hypothesis =
609 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
610 SALOMEDS::GenericAttribute_var anAttr;
611 SALOMEDS::AttributeIOR_var anIOR;
613 if (!SO_Hypothesis->_is_nil())
615 QApplication::setOverrideCursor(Qt::waitCursor);
616 if (SO_Hypothesis->FindAttribute(anAttr, "AttributeIOR"))
618 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
620 SMESH::SMESH_Hypothesis::_narrow(_orb->
621 string_to_object(anIOR->Value()));
624 SALOMEDS::SObject_var SO_Applied_Hypothesis =
625 smeshGUI->myStudy->FindObjectID(IObject->getReference());
626 if (!SO_Applied_Hypothesis->_is_nil())
628 SALOMEDS::SObject_var MorSM =
629 smeshGUI->myStudyAPI.
630 GetMeshOrSubmesh(SO_Applied_Hypothesis);
631 if (!MorSM->_is_nil())
633 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
635 GEOM::GEOM_Shape_var aShape =
636 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
637 if (!aShape->_is_nil())
639 if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
641 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
642 SMESH::SMESH_Mesh_var aMesh =
643 SMESH::SMESH_Mesh::_narrow(_orb->
644 string_to_object(anIOR->Value()));
645 SMESH::SMESH_subMesh_var aSubMesh =
646 SMESH::SMESH_subMesh::_narrow(_orb->
647 string_to_object(anIOR->Value()));
648 if (!aMesh->_is_nil())
651 aMesh->RemoveHypothesis(aShape, anHyp);
654 QApplication::restoreOverrideCursor();
655 QAD_MessageBox::warn1(QAD_Application::
656 getDesktop(), tr("SMESH_WRN_WARNING"),
657 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
658 tr("SMESH_BUT_YES"));
661 else if (!aSubMesh->_is_nil())
663 aMesh = aSubMesh->GetFather();
664 if (!aMesh->_is_nil())
667 aMesh->RemoveHypothesis(aShape, anHyp);
670 QApplication::restoreOverrideCursor();
671 QAD_MessageBox::warn1(QAD_Application::
673 tr("SMESH_WRN_WARNING"),
674 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
675 tr("SMESH_BUT_YES"));
679 if (myAutomaticUpdate)
681 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
689 smeshGUI->ChangeRepresentation(Mesh,
690 Mesh->getDisplayMode());
696 smeshGUI->myStudyAPI.UnSetHypothesis(SO_Applied_Hypothesis);
700 else if (IObject->hasEntry())
702 MESSAGE("IObject entry " << IObject->getEntry())}
703 QApplication::restoreOverrideCursor();
706 //=============================================================================
710 //=============================================================================
711 void SMESHGUI::RemoveHypothesisOrAlgorithmOnMesh(SALOMEDS::SObject_ptr MorSM,
712 SMESH::SMESH_Hypothesis_ptr anHyp)
714 SALOMEDS::SObject_var AHR, aRef;
715 SALOMEDS::GenericAttribute_var anAttr;
716 SALOMEDS::AttributeIOR_var anIOR;
718 if (!MorSM->_is_nil())
720 GEOM::GEOM_Shape_var aShape =
721 smeshGUI->myStudyAPI.GetShapeOnMeshOrSubMesh(MorSM);
722 if (!aShape->_is_nil())
724 if (MorSM->FindAttribute(anAttr, "AttributeIOR"))
726 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
727 SMESH::SMESH_Mesh_var aMesh =
728 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
730 SMESH::SMESH_subMesh_var aSubMesh =
731 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
733 if (!aMesh->_is_nil())
735 bool res = aMesh->RemoveHypothesis(aShape, anHyp);
738 QApplication::restoreOverrideCursor();
739 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
740 tr("SMESH_WRN_WARNING"),
741 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
742 tr("SMESH_BUT_YES"));
745 else if (!aSubMesh->_is_nil())
747 aMesh = aSubMesh->GetFather();
748 if (!aMesh->_is_nil())
750 bool res = aMesh->RemoveHypothesis(aShape, anHyp);
753 QApplication::restoreOverrideCursor();
754 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
755 tr("SMESH_WRN_WARNING"),
756 tr("SMESH_WRN_HYPOTHESIS_NOTEXIST"),
757 tr("SMESH_BUT_YES"));
761 if (myAutomaticUpdate)
763 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
771 // smeshGUI->ChangeRepresentation( Mesh, Mesh->getDisplayMode() );
777 if (MorSM->FindSubObject(2, AHR))
779 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
780 for (; it->More(); it->Next())
782 SALOMEDS::SObject_var Obj = it->Value();
783 if (Obj->ReferencedObject(aRef))
785 if (aRef->FindAttribute(anAttr, "AttributeIOR"))
787 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
788 if (strcmp(anIOR->Value(),
789 _orb->object_to_string(anHyp)) == 0)
791 smeshGUI->myStudyAPI.UnSetHypothesis(Obj);
798 if (MorSM->FindSubObject(3, AHR))
800 SALOMEDS::ChildIterator_var it = myStudy->NewChildIterator(AHR);
801 for (; it->More(); it->Next())
803 SALOMEDS::SObject_var Obj = it->Value();
804 if (Obj->ReferencedObject(aRef))
806 if (aRef->FindAttribute(anAttr, "AttributeIOR"))
808 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
809 if (strcmp(anIOR->Value(),
810 _orb->object_to_string(anHyp)) == 0)
812 smeshGUI->myStudyAPI.UnSetAlgorithm(Obj);
819 smeshGUI->myStudyAPI.ModifiedMesh(MorSM, false);
821 QApplication::restoreOverrideCursor();
824 //=============================================================================
828 //=============================================================================
829 void SMESHGUI::AddAlgorithmOnMesh(SMESH::SMESH_Mesh_ptr aMesh,
830 SMESH::SMESH_Hypothesis_ptr aHyp)
832 if (!aMesh->_is_nil())
834 QApplication::setOverrideCursor(Qt::waitCursor);
835 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
836 GEOM::GEOM_Shape_var aShape = myStudyAPI.GetShapeOnMeshOrSubMesh(SM);
839 bool res = aMesh->AddHypothesis(aShape, aHyp);
842 SALOMEDS::SObject_var SH =
843 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
844 if (!SM->_is_nil() && !SH->_is_nil())
846 myStudyAPI.SetAlgorithms(SM, SH);
847 myStudyAPI.ModifiedMesh(SM, false);
852 QApplication::restoreOverrideCursor();
853 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
854 tr("SMESH_WRN_WARNING"),
855 tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
856 tr("SMESH_BUT_YES"));
859 catch(const SALOME::SALOME_Exception & S_ex)
861 QtCatchCorbaException(S_ex);
864 myActiveStudy->updateObjBrowser(true);
865 QApplication::restoreOverrideCursor();
868 //=============================================================================
872 //=============================================================================
873 void SMESHGUI::AddHypothesisOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
874 SMESH::SMESH_Hypothesis_ptr aHyp)
876 if (!aSubMesh->_is_nil())
878 QApplication::setOverrideCursor(Qt::waitCursor);
881 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
882 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
883 GEOM::GEOM_Shape_var aShape =
884 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
885 if (!aMesh->_is_nil())
887 bool res = aMesh->AddHypothesis(aShape, aHyp);
890 SALOMEDS::SObject_var SH =
891 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
892 if (!SsubM->_is_nil() && !SH->_is_nil())
894 myStudyAPI.SetHypothesis(SsubM, SH);
895 myStudyAPI.ModifiedMesh(SsubM, false);
900 QApplication::restoreOverrideCursor();
901 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
902 tr("SMESH_WRN_WARNING"),
903 tr("SMESH_WRN_HYPOTHESIS_ALREADYEXIST"),
904 tr("SMESH_BUT_YES"));
908 catch(const SALOME::SALOME_Exception & S_ex)
910 QtCatchCorbaException(S_ex);
913 myActiveStudy->updateObjBrowser(true);
914 QApplication::restoreOverrideCursor();
917 //=============================================================================
921 //=============================================================================
922 void SMESHGUI::AddAlgorithmOnSubMesh(SMESH::SMESH_subMesh_ptr aSubMesh,
923 SMESH::SMESH_Hypothesis_ptr aHyp)
925 if (!aSubMesh->_is_nil())
927 QApplication::setOverrideCursor(Qt::waitCursor);
930 SMESH::SMESH_Mesh_var aMesh = aSubMesh->GetFather();
931 SALOMEDS::SObject_var SsubM = myStudyAPI.FindSubMesh(aSubMesh);
932 GEOM::GEOM_Shape_var aShape =
933 myStudyAPI.GetShapeOnMeshOrSubMesh(SsubM);
934 if (!aMesh->_is_nil())
936 bool res = aMesh->AddHypothesis(aShape, aHyp);
939 SALOMEDS::SObject_var SH =
940 myStudyAPI.FindHypothesisOrAlgorithms(aHyp);
941 if (!SsubM->_is_nil() && !SH->_is_nil())
943 myStudyAPI.SetAlgorithms(SsubM, SH);
944 myStudyAPI.ModifiedMesh(SsubM, false);
949 QApplication::restoreOverrideCursor();
950 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
951 tr("SMESH_WRN_WARNING"),
952 tr("SMESH_WRN_ALGORITHM_ALREADYEXIST"),
953 tr("SMESH_BUT_YES"));
957 catch(const SALOME::SALOME_Exception & S_ex)
959 QtCatchCorbaException(S_ex);
962 myActiveStudy->updateObjBrowser(true);
963 QApplication::restoreOverrideCursor();
966 //=============================================================================
970 //=============================================================================
971 void SMESHGUI::CreateAlgorithm(QString TypeAlgo, QString NameAlgo)
973 SMESH::SMESH_Hypothesis_var Hyp;
976 if (TypeAlgo.compare("Regular_1D") == 0)
977 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
978 else if (TypeAlgo.compare("MEFISTO_2D") == 0)
979 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
980 else if (TypeAlgo.compare("Quadrangle_2D") == 0)
981 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
982 else if (TypeAlgo.compare("Hexa_3D") == 0)
983 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
984 else if (TypeAlgo.compare("NETGEN_3D") == 0)
985 Hyp = myComponentMesh->CreateHypothesis(TypeAlgo, myStudyId);
989 SALOMEDS::SObject_var SHyp = myStudyAPI.AddNewAlgorithms(Hyp);
990 myStudyAPI.SetName(SHyp, NameAlgo);
993 catch(const SALOME::SALOME_Exception & S_ex)
995 QtCatchCorbaException(S_ex);
997 myActiveStudy->updateObjBrowser(true);
1000 //=============================================================================
1004 //=============================================================================
1005 void SMESHGUI::CreateLocalLength(QString TypeHypothesis, QString NameHypothesis,
1008 QApplication::setOverrideCursor(Qt::waitCursor);
1011 SMESH::SMESH_Hypothesis_var Hyp =
1012 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1014 SMESH::SMESH_LocalLength_var LL =
1015 SMESH::SMESH_LocalLength::_narrow(Hyp);
1017 LL->SetLength(Length);
1019 catch(const SALOME::SALOME_Exception & S_ex)
1021 QtCatchCorbaException(S_ex);
1023 myActiveStudy->updateObjBrowser(true);
1024 QApplication::restoreOverrideCursor();
1027 //=============================================================================
1031 //=============================================================================
1032 void SMESHGUI::CreateMaxElementArea(QString TypeHypothesis,
1033 QString NameHypothesis, double MaxArea)
1035 QApplication::setOverrideCursor(Qt::waitCursor);
1038 SMESH::SMESH_Hypothesis_var Hyp =
1039 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1041 SMESH::SMESH_MaxElementArea_var MaxElArea =
1042 SMESH::SMESH_MaxElementArea::_narrow(Hyp);
1043 if (!MaxElArea->_is_nil())
1044 MaxElArea->SetMaxElementArea(MaxArea);
1046 catch(SALOME::SALOME_Exception & S_ex)
1048 QtCatchCorbaException(S_ex);
1051 myActiveStudy->updateObjBrowser(true);
1052 QApplication::restoreOverrideCursor();
1055 //=============================================================================
1059 //=============================================================================
1060 void SMESHGUI::CreateMaxElementVolume(QString TypeHypothesis,
1061 QString NameHypothesis, double MaxVolume)
1063 QApplication::setOverrideCursor(Qt::waitCursor);
1066 SMESH::SMESH_Hypothesis_var Hyp =
1067 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1069 SMESH::SMESH_MaxElementVolume_var MaxElVolume =
1070 SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
1071 if (!MaxElVolume->_is_nil())
1072 MaxElVolume->SetMaxElementVolume(MaxVolume);
1074 catch(const SALOME::SALOME_Exception & S_ex)
1076 QtCatchCorbaException(S_ex);
1078 myActiveStudy->updateObjBrowser(true);
1079 QApplication::restoreOverrideCursor();
1082 //=============================================================================
1086 //=============================================================================
1087 void SMESHGUI::CreateNbSegments(QString TypeHypothesis, QString NameHypothesis,
1090 QApplication::setOverrideCursor(Qt::waitCursor);
1093 SMESH::SMESH_Hypothesis_var Hyp =
1094 SMESH::SMESH_Hypothesis::_narrow(CreateHypothesis(TypeHypothesis,
1096 SMESH::SMESH_NumberOfSegments_var NbS =
1097 SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
1098 if (!NbS->_is_nil())
1099 NbS->SetNumberOfSegments(nbSegments);
1101 catch(const SALOME::SALOME_Exception & S_ex)
1103 QtCatchCorbaException(S_ex);
1105 myActiveStudy->updateObjBrowser(true);
1106 QApplication::restoreOverrideCursor();
1109 //=============================================================================
1113 //=============================================================================
1114 int SMESHGUI::GetNameOfSelectedIObjects(SALOME_Selection * Sel, QString & aName)
1116 int nbSel = Sel->IObjectCount();
1119 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1120 aName = IObject->getName();
1124 aName = tr("SMESH_OBJECTS_SELECTED").arg(nbSel);
1129 //=============================================================================
1133 //=============================================================================
1134 int SMESHGUI::GetNameOfSelectedNodes(SALOME_Selection * Sel, QString & aName)
1137 int nbSel = Sel->IObjectCount();
1140 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1141 if (!IObject->hasEntry())
1144 Standard_Boolean res;
1145 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1149 TColStd_MapOfInteger MapIndex;
1150 Sel->GetIndex(IObject, MapIndex);
1151 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1153 nbNodes = MapIndex.Extent();
1154 for (; ite.More(); ite.Next())
1157 aName + QString("%1").arg(ac->GetIdSMESHDSNode(ite.Key())) +
1168 //=============================================================================
1172 //=============================================================================
1173 int SMESHGUI::GetNameOfSelectedElements(SALOME_Selection * Sel, QString & aName)
1176 int nbSel = Sel->IObjectCount();
1179 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1180 if (!IObject->hasEntry())
1183 Standard_Boolean res;
1184 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1188 TColStd_MapOfInteger MapIndex;
1189 Sel->GetIndex(IObject, MapIndex);
1190 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1192 nbElements = MapIndex.Extent();
1193 MESSAGE("GetNameOfSelectedElements(): number = " << nbElements);
1194 for (; ite.More(); ite.Next())
1196 int idVTK = ite.Key();
1197 MESSAGE("GetNameOfSelectedElements(): VTK Id = " << idVTK);
1199 aName + QString("%1").arg(ac->GetIdSMESHDSElement(idVTK)) + " ";
1209 //=============================================================================
1213 //=============================================================================
1214 int SMESHGUI::GetNameOfSelectedEdges(SALOME_Selection * Sel, QString & aName)
1217 int nbSel = Sel->IObjectCount();
1220 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
1221 if (!IObject->hasEntry())
1224 Standard_Boolean res;
1225 SMESH_Actor *ac = FindActorByEntry(IObject->getEntry(), res, true);
1229 TColStd_MapOfInteger MapIndex;
1230 Sel->GetIndex(IObject, MapIndex);
1231 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
1233 nbElements = MapIndex.Extent();
1234 for (; ite.More(); ite.Next())
1236 aName = aName + QString("%1").arg(ite.Key()) + " ";
1246 //=============================================================================
1250 //=============================================================================
1251 SMESH_Actor *SMESHGUI::FindActorByEntry(QString entry,
1252 Standard_Boolean & testResult, bool onlyInActiveView)
1254 int nbSf = myActiveStudy->getStudyFramesCount();
1255 for (int i = 0; i < nbSf; i++)
1257 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
1258 if (sf->getTypeView() == VIEW_VTK)
1260 vtkRenderer *Renderer =
1261 ((VTKViewer_ViewFrame *) sf->getRightFrame()->getViewFrame())->
1263 vtkActorCollection *theActors = Renderer->GetActors();
1264 theActors->InitTraversal();
1265 vtkActor *ac = theActors->GetNextActor();
1266 while (!(ac == NULL))
1268 if (ac->IsA("SMESH_Actor"))
1270 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
1271 if (anActor->hasIO())
1273 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
1274 if (strcmp(IO->getEntry(), entry) == 0)
1276 if (onlyInActiveView)
1278 if (sf == myActiveStudy->getActiveStudyFrame())
1292 ac = theActors->GetNextActor();
1297 MESSAGE(" Actor Not Found ") testResult = false;
1298 return SMESH_Actor::New();
1301 //=============================================================================
1305 //=============================================================================
1306 SMESH_Actor *SMESHGUI::FindActor(SMESH::SMESH_Mesh_ptr aMesh,
1307 Standard_Boolean & testResult, bool onlyInActiveView)
1309 SALOMEDS::SObject_var SM = myStudyAPI.FindMesh(aMesh);
1312 MESSAGE(" Actor Not Found ") testResult = false;
1313 return SMESH_Actor::New();
1316 return FindActorByEntry(SM->GetID(), testResult, onlyInActiveView);
1319 //=============================================================================
1323 //=============================================================================
1324 SMESH::SMESH_Mesh_ptr SMESHGUI::
1325 ConvertIOinMesh(const Handle(SALOME_InteractiveObject) & IO,
1326 Standard_Boolean & testResult)
1328 SMESH::SMESH_Mesh_var aMesh;
1334 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1335 SALOMEDS::GenericAttribute_var anAttr;
1336 SALOMEDS::AttributeIOR_var anIOR;
1337 if (!obj->_is_nil())
1339 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1341 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1343 SMESH::SMESH_Mesh::_narrow(_orb->string_to_object(anIOR->
1345 if (!aMesh->_is_nil())
1348 return SMESH::SMESH_Mesh::_duplicate(aMesh);
1353 return SMESH::SMESH_Mesh::_nil();
1356 //=============================================================================
1360 //=============================================================================
1361 SMESH::SMESH_subMesh_ptr SMESHGUI::
1362 ConvertIOinSubMesh(const Handle(SALOME_InteractiveObject) & IO,
1363 Standard_Boolean & testResult)
1365 SMESH::SMESH_subMesh_var aSubMesh;
1371 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1372 SALOMEDS::GenericAttribute_var anAttr;
1373 SALOMEDS::AttributeIOR_var anIOR;
1374 if (!obj->_is_nil())
1376 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1378 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1380 SMESH::SMESH_subMesh::_narrow(_orb->string_to_object(anIOR->
1382 if (!aSubMesh->_is_nil())
1385 return SMESH::SMESH_subMesh::_duplicate(aSubMesh);
1390 return SMESH::SMESH_subMesh::_nil();
1393 //=============================================================================
1397 //=============================================================================
1398 SMESH::SMESH_Hypothesis_ptr SMESHGUI::
1399 ConvertIOinSMESHHypothesis(const Handle(SALOME_InteractiveObject) & IO,
1400 Standard_Boolean & testResult)
1402 SMESH::SMESH_Hypothesis_var aHyp;
1408 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1409 SALOMEDS::GenericAttribute_var anAttr;
1410 SALOMEDS::AttributeIOR_var anIOR;
1411 if (!obj->_is_nil())
1413 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1415 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1417 SMESH::SMESH_Hypothesis::_narrow(_orb->
1418 string_to_object(anIOR->Value()));
1419 if (!aHyp->_is_nil())
1422 return SMESH::SMESH_Hypothesis::_duplicate(aHyp);
1427 return SMESH::SMESH_Hypothesis::_nil();
1430 //=============================================================================
1434 //=============================================================================
1435 GEOM::GEOM_Shape_ptr SMESHGUI::
1436 ConvertIOinGEOMShape(const Handle(SALOME_InteractiveObject) & IO,
1437 Standard_Boolean & testResult)
1439 GEOM::GEOM_Shape_var aShape;
1445 SALOMEDS::SObject_var obj = myStudy->FindObjectID(IO->getEntry());
1446 SALOMEDS::GenericAttribute_var anAttr;
1447 SALOMEDS::AttributeIOR_var anIOR;
1448 if (!obj->_is_nil())
1450 if (obj->FindAttribute(anAttr, "AttributeIOR"))
1452 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
1453 aShape = myComponentGeom->GetIORFromString(anIOR->Value());
1454 if (!aShape->_is_nil())
1457 return GEOM::GEOM_Shape::_duplicate(aShape);
1462 return GEOM::GEOM_Shape::_nil();
1465 //=============================================================================
1469 //=============================================================================
1470 void SMESHGUI::SetViewMode(int commandId)
1472 SALOME_Selection *Sel =
1473 SALOME_Selection::Selection(myActiveStudy->getSelection());
1474 int nbSel = Sel->IObjectCount();
1477 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
1478 for (; It.More(); It.Next())
1480 Handle(SALOME_InteractiveObject) IObject = It.Value();
1481 if (IObject->hasEntry())
1483 Standard_Boolean res;
1485 FindActorByEntry(IObject->getEntry(), res, true);
1492 ChangeRepresentation(ac, 0);
1497 ChangeRepresentation(ac, 1);
1502 ChangeRepresentation(ac, 2);
1507 ChangeRepresentation(ac, 3);
1514 if (commandId == 1133)
1516 ChangeRepresentation(SMESH_Actor::New(), 4);
1521 //=============================================================================
1525 //=============================================================================
1526 void SMESHGUI::ChangeRepresentation(SMESH_Actor * ac, int type)
1528 if (ac->DataSource == NULL && type != 4)
1533 if (ac->getMapper() == NULL)
1542 QApplication::setOverrideCursor(Qt::waitCursor);
1543 if (ac->getDisplayMode() == 2)
1545 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1546 vtkDataSetMapper *meshMapper =
1547 (vtkDataSetMapper *) (ac->getMapper());
1548 meshMapper->SetInput(ac->DataSource);
1549 meshMapper->SetScalarVisibility(isColored); //SAL3899
1551 ac->setDisplayMode(0);
1552 ac->GetProperty()->SetRepresentationToWireframe();
1553 // ac->SetActorProperty( ac->GetProperty() );
1554 QApplication::restoreOverrideCursor();
1559 QApplication::setOverrideCursor(Qt::waitCursor);
1560 if (ac->getDisplayMode() == 2)
1562 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1563 vtkDataSetMapper *meshMapper =
1564 (vtkDataSetMapper *) (ac->getMapper());
1565 meshMapper->SetInput(ac->DataSource);
1566 meshMapper->SetScalarVisibility(isColored); //SAL3899
1568 ac->setDisplayMode(1);
1569 ac->GetProperty()->SetRepresentationToSurface();
1570 QApplication::restoreOverrideCursor();
1571 // ac->SetActorProperty( ac->GetProperty() );
1576 // if (!(ac->getDisplayMode()==2)) {
1577 // ChangeRepresentation(ac, 1);
1578 QApplication::setOverrideCursor(Qt::waitCursor);
1579 ac->setDisplayMode(2);
1580 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1581 vtkDataSetMapper *meshMapper = (vtkDataSetMapper *) (ac->getMapper());
1582 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1583 shrink->SetInput(ac->DataSource);
1584 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1586 meshMapper->SetInput(shrink->GetOutput());
1587 meshMapper->SetScalarVisibility(isColored); //SAL3899
1588 ac->SetMapper(meshMapper);
1589 QApplication::restoreOverrideCursor();
1597 float backfacecolor[3];
1599 ac->GetColor(color[0], color[1], color[2]);
1600 // QColor c(color[0]*255,color[1]*255,color[2]*255);
1601 int c0 = int (color[0] * 255);
1602 int c1 = int (color[1] * 255);
1603 int c2 = int (color[2] * 255);
1604 QColor c(c0, c1, c2);
1605 ac->GetEdgeColor(edgecolor[0], edgecolor[1], edgecolor[2]);
1606 // QColor e(edgecolor[0]*255,edgecolor[1]*255,edgecolor[2]*255);
1607 c0 = int (edgecolor[0] * 255);
1608 c1 = int (edgecolor[1] * 255);
1609 c2 = int (edgecolor[2] * 255);
1610 QColor e(c0, c1, c2);
1611 ac->GetBackfaceProperty()->GetColor(backfacecolor);
1612 // QColor b(backfacecolor[0]*255,backfacecolor[1]*255,backfacecolor[2]*255);
1613 c0 = int (backfacecolor[0] * 255);
1614 c1 = int (backfacecolor[1] * 255);
1615 c2 = int (backfacecolor[2] * 255);
1616 QColor b(c0, c1, c2);
1617 ac->GetNodeColor(nodecolor[0], nodecolor[1], nodecolor[2]);
1618 // QColor n(nodecolor[0]*255, nodecolor[1]*255, nodecolor[2]*255 ) ;
1619 c0 = int (nodecolor[0] * 255);
1620 c1 = int (nodecolor[1] * 255);
1621 c2 = int (nodecolor[2] * 255);
1622 QColor n(c0, c1, c2);
1624 int Edgewidth = (int)ac->EdgeDevice->GetProperty()->GetLineWidth();
1627 int intValue = ac->GetNodeSize();
1628 float Shrink = ac->GetShrinkFactor();
1630 SMESHGUI_Preferences_ColorDlg *aDlg =
1631 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(),
1633 aDlg->SetColor(1, c);
1634 aDlg->SetColor(2, e);
1635 aDlg->SetColor(3, n);
1636 aDlg->SetColor(4, b);
1637 aDlg->SetIntValue(1, Edgewidth);
1638 aDlg->SetIntValue(2, intValue);
1639 aDlg->SetIntValue(3, int (Shrink * 100.));
1643 QApplication::setOverrideCursor(Qt::waitCursor);
1644 QColor color = aDlg->GetColor(1);
1645 QColor edgecolor = aDlg->GetColor(2);
1646 QColor nodecolor = aDlg->GetColor(3);
1647 QColor backfacecolor = aDlg->GetColor(4);
1648 /* actor color and backface color */
1649 ac->GetProperty()->SetColor(float (color.red()) / 255.,
1650 float (color.green()) / 255., float (color.blue()) / 255.);
1651 ac->SetColor(float (color.red()) / 255.,
1652 float (color.green()) / 255., float (color.blue()) / 255.);
1653 ac->GetBackfaceProperty()->SetColor(float (backfacecolor.red()) /
1654 255., float (backfacecolor.green()) / 255.,
1655 float (backfacecolor.blue()) / 255.);
1658 ac->EdgeDevice->GetProperty()->SetColor(float (edgecolor.red()) /
1659 255., float (edgecolor.green()) / 255.,
1660 float (edgecolor.blue()) / 255.);
1661 ac->EdgeShrinkDevice->GetProperty()->SetColor(float (edgecolor.
1662 red()) / 255., float (edgecolor.green()) / 255.,
1663 float (edgecolor.blue()) / 255.);
1664 ac->SetEdgeColor(float (edgecolor.red()) / 255.,
1665 float (edgecolor.green()) / 255.,
1666 float (edgecolor.blue()) / 255.);
1668 /* Shrink factor and size edges */
1669 ac->SetShrinkFactor(aDlg->GetIntValue(3) / 100.);
1670 ac->EdgeDevice->GetProperty()->SetLineWidth(aDlg->GetIntValue(1));
1671 ac->EdgeShrinkDevice->GetProperty()->SetLineWidth(aDlg->
1674 /* Nodes color and size */
1675 ac->SetNodeColor(float (nodecolor.red()) / 255.,
1676 float (nodecolor.green()) / 255.,
1677 float (nodecolor.blue()) / 255.);
1678 ac->SetNodeSize(aDlg->GetIntValue(2));
1680 if (ac->getDisplayMode() == 2)
1682 bool isColored = ac->getMapper()->GetScalarVisibility(); //SAL3899
1683 vtkDataSetMapper *meshMapper =
1684 (vtkDataSetMapper *) (ac->getMapper());
1685 meshMapper->SetInput(ac->DataSource);
1686 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
1687 shrink->SetInput(meshMapper->GetInput());
1688 shrink->SetShrinkFactor(ac->GetShrinkFactor());
1690 meshMapper->SetInput(shrink->GetOutput());
1691 meshMapper->SetScalarVisibility(isColored); //SAL3899
1692 ac->SetMapper(meshMapper);
1696 QApplication::restoreOverrideCursor();
1701 EmitSignalDeactivateDialog();
1702 SALOME_Selection *Sel =
1703 SALOME_Selection::Selection(myActiveStudy->getSelection());
1704 SMESHGUI_TransparencyDlg *aDlg =
1705 new SMESHGUI_TransparencyDlg(QAD_Application::getDesktop(), "",
1711 QApplication::setOverrideCursor(Qt::waitCursor);
1712 ac->GetProperty()->SetRepresentationToPoints();
1713 QApplication::restoreOverrideCursor();
1718 QApplication::setOverrideCursor(Qt::waitCursor);
1719 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
1721 vtkRenderer *theRenderer =
1722 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1723 getRightFrame()->getViewFrame())->getRenderer();
1724 theRenderer->Render();
1726 QApplication::restoreOverrideCursor();
1729 //=============================================================================
1733 //=============================================================================
1734 void SMESHGUI::UpdateView()
1736 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1739 vtkRenderer *theRenderer =
1740 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1741 getRightFrame()->getViewFrame())->getRenderer();
1742 theRenderer->Render();
1745 //=============================================================================
1749 //=============================================================================
1750 void SMESHGUI::DisplayActor(SMESH_Actor * ac, bool visibility)
1752 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1755 MESSAGE("DisplayActor(): DataSource = " << ac->DataSource);
1757 vtkRenderer *theRenderer =
1758 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1759 getRightFrame()->getViewFrame())->getRenderer();
1760 vtkActorCollection *theActors = theRenderer->GetActors();
1761 theActors->InitTraversal();
1762 if (theActors->IsItemPresent(ac) == 0)
1764 vtkProperty *prop = vtkProperty::New();
1765 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1767 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1769 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1772 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
1774 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
1776 ac->SetProperty(prop);
1777 ac->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed").
1779 QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen").toFloat() /
1781 QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue").toFloat() /
1784 // prop->BackfaceCullingOn();
1785 vtkProperty *backprop = vtkProperty::New();
1786 backprop->SetColor(QAD_CONFIG->
1787 getSetting("SMESH:SettingsBackFaceColorRed").toFloat() / 255.,
1788 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen").
1790 QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue").
1792 ac->SetBackfaceProperty(backprop);
1795 QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff").toInt();
1798 ac->SetShrinkFactor(intValue / 100.);
1800 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
1801 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
1803 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
1804 if (DisplayMode.compare("Wireframe") == 0)
1806 ac->setDisplayMode(0);
1807 ChangeRepresentation(ac, 0);
1809 else if (DisplayMode.compare("Shading") == 0)
1811 ac->setDisplayMode(1);
1812 ChangeRepresentation(ac, 1);
1814 else if (DisplayMode.compare("Shrink") == 0)
1816 ac->setDisplayMode(2);
1817 ChangeRepresentation(ac, 2);
1819 theRenderer->AddActor(ac);
1823 if (ac->GetMapper())
1824 ac->GetMapper()->Update();
1827 // if ( visibility )
1828 ac->SetVisibility(visibility);
1829 // ac->VisibilityOn();
1831 // ac->VisibilityOff();
1833 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
1837 //=============================================================================
1841 //=============================================================================
1842 void SMESHGUI::EraseActor(SMESH_Actor * ac)
1844 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
1847 vtkRenderer *theRenderer =
1848 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
1849 getRightFrame()->getViewFrame())->getRenderer();
1851 //NRI- : 02/12/2002 : Fixed bugId 882
1852 // ac->EdgeDevice->VisibilityOff();
1853 // ac->EdgeShrinkDevice->VisibilityOff();
1854 // ac->VisibilityOff();
1855 ac->SetVisibility(false);
1857 theRenderer->Render();
1860 //=============================================================================
1864 //=============================================================================
1865 bool SMESHGUI::AddActorInSelection(SMESH_Actor * ac)
1867 SALOME_Selection *Sel =
1868 SALOME_Selection::Selection(myActiveStudy->getSelection());
1869 Sel->ClearIObjects();
1871 return Sel->AddIObject(ac->getIO());
1876 //=============================================================================
1880 //=============================================================================
1881 QString SMESHGUI::CheckHomogeneousSelection()
1883 SALOME_Selection *Sel =
1884 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1887 SALOME_ListIteratorOfListIO Itinit(Sel->StoredIObjects());
1888 for (; Itinit.More(); Itinit.Next())
1890 List.Append(Itinit.Value());
1893 QString RefType = CheckTypeObject(Sel->firstIObject());
1894 SALOME_ListIteratorOfListIO It(List);
1895 for (; It.More(); It.Next())
1897 Handle(SALOME_InteractiveObject) IObject = It.Value();
1898 QString Type = CheckTypeObject(IObject);
1899 if (Type.compare(RefType) != 0)
1900 return "Heterogeneous Selection";
1903 Sel->ClearIObjects();
1904 SALOME_ListIteratorOfListIO It1(List);
1905 for (; It1.More(); It1.Next())
1907 int res = Sel->AddIObject(It1.Value());
1909 myActiveStudy->highlight(It1.Value(), false);
1911 myActiveStudy->highlight(It1.Value(), true);
1916 //=============================================================================
1920 //=============================================================================
1921 QString SMESHGUI::CheckTypeObject(const Handle(SALOME_InteractiveObject) & IO)
1923 SALOMEDS::SObject_var sobj =
1924 smeshGUI->myActiveStudy->getStudyDocument()->FindObjectID(IO->
1926 if (!sobj->_is_nil())
1928 SALOMEDS::SComponent_var scomp = sobj->GetFatherComponent();
1929 if (strcmp(scomp->GetID(), IO->getEntry()) == 0)
1930 { // component is selected
1935 SALOME_Selection *Sel =
1936 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
1937 Sel->ClearIObjects();
1939 Handle(SMESH_TypeFilter) aHypFilter = new SMESH_TypeFilter(HYPOTHESIS);
1940 Handle(SMESH_TypeFilter) anAlgoFilter = new SMESH_TypeFilter(ALGORITHM);
1941 Handle(SMESH_TypeFilter) aMeshFilter = new SMESH_TypeFilter(MESH);
1942 Handle(SMESH_TypeFilter) aSubMeshFilter = new SMESH_TypeFilter(SUBMESH);
1943 Handle(SMESH_TypeFilter) aMeshOrSubMeshFilter =
1944 new SMESH_TypeFilter(MESHorSUBMESH);
1945 Handle(SMESH_TypeFilter) aSubMeshVextexFilter =
1946 new SMESH_TypeFilter(SUBMESH_VERTEX);
1947 Handle(SMESH_TypeFilter) aSubMeshEdgeFilter =
1948 new SMESH_TypeFilter(SUBMESH_EDGE);
1949 Handle(SMESH_TypeFilter) aSubMeshFaceFilter =
1950 new SMESH_TypeFilter(SUBMESH_FACE);
1951 Handle(SMESH_TypeFilter) aSubMeshSolidFilter =
1952 new SMESH_TypeFilter(SUBMESH_SOLID);
1953 Handle(SMESH_TypeFilter) aSubMeshCompoundFilter =
1954 new SMESH_TypeFilter(SUBMESH_COMPOUND);
1956 Sel->AddFilter(aHypFilter);
1957 if (Sel->AddIObject(IO) != -1)
1959 Sel->ClearFilters();
1960 return "Hypothesis";
1963 Sel->ClearFilters();
1964 Sel->AddFilter(anAlgoFilter);
1965 if (Sel->AddIObject(IO) != -1)
1967 Sel->ClearFilters();
1971 Sel->ClearFilters();
1972 Sel->AddFilter(aMeshFilter);
1973 if (Sel->AddIObject(IO) != -1)
1975 Sel->ClearFilters();
1979 Sel->ClearFilters();
1980 Sel->AddFilter(aSubMeshFilter);
1981 if (Sel->AddIObject(IO) != -1)
1983 Sel->ClearFilters();
1987 Sel->ClearFilters();
1988 Sel->AddFilter(aSubMeshVextexFilter);
1989 if (Sel->AddIObject(IO) != -1)
1991 Sel->ClearFilters();
1992 return "SubMeshVertex";
1995 Sel->ClearFilters();
1996 Sel->AddFilter(aSubMeshEdgeFilter);
1997 if (Sel->AddIObject(IO) != -1)
1999 Sel->ClearFilters();
2000 return "SubMeshEdge";
2003 Sel->ClearFilters();
2004 Sel->AddFilter(aSubMeshFaceFilter);
2005 if (Sel->AddIObject(IO) != -1)
2007 Sel->ClearFilters();
2008 return "SubMeshFace";
2011 Sel->ClearFilters();
2012 Sel->AddFilter(aSubMeshSolidFilter);
2013 if (Sel->AddIObject(IO) != -1)
2015 Sel->ClearFilters();
2016 return "SubMeshSolid";
2019 Sel->ClearFilters();
2020 Sel->AddFilter(aSubMeshCompoundFilter);
2021 if (Sel->AddIObject(IO) != -1)
2023 Sel->ClearFilters();
2024 return "SubMeshCompound";
2027 Sel->ClearFilters();
2028 Sel->AddIObject(IO);
2032 //=============================================================================
2036 //=============================================================================
2037 bool SMESHGUI::OnGUIEvent(int theCommandID, QAD_Desktop * parent)
2039 /* Create or retrieve an object SMESHGUI */
2040 SMESHGUI::GetOrCreateSMESHGUI(parent);
2042 // NRI : Temporary added
2043 if (smeshGUI->myStudy->GetProperties()->IsLocked())
2049 // QAD_Viewer3d* v3d;
2050 OCCViewer_Viewer3d *v3d;
2052 Handle(AIS_InteractiveContext) ic;
2053 vtkRenderer *Renderer;
2054 vtkRenderWindow *RenWin;
2056 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2060 ((OCCViewer_ViewFrame *) smeshGUI->myActiveStudy->
2061 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2063 ic = v3d->getAISContext();
2065 else if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2069 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2070 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2072 RenWin = Renderer->GetRenderWindow();
2075 switch (theCommandID)
2078 smeshGUI->OnEditDelete();
2085 smeshGUI->Import_Document(parent, theCommandID);
2089 case 122: // EXPORT MED
2093 Export_Mesh(parent, theCommandID);
2097 case 200: // SCALAR BAR
2099 smeshGUI->DisplayScalarBar(false);
2104 SMESHGUI_EditScalarBarDlg *aDlg =
2105 new SMESHGUI_EditScalarBarDlg(parent, "", false);
2111 smeshGUI->DisplayScalarBar(true);
2115 case 1133: // DISPLAY MODE : WireFrame, Surface, Shrink
2121 smeshGUI->SetViewMode(theCommandID);
2133 SALOME_Selection *Sel =
2134 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2136 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2140 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2141 for (; It.More(); It.Next())
2143 Handle(SALOME_InteractiveObject) IOS = It.Value();
2144 if (IOS->hasEntry())
2146 Standard_Boolean res;
2148 smeshGUI->FindActorByEntry(IOS->getEntry(), res, true);
2150 smeshGUI->EraseActor(ac);
2154 Sel->ClearIObjects();
2155 smeshGUI->myActiveStudy->updateObjBrowser(true);
2158 case 301: // DISPLAY
2160 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2164 QApplication::setOverrideCursor(Qt::waitCursor);
2165 SALOMEDS::SObject_var fatherSF =
2166 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2167 getActiveStudyFrame()->entry());
2169 SALOME_Selection *Sel =
2170 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2172 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2174 for (; It.More(); It.Next())
2176 Handle(SALOME_InteractiveObject) IObject = It.Value();
2177 if (IObject->hasEntry())
2179 Standard_Boolean res;
2181 smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2185 smeshGUI->DisplayActor(ac, true);
2186 smeshGUI->DisplayEdges(ac);
2187 smeshGUI->ChangeRepresentation(ac,
2188 ac->getDisplayMode());
2192 QApplication::restoreOverrideCursor();
2197 case 302: // DISPLAY ONLY
2199 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2202 QApplication::setOverrideCursor(Qt::waitCursor);
2203 vtkActorCollection *theActors = Renderer->GetActors();
2204 theActors->InitTraversal();
2205 vtkActor *ac = theActors->GetNextActor();
2206 while (!(ac == NULL))
2208 if (ac->IsA("SMESH_Actor"))
2210 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
2211 if (!anActor->isHighlighted())
2213 //anActor->VisibilityOff();
2214 //NRI- : 02/12/2002 : Fixed bugId 882
2215 // anActor->EdgeDevice->VisibilityOff();
2216 // anActor->EdgeShrinkDevice->VisibilityOff();
2217 anActor->SetVisibility(false);
2220 ac = theActors->GetNextActor();
2223 // Display selection
2224 SALOMEDS::SObject_var fatherSF =
2225 smeshGUI->myStudy->FindObjectID(smeshGUI->myActiveStudy->
2226 getActiveStudyFrame()->entry());
2228 SALOME_Selection *Sel =
2229 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2231 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2233 for (; It.More(); It.Next())
2235 Handle(SALOME_InteractiveObject) IObject = It.Value();
2236 SALOMEDS::SObject_var obj =
2237 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2239 VTKViewer_RenderWindowInteractor *myRenderInter =
2240 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2241 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2243 // vtkQGLRenderWindowInteractor* myRenderInter= smeshGUI->myActiveStudy->getActiveStudyFrame()->getRightFrame()->getVTKView()->getRWInteractor();
2245 if (myRenderInter->isInViewer(IObject))
2247 if (IObject->hasEntry())
2249 Standard_Boolean res;
2251 smeshGUI->FindActorByEntry(IObject->getEntry(), res,
2255 smeshGUI->DisplayActor(ac, true);
2256 smeshGUI->DisplayEdges(ac);
2257 smeshGUI->ChangeRepresentation(ac,
2258 ac->getDisplayMode());
2263 smeshGUI->myActiveStudy->updateObjBrowser(true);
2264 QApplication::restoreOverrideCursor();
2271 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2274 smeshGUI->EmitSignalDeactivateDialog();
2275 SALOME_Selection *Sel =
2276 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2278 Sel->ClearIObjects();
2279 smeshGUI->myDesktop->SetSelectionMode(1, true);
2280 parent->menuBar()->setItemChecked(9010, false);
2281 parent->menuBar()->setItemChecked(9011, false);
2282 smeshGUI->ViewNodes();
2283 SMESHGUI_NodesDlg *aDlg = new SMESHGUI_NodesDlg(parent, "", Sel);
2287 QApplication::restoreOverrideCursor();
2288 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2289 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2290 tr("SMESH_BUT_YES"));
2295 case 405: // MOVE NODE
2297 smeshGUI->myDesktop->SetSelectionMode(1, true);
2298 SALOME_Selection *Sel =
2299 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2301 SMESHGUI_MoveNodesDlg *aDlg =
2302 new SMESHGUI_MoveNodesDlg(parent, "", Sel);
2306 case 701: // COMPUTE MESH
2308 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2311 SALOME_Selection *Sel =
2312 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2314 int nbSel = Sel->IObjectCount();
2317 QApplication::restoreOverrideCursor();
2321 SMESH::SMESH_Mesh_var aM;
2322 SMESH::SMESH_subMesh_var aSubM;
2323 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
2324 if (IObject->hasEntry())
2326 SALOMEDS::SObject_var aMorSM =
2327 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2328 SALOMEDS::GenericAttribute_var anAttr;
2329 SALOMEDS::AttributeIOR_var anIOR;
2330 if (!aMorSM->_is_nil())
2332 if (aMorSM->FindAttribute(anAttr, "AttributeIOR"))
2334 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
2335 MESSAGE("SMESHGUI::OnGUIEvent - Compute mesh : IOR = "
2336 << anIOR->Value())CORBA::Object_var cobj;
2339 cobj = _orb->string_to_object(anIOR->Value());
2340 if (CORBA::is_nil(cobj))
2343 ("SMESHGUI::OnGUIEvent - Compute mesh : nil object")}
2345 catch(CORBA::COMM_FAILURE & ex)
2348 ("SMESHGUI::OnGUIEvent - Compute mesh : exception (1)")}
2349 aM = SMESH::SMESH_Mesh::_narrow(cobj);
2350 //aM = SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()) );
2352 SMESH::SMESH_subMesh::_narrow(_orb->
2353 string_to_object(anIOR->Value()));
2356 GEOM::GEOM_Shape_var refShape =
2357 smeshGUI->myStudyAPI.
2358 GetShapeOnMeshOrSubMesh(aMorSM);
2359 if (!refShape->_is_nil())
2362 smeshGUI->myComponentMesh->
2363 IsReadyToCompute(aM, refShape);
2366 QApplication::restoreOverrideCursor();
2367 QAD_MessageBox::warn1(QAD_Application::
2368 getDesktop(), tr("SMESH_WRN_WARNING"),
2369 tr("SMESH_WRN_MISSING_PARAMETERS"),
2370 tr("SMESH_BUT_YES"));
2375 smeshGUI->myComponentMesh->Compute(aM,
2377 smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2379 // TO Do : change icon of all submeshes
2381 catch(const SALOME::SALOME_Exception & S_ex)
2383 QtCatchCorbaException(S_ex);
2387 else if (!aSubM->_is_nil())
2389 aM = aSubM->GetFather();
2390 GEOM::GEOM_Shape_var refShape =
2391 smeshGUI->myStudyAPI.
2392 GetShapeOnMeshOrSubMesh(aMorSM);
2393 if (!refShape->_is_nil())
2396 smeshGUI->myComponentMesh->
2397 IsReadyToCompute(aM, refShape);
2400 QApplication::restoreOverrideCursor();
2401 QAD_MessageBox::warn1(QAD_Application::
2402 getDesktop(), tr("SMESH_WRN_WARNING"),
2403 tr("SMESH_WRN_MISSING_PARAMETERS"),
2404 tr("SMESH_BUT_YES"));
2409 smeshGUI->myComponentMesh->Compute(aM,
2411 smeshGUI->myStudyAPI.ModifiedMesh(aMorSM,
2413 // TO Do : change icon of all submeshes
2415 catch(const SALOME::SALOME_Exception & S_ex)
2417 QtCatchCorbaException(S_ex);
2425 // Check whether the actor for the mesh exists at least in one view
2426 Standard_Boolean res;
2428 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
2430 smeshGUI->InitActor(aM);
2433 // Check whether the actor belongs to the active view
2434 VTKViewer_RenderWindowInteractor *rwInter =
2435 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
2436 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
2439 // The actor belongs to inactive view -> create a copy and add it in the active view
2440 if (!rwInter->isInViewer(IObject))
2442 SMESH_Actor *acCopy = SMESH_Actor::New();
2443 acCopy->ShallowCopy(ac);
2445 smeshGUI->DisplayActor(acCopy, false);
2449 if (smeshGUI->myAutomaticUpdate)
2451 SMESH_Actor *Mesh = smeshGUI->ReadScript(aM);
2457 smeshGUI->DisplayActor(Mesh, true);
2458 smeshGUI->DisplayEdges(Mesh, true);
2459 smeshGUI->ChangeRepresentation(Mesh,
2460 Mesh->getDisplayMode());
2466 QApplication::restoreOverrideCursor();
2467 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2468 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2469 tr("SMESH_BUT_YES"));
2471 QApplication::restoreOverrideCursor();
2475 case 702: // ADD SUB MESH
2477 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2480 smeshGUI->EmitSignalDeactivateDialog();
2481 SALOME_Selection *Sel =
2482 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2484 SMESHGUI_AddSubMeshDlg *aDlg =
2485 new SMESHGUI_AddSubMeshDlg(parent, "", Sel);
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"));
2497 case 703: // INIT MESH
2499 smeshGUI->EmitSignalDeactivateDialog();
2500 SALOME_Selection *Sel =
2501 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2503 SMESHGUI_InitMeshDlg *aDlg = new SMESHGUI_InitMeshDlg(parent, "", Sel);
2507 case 704: // EDIT Hypothesis
2509 smeshGUI->EmitSignalDeactivateDialog();
2510 SALOME_Selection *Sel =
2511 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2513 SMESHGUI_EditHypothesesDlg *aDlg =
2514 new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2518 case 705: // EDIT Global Hypothesis
2520 smeshGUI->EmitSignalDeactivateDialog();
2521 SALOME_Selection *Sel =
2522 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2524 SMESHGUI_EditHypothesesDlg *aDlg =
2525 new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2529 case 706: // EDIT Local Hypothesis
2531 smeshGUI->EmitSignalDeactivateDialog();
2532 SALOME_Selection *Sel =
2533 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2535 SMESHGUI_EditHypothesesDlg *aDlg =
2536 new SMESHGUI_EditHypothesesDlg(parent, "", Sel);
2540 case 806: // ORIENTATION ELEMENTS
2542 smeshGUI->EmitSignalDeactivateDialog();
2543 SALOME_Selection *Sel =
2544 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2546 smeshGUI->myDesktop->SetSelectionMode(3, true);
2547 SMESHGUI_OrientationElementsDlg *aDlg =
2548 new SMESHGUI_OrientationElementsDlg(parent, "", Sel);
2552 case 807: // DIAGONAL INVERSION
2554 smeshGUI->EmitSignalDeactivateDialog();
2555 SALOME_Selection *Sel =
2556 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2558 Sel->ClearIObjects();
2559 smeshGUI->myDesktop->SetSelectionMode(2, true);
2560 SMESHGUI_DiagonalInversionDlg *aDlg =
2561 new SMESHGUI_DiagonalInversionDlg(parent, "", Sel);
2565 case 900: // MESH INFOS
2567 smeshGUI->EmitSignalDeactivateDialog();
2568 SALOME_Selection *Sel =
2569 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2571 SMESHGUI_MeshInfosDlg *aDlg =
2572 new SMESHGUI_MeshInfosDlg(parent, "", Sel);
2576 case 1001: // AUTOMATIC UPDATE PREFERENCES
2578 parent->menuBar()->setItemChecked(1001,
2579 !parent->menuBar()->isItemChecked(1001));
2580 if (parent->menuBar()->isItemChecked(1001))
2582 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "true");
2583 smeshGUI->myAutomaticUpdate = true;
2587 QAD_CONFIG->addSetting("SMESH:AutomaticUpdate", "false");
2588 smeshGUI->myAutomaticUpdate = false;
2593 case 1003: // MESH PREFERENCES
2595 smeshGUI->SetDisplaySettings();
2601 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
2602 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
2603 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
2604 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
2605 QString Orientation = QAD_CONFIG->getSetting("ScalarBar:Orientation");
2606 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
2607 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
2608 int NumberOfLabels =
2609 QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
2610 int NumberOfColors =
2611 QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
2617 if (NumberOfLabels == 0)
2619 if (NumberOfColors == 0)
2620 NumberOfColors = 64;
2622 SMESHGUI_Preferences_ScalarBarDlg *aDlg =
2623 new SMESHGUI_Preferences_ScalarBarDlg(parent, "", true);
2625 if (Bold.compare("true") == 0)
2626 aDlg->Bold->setChecked(true);
2628 aDlg->Bold->setChecked(false);
2629 if (Italic.compare("true") == 0)
2630 aDlg->Italic->setChecked(true);
2632 aDlg->Italic->setChecked(false);
2633 if (Shadow.compare("true") == 0)
2634 aDlg->Shadow->setChecked(true);
2636 aDlg->Shadow->setChecked(false);
2638 if (Orientation.compare("Horizontal") == 0)
2639 aDlg->RadioHoriz->setChecked(true);
2641 aDlg->RadioVert->setChecked(true);
2643 int NbItems = aDlg->ComboBox1->count();
2645 aDlg->ComboBox1->setCurrentItem(i);
2648 if (FontFamily.compare(aDlg->ComboBox1->text(i)) == 0)
2649 aDlg->ComboBox1->setCurrentItem(i);
2653 aDlg->LineEditWidth->setText(QString("%1").arg(Width));
2654 aDlg->LineEditHeight->setText(QString("%1").arg(Height));
2656 aDlg->SpinBoxLabels->setValue(NumberOfLabels);
2657 aDlg->SpinBoxColors->setValue(NumberOfColors);
2662 if (aDlg->RadioHoriz->isChecked())
2663 Orientation = "Horizontal";
2665 Orientation = "Vertical";
2666 if (aDlg->Bold->isChecked())
2670 if (aDlg->Italic->isChecked())
2674 if (aDlg->Shadow->isChecked())
2679 FontFamily = aDlg->ComboBox1->currentText();
2680 Width = aDlg->LineEditWidth->text().toFloat();
2681 Height = aDlg->LineEditHeight->text().toFloat();
2682 NumberOfColors = aDlg->SpinBoxColors->text().toInt();
2683 NumberOfLabels = aDlg->SpinBoxLabels->text().toInt();
2685 vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
2686 if (aScalarBar != NULL)
2688 smeshGUI->SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow,
2689 FontFamily, Orientation,
2690 Width, Height, NumberOfColors, NumberOfLabels);
2693 QAD_CONFIG->addSetting("ScalarBar:Bold", Bold);
2694 QAD_CONFIG->addSetting("ScalarBar:Italic", Italic);
2695 QAD_CONFIG->addSetting("ScalarBar:Shadow", Shadow);
2696 QAD_CONFIG->addSetting("ScalarBar:FontFamily", FontFamily);
2697 QAD_CONFIG->addSetting("ScalarBar:Orientation", Orientation);
2698 QAD_CONFIG->addSetting("ScalarBar:Width", Width);
2699 QAD_CONFIG->addSetting("ScalarBar:Height", Height);
2700 QAD_CONFIG->addSetting("ScalarBar:NumberOfLabels", NumberOfLabels);
2701 QAD_CONFIG->addSetting("ScalarBar:NumberOfColors", NumberOfColors);
2706 case 1100: // EDIT HYPOTHESIS
2708 SALOME_Selection *Sel =
2709 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2711 int nbSel = Sel->IObjectCount();
2715 Standard_Boolean res;
2716 SMESH::SMESH_Hypothesis_var Hyp =
2717 smeshGUI->ConvertIOinSMESHHypothesis(Sel->firstIObject(), res);
2719 /* Look for all mesh objects that have this hupothesis affected in order to flag as ModifiedMesh */
2720 /* At end below '...->updateObjBrowser(true)' will change icon of mesh objects */
2721 /* Warning : however by internal mechanism all subMeshes icons are changed ! */
2722 SALOMEDS::Study::ListOfSObject_var listSOmesh =
2723 smeshGUI->GetMeshesUsingAlgoOrHypothesis(Hyp);
2727 QString Name = Hyp->GetName();
2729 if (Name.compare("LocalLength") == 0)
2731 SMESH::SMESH_LocalLength_var LL =
2732 SMESH::SMESH_LocalLength::_narrow(Hyp);
2733 double beforeLength = LL->GetLength();
2734 double Length = smeshGUI->Parameter(res,
2736 tr("SMESH_LOCAL_LENGTH_HYPOTHESIS"),
2739 if (res && Length != beforeLength)
2741 LL->SetLength(Length);
2742 for (int i = 0; i < listSOmesh->length(); i++)
2744 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2751 else if (Name.compare("NumberOfSegments") == 0)
2753 SMESH::SMESH_NumberOfSegments_var NOS =
2754 SMESH::SMESH_NumberOfSegments::_narrow(Hyp);
2755 int beforeNbSeg = NOS->GetNumberOfSegments();
2756 int NbSeg = smeshGUI->Parameter(res,
2758 tr("SMESH_NB_SEGMENTS_HYPOTHESIS"),
2762 if (res && NbSeg != beforeNbSeg)
2764 NOS->SetNumberOfSegments(NbSeg);
2765 for (int i = 0; i < listSOmesh->length(); i++)
2767 SALOMEDS::SObject_var SO = listSOmesh[i];
2768 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2775 else if (Name.compare("MaxElementArea") == 0)
2777 SMESH::SMESH_MaxElementArea_var MEA =
2778 SMESH::SMESH_MaxElementArea::_narrow(Hyp);
2779 double beforeMaxArea = MEA->GetMaxElementArea();
2780 double MaxArea = smeshGUI->Parameter(res,
2782 tr("SMESH_MAX_ELEMENT_AREA_HYPOTHESIS"),
2785 if (res && MaxArea != beforeMaxArea)
2787 MEA->SetMaxElementArea(MaxArea);
2788 for (int i = 0; i < listSOmesh->length(); i++)
2790 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2797 else if (Name.compare("MaxElementVolume") == 0)
2799 SMESH::SMESH_MaxElementVolume_var MEV =
2800 SMESH::SMESH_MaxElementVolume::_narrow(Hyp);
2801 double beforeMaxVolume = MEV->GetMaxElementVolume();
2802 double MaxVolume = smeshGUI->Parameter(res,
2804 tr("SMESH_MAX_ELEMENT_VOLUME_HYPOTHESIS"),
2807 if (res && MaxVolume != beforeMaxVolume)
2809 MEV->SetMaxElementVolume(MaxVolume);
2810 for (int i = 0; i < listSOmesh->length(); i++)
2812 smeshGUI->GetStudyAPI().ModifiedMesh(listSOmesh[i],
2819 else if (Name.compare("Regular_1D") == 0)
2822 else if (Name.compare("MEFISTO_2D") == 0)
2834 case 1101: // RENAME
2836 SALOME_Selection *Sel =
2837 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2839 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2840 for (; It.More(); It.Next())
2842 Handle(SALOME_InteractiveObject) IObject = It.Value();
2844 SALOMEDS::SObject_var obj =
2845 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
2846 SALOMEDS::GenericAttribute_var anAttr;
2847 SALOMEDS::AttributeName_var aName;
2848 if (!obj->_is_nil())
2850 if (obj->FindAttribute(anAttr, "AttributeName"))
2852 aName = SALOMEDS::AttributeName::_narrow(anAttr);
2853 QString newName = QString(aName->Value());
2855 SALOMEGUI_NameDlg::getName(QAD_Application::
2856 getDesktop(), newName);
2857 if (!newName.isEmpty())
2859 QApplication::setOverrideCursor(Qt::waitCursor);
2860 smeshGUI->myActiveStudy->renameIObject(IObject,
2863 QApplication::restoreOverrideCursor();
2870 case 1102: // REMOVE HYPOTHESIS / ALGORITHMS
2872 QApplication::setOverrideCursor(Qt::waitCursor);
2873 SALOME_Selection *Sel =
2874 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2876 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
2877 for (int i = 0; It.More(); It.Next(), i++)
2879 Handle(SALOME_InteractiveObject) IObject = It.Value();
2880 smeshGUI->RemoveHypothesisOrAlgorithmOnMesh(IObject);
2882 Sel->ClearIObjects();
2883 smeshGUI->myActiveStudy->updateObjBrowser(true);
2884 QApplication::restoreOverrideCursor();
2888 case 401: // GEOM::EDGE
2890 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2893 smeshGUI->EmitSignalDeactivateDialog();
2894 SALOME_Selection *Sel =
2895 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2897 Sel->ClearIObjects();
2898 smeshGUI->myDesktop->SetSelectionMode(1, true);
2899 parent->menuBar()->setItemChecked(9010, false);
2900 parent->menuBar()->setItemChecked(9011, false);
2901 smeshGUI->ViewNodes();
2902 SMESHGUI_AddEdgeDlg *aDlg =
2903 new SMESHGUI_AddEdgeDlg(parent, "", Sel);
2907 QApplication::restoreOverrideCursor();
2908 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2909 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2910 tr("SMESH_BUT_YES"));
2914 case 4021: // TRIANGLE
2916 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2919 smeshGUI->EmitSignalDeactivateDialog();
2920 SALOME_Selection *Sel =
2921 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2923 Sel->ClearIObjects();
2924 smeshGUI->myDesktop->SetSelectionMode(1, true);
2925 parent->menuBar()->setItemChecked(9010, false);
2926 parent->menuBar()->setItemChecked(9011, false);
2927 smeshGUI->ViewNodes();
2928 SMESHGUI_AddFaceDlg *aDlg =
2929 new SMESHGUI_AddFaceDlg(parent, "", Sel, 3);
2933 QApplication::restoreOverrideCursor();
2934 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2935 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2936 tr("SMESH_BUT_YES"));
2942 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2945 smeshGUI->EmitSignalDeactivateDialog();
2946 SALOME_Selection *Sel =
2947 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2949 Sel->ClearIObjects();
2950 smeshGUI->myDesktop->SetSelectionMode(1, true);
2951 parent->menuBar()->setItemChecked(9010, false);
2952 parent->menuBar()->setItemChecked(9011, false);
2953 smeshGUI->ViewNodes();
2954 SMESHGUI_AddFaceDlg *aDlg =
2955 new SMESHGUI_AddFaceDlg(parent, "", Sel, 4);
2959 QApplication::restoreOverrideCursor();
2960 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2961 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2962 tr("SMESH_BUT_YES"));
2968 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2971 smeshGUI->EmitSignalDeactivateDialog();
2972 SALOME_Selection *Sel =
2973 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
2975 Sel->ClearIObjects();
2976 smeshGUI->myDesktop->SetSelectionMode(1, true);
2977 parent->menuBar()->setItemChecked(9010, false);
2978 parent->menuBar()->setItemChecked(9011, false);
2979 smeshGUI->ViewNodes();
2980 SMESHGUI_AddVolumeDlg *aDlg =
2981 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 4);
2985 QApplication::restoreOverrideCursor();
2986 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
2987 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
2988 tr("SMESH_BUT_YES"));
2994 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
2997 smeshGUI->EmitSignalDeactivateDialog();
2998 SALOME_Selection *Sel =
2999 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3001 Sel->ClearIObjects();
3002 smeshGUI->myDesktop->SetSelectionMode(1, true);
3003 parent->menuBar()->setItemChecked(9010, false);
3004 parent->menuBar()->setItemChecked(9011, false);
3005 smeshGUI->ViewNodes();
3006 SMESHGUI_AddVolumeDlg *aDlg =
3007 new SMESHGUI_AddVolumeDlg(parent, "", Sel, 8);
3011 QApplication::restoreOverrideCursor();
3012 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3013 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3014 tr("SMESH_BUT_YES"));
3019 case 4041: // REMOVES NODES
3021 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3024 smeshGUI->EmitSignalDeactivateDialog();
3025 SALOME_Selection *Sel =
3026 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3028 Sel->ClearIObjects();
3029 smeshGUI->myDesktop->SetSelectionMode(1, true);
3030 parent->menuBar()->setItemChecked(9010, false);
3031 parent->menuBar()->setItemChecked(9011, false);
3032 smeshGUI->ViewNodes();
3033 SMESHGUI_RemoveNodesDlg *aDlg =
3034 new SMESHGUI_RemoveNodesDlg(parent, "", Sel);
3038 QApplication::restoreOverrideCursor();
3039 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3040 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3041 tr("SMESH_BUT_YES"));
3045 case 4042: // REMOVES ELEMENTS
3047 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3050 smeshGUI->EmitSignalDeactivateDialog();
3051 SALOME_Selection *Sel =
3052 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3054 Sel->ClearIObjects();
3055 smeshGUI->myDesktop->SetSelectionMode(3, true);
3056 SMESHGUI_RemoveElementsDlg *aDlg =
3057 new SMESHGUI_RemoveElementsDlg(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"));
3069 case 5000: // HYPOTHESIS - ALGO
3071 smeshGUI->CreateAlgorithm("Regular_1D", "Wire Discretisation");
3076 smeshGUI->CreateAlgorithm("MEFISTO_2D", "Triangle (Mefisto)");
3081 smeshGUI->CreateAlgorithm("Quadrangle_2D", "Quadrangle (Mapping)");
3086 smeshGUI->CreateAlgorithm("Hexa_3D", "Hexahedron (i,j,k)");
3091 smeshGUI->CreateAlgorithm("NETGEN_3D", "Tetrahedron (Netgen)");
3095 case 5030: // HYPOTHESIS - LOCAL LENGTH
3097 smeshGUI->EmitSignalDeactivateDialog();
3098 SALOME_Selection *Sel =
3099 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3101 SMESHGUI_LocalLengthDlg *aDlg = new SMESHGUI_LocalLengthDlg(parent, "");
3104 case 5031: // HYPOTHESIS - NB SEGMENTS
3106 smeshGUI->EmitSignalDeactivateDialog();
3107 SALOME_Selection *Sel =
3108 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3110 SMESHGUI_NbSegmentsDlg *aDlg = new SMESHGUI_NbSegmentsDlg(parent, "");
3114 case 5032: // HYPOTHESIS - MAX ELEMENT AREA
3116 smeshGUI->EmitSignalDeactivateDialog();
3117 SALOME_Selection *Sel =
3118 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3120 SMESHGUI_MaxElementAreaDlg *aDlg =
3121 new SMESHGUI_MaxElementAreaDlg(parent, "");
3125 case 5033: // HYPOTHESIS - MAX ELEMENT VOLUME
3127 smeshGUI->EmitSignalDeactivateDialog();
3128 SALOME_Selection *Sel =
3129 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3131 SMESHGUI_MaxElementVolumeDlg *aDlg =
3132 new SMESHGUI_MaxElementVolumeDlg(parent, "");
3136 case 5034: // HYPOTHESIS - LENGTH FROM EDGES
3138 SMESH::SMESH_Hypothesis_var Hyp;
3141 Hyp = smeshGUI->myComponentMesh->CreateHypothesis("LengthFromEdges", smeshGUI->myStudyId);
3143 if (!Hyp->_is_nil())
3145 SALOMEDS::SObject_var SHyp = smeshGUI->myStudyAPI.AddNewHypothesis(Hyp);
3146 smeshGUI->myStudyAPI.SetName(SHyp, "LengthFromEdges");
3149 catch(const SALOME::SALOME_Exception & S_ex)
3151 QtCatchCorbaException(S_ex);
3153 smeshGUI->myActiveStudy->updateObjBrowser(true);
3158 case 6016: // CONTROLS
3166 SALOME_Selection *Sel =
3167 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3169 int nbSel = Sel->IObjectCount();
3172 smeshGUI->Control(theCommandID);
3178 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3181 SALOME_Selection *Sel =
3182 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3184 SMESHGUI_EdgesConnectivityDlg *Dlg =
3185 new SMESHGUI_EdgesConnectivityDlg(parent, "", Sel);
3189 QApplication::restoreOverrideCursor();
3190 QAD_MessageBox::warn1(QAD_Application::getDesktop(),
3191 tr("SMESH_WRN_WARNING"), tr("SMESH_WRN_VIEWER_VTK"),
3192 tr("SMESH_BUT_YES"));
3199 if (!parent->menuBar()->isItemChecked(9010))
3201 QApplication::setOverrideCursor(Qt::waitCursor);
3202 parent->menuBar()->setItemChecked(9011, false);
3204 smeshGUI->EraseSimulationActors();
3205 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3207 SALOME_Selection *Sel =
3208 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3210 int nbSel = Sel->IObjectCount();
3213 Standard_Boolean res;
3214 SMESH_Actor *MeshActor =
3215 smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3219 parent->menuBar()->setItemChecked(9010,
3220 !parent->menuBar()->isItemChecked(9010));
3222 // It's necessary to display SMDS IDs instead of VTK ones, so
3223 // vtkIdFilter is unacceptable here. We have to do it manually :(
3224 vtkUnstructuredGrid *ptGrid = vtkUnstructuredGrid::New();
3225 ptGrid->CopyStructure(MeshActor->DataSource);
3227 int numPts = MeshActor->DataSource->GetNumberOfPoints();
3229 // Loop over points and generate ids
3230 vtkIntArray *ptIds = vtkIntArray::New();
3231 ptIds->SetNumberOfValues(numPts);
3233 for (int id = 0; id < numPts; id++)
3235 int idSMDS = MeshActor->GetIdSMESHDSNode(id);
3236 ptIds->SetValue(id, idSMDS);
3239 // mpv porting vtk4.2.2
3240 // vtkScalars* newScalars = vtkScalars::New();
3241 // newScalars->SetData(ptIds);
3242 // ptGrid->GetPointData()->SetScalars(newScalars);
3243 ptGrid->GetPointData()->SetScalars(ptIds);
3244 // newScalars->Delete();
3248 vtkMaskPoints *mask = vtkMaskPoints::New();
3249 mask->SetInput(ptGrid);
3250 mask->SetOnRatio(1);
3251 // mask->SetMaximumNumberOfPoints( 50 );
3252 // mask->RandomModeOn();
3254 vtkSelectVisiblePoints *visPts =
3255 vtkSelectVisiblePoints::New();
3256 visPts->SetInput(mask->GetOutput());
3257 visPts->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3258 myActiveStudy->getActiveStudyFrame()->
3259 getRightFrame()->getViewFrame())->getRenderer());
3260 //visPts->SetSelectInvisible(1);
3261 visPts->SelectInvisibleOff();
3262 visPts->SetTolerance(0.1);
3264 vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3265 ldm->SetInput(visPts->GetOutput());
3266 ldm->SetLabelFormat("%g");
3267 ldm->SetLabelModeToLabelScalars();
3268 //ldm->SetLabelModeToLabelFieldData();
3270 ldm->SetFontFamilyToTimes();
3271 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3276 vtkActor2D *pointLabels = vtkActor2D::New();
3277 pointLabels->SetMapper(ldm);
3278 pointLabels->GetProperty()->SetColor(0, 1, 0);
3282 smeshGUI->mySimulationActors2D->AddItem(pointLabels);
3283 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3284 getActiveStudyFrame()->getRightFrame()->
3285 getViewFrame())->getRenderer()->AddActor2D(pointLabels);
3291 QApplication::setOverrideCursor(Qt::waitCursor);
3292 parent->menuBar()->setItemChecked(9010,
3293 !parent->menuBar()->isItemChecked(9010));
3294 smeshGUI->EraseSimulationActors();
3295 smeshGUI->ScalarVisibilityOff();
3297 QApplication::restoreOverrideCursor();
3302 if (!parent->menuBar()->isItemChecked(9011))
3304 QApplication::setOverrideCursor(Qt::waitCursor);
3305 parent->menuBar()->setItemChecked(9010, false);
3307 smeshGUI->EraseSimulationActors();
3308 smeshGUI->mySimulationActors2D = vtkActor2DCollection::New();
3310 SALOME_Selection *Sel =
3311 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
3313 int nbSel = Sel->IObjectCount();
3316 Standard_Boolean res;
3317 SMESH_Actor *MeshActor =
3318 smeshGUI->FindActorByEntry(Sel->firstIObject()->getEntry(),
3322 parent->menuBar()->setItemChecked(9011,
3323 !parent->menuBar()->isItemChecked(9011));
3325 // It's necessary to display SMDS IDs instead of VTK ones, so
3326 // vtkIdFilter is unacceptable here. We have to do it manually :(
3327 vtkUnstructuredGrid *elGrid = vtkUnstructuredGrid::New();
3328 elGrid->CopyStructure(MeshActor->DataSource);
3330 int numCells = MeshActor->DataSource->GetNumberOfCells();
3332 // Loop over points and generate ids
3333 vtkIntArray *cellIds = vtkIntArray::New();
3334 cellIds->SetNumberOfValues(numCells);
3336 for (int id = 0; id < numCells; id++)
3338 int idSMDS = MeshActor->GetIdSMESHDSElement(id);
3339 cellIds->SetValue(id, idSMDS);
3342 // mpv porting vk4.2.2
3343 // vtkScalars* newScalars = vtkScalars::New();
3344 // newScalars->SetData(cellIds);
3345 elGrid->GetCellData()->SetScalars(cellIds);
3346 // elGrid->GetCellData()->SetScalars(newScalars);
3347 // newScalars->Delete();
3352 vtkCellCenters *cc = vtkCellCenters::New();
3353 cc->SetInput(elGrid);
3355 vtkSelectVisiblePoints *visCells =
3356 vtkSelectVisiblePoints::New();
3357 visCells->SetInput(cc->GetOutput());
3358 visCells->SetRenderer(((VTKViewer_ViewFrame *) smeshGUI->
3359 myActiveStudy->getActiveStudyFrame()->
3360 getRightFrame()->getViewFrame())->getRenderer());
3361 visCells->SelectInvisibleOff();
3362 visCells->SetTolerance(0.1);
3363 // visCells->SetSelectInvisible(1);
3365 vtkLabeledDataMapper *ldm = vtkLabeledDataMapper::New();
3366 ldm->SetInput(visCells->GetOutput());
3367 ldm->SetLabelFormat("%g");
3368 ldm->SetLabelModeToLabelScalars();
3370 ldm->SetFontFamilyToTimes();
3371 ldm->SetFontSize(6 * parent->font().pointSize() / 5);
3376 vtkActor2D *cellLabels = vtkActor2D::New();
3377 cellLabels->SetMapper(ldm);
3378 cellLabels->GetProperty()->SetColor(1, 0, 0);
3383 smeshGUI->mySimulationActors2D->AddItem(cellLabels);
3384 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
3385 getActiveStudyFrame()->getRightFrame()->
3386 getViewFrame())->getRenderer()->AddActor2D(cellLabels);
3392 QApplication::setOverrideCursor(Qt::waitCursor);
3393 parent->menuBar()->setItemChecked(9011,
3394 !parent->menuBar()->isItemChecked(9011));
3395 smeshGUI->EraseSimulationActors();
3396 smeshGUI->ScalarVisibilityOff();
3398 QApplication::restoreOverrideCursor();
3402 case 10001: // DISPLAY MODE PREFERENCE
3404 parent->menuBar()->setItemChecked(10001,
3405 !parent->menuBar()->isItemChecked(10001));
3406 parent->menuBar()->setItemChecked(10002, false);
3407 parent->menuBar()->setItemChecked(10003, false);
3408 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Wireframe");
3413 parent->menuBar()->setItemChecked(10002,
3414 !parent->menuBar()->isItemChecked(10002));
3415 parent->menuBar()->setItemChecked(10001, false);
3416 parent->menuBar()->setItemChecked(10003, false);
3417 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3422 parent->menuBar()->setItemChecked(10003,
3423 !parent->menuBar()->isItemChecked(10003));
3424 parent->menuBar()->setItemChecked(10002, false);
3425 parent->menuBar()->setItemChecked(10001, false);
3426 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shrink");
3432 smeshGUI->myActiveStudy->updateObjBrowser(true);
3436 //=============================================================================
3437 /*! function : GetMeshesUsingAlgoOrHypothesis()
3438 * purpose : return a list of Study objects (mesh kind) that have 'AlgoOrHyp' affected.
3439 * : However is supposed here that father of father of an hypothesis is a Mesh Object.
3441 //=============================================================================
3442 SALOMEDS::Study::ListOfSObject *
3443 SMESHGUI::GetMeshesUsingAlgoOrHypothesis(SMESH::
3444 SMESH_Hypothesis_ptr AlgoOrHyp)
3446 SALOMEDS::Study::ListOfSObject_var listSOmesh =
3447 new SALOMEDS::Study::ListOfSObject;
3448 listSOmesh->length(0);
3449 unsigned int index = 0;
3450 if (!AlgoOrHyp->_is_nil())
3452 SALOMEDS::SObject_var SO_Hypothesis =
3453 smeshGUI->GetStudyAPI().FindHypothesisOrAlgorithms(AlgoOrHyp);
3454 if (!SO_Hypothesis->_is_nil())
3456 SALOMEDS::Study::ListOfSObject_var listSO =
3457 smeshGUI->myStudy->FindDependances(SO_Hypothesis);
3458 for (unsigned int i = 0; i < listSO->length(); i++)
3460 SALOMEDS::SObject_var SO = listSO[i];
3463 SALOMEDS::SObject_var SOfatherFather =
3464 SO->GetFather()->GetFather();
3465 if (!SOfatherFather->_is_nil())
3468 listSOmesh->length(index);
3469 listSOmesh[index - 1] = SOfatherFather;
3475 return listSOmesh._retn();
3478 //=============================================================================
3482 //=============================================================================
3483 void SMESHGUI::Export_Mesh(QAD_Desktop * parent, int theCommandID)
3485 SALOME_Selection *Sel =
3486 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3487 int nbSel = Sel->IObjectCount();
3490 Standard_Boolean res;
3491 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3492 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(IObject, res);
3496 if (theCommandID == 122)
3498 QString filename = QAD_FileDlg::getFileName(parent,
3500 tr("MED files (*.med)"),
3503 if (!filename.isEmpty())
3505 QApplication::setOverrideCursor(Qt::waitCursor);
3506 aMesh->Export(filename.latin1(), "MED");
3507 QApplication::restoreOverrideCursor();
3510 else if (theCommandID == 121)
3512 QString filename = QAD_FileDlg::getFileName(parent,
3514 tr("DAT files (*.dat)"),
3517 if (!filename.isEmpty())
3519 QApplication::setOverrideCursor(Qt::waitCursor);
3520 aMesh->Export(filename.latin1(), "DAT");
3521 QApplication::restoreOverrideCursor();
3524 else if (theCommandID == 123)
3526 QString filename = QAD_FileDlg::getFileName(parent,
3528 tr("IDEAS files (*.unv)"),
3531 if (!filename.isEmpty())
3533 QApplication::setOverrideCursor(Qt::waitCursor);
3534 aMesh->Export(filename.latin1(), "UNV");
3535 QApplication::restoreOverrideCursor();
3539 aMesh->Export(filename.latin1(), "DAT");
3541 if (IObject->hasEntry())
3544 SALOMEDS::SObject_var SO =
3545 smeshGUI->myStudy->FindObjectID(IObject->getEntry());
3546 SALOMEDS::GenericAttribute_var anAttr;
3547 SALOMEDS::AttributeComment_var aFileName;
3549 SALOMEDS::StudyBuilder_var aStudyBuilder =
3550 smeshGUI->myStudy->NewBuilder();
3553 aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
3554 aFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
3555 aFileName->SetValue(filename.latin1());
3557 // Add a MEDFILE attribute to make selection in Efficas
3558 if (theCommandID == 122)
3560 QString medfilename="FICHIERMED"+filename;
3561 anAttr = aStudyBuilder->FindOrCreateAttribute(SO, "AttributeComment");
3562 SALOMEDS::AttributeComment_var MEDFileName;
3563 MEDFileName = SALOMEDS::AttributeComment::_narrow(anAttr);
3564 MEDFileName->SetValue(medfilename.latin1());
3568 QApplication::restoreOverrideCursor();
3573 //=============================================================================
3577 //=============================================================================
3578 void SMESHGUI::Import_Document(QAD_Desktop * parent, int theCommandID)
3583 if (theCommandID == 113)
3585 filter = tr("MED files (*.med)");
3586 myExtension = string("MED");
3588 else if (theCommandID == 112)
3590 filter = tr("IDEAS files (*.unv)");
3591 myExtension = string("UNV");
3593 else if (theCommandID == 111)
3595 filter = tr("DAT files (*.dat)");
3596 myExtension = string("DAT");
3599 QString filename = QAD_FileDlg::getFileName(parent, "", filter,
3600 tr("Import document"), true);
3602 if (!filename.isEmpty())
3604 QApplication::setOverrideCursor(Qt::waitCursor);
3607 if (!myComponentMesh->_is_nil())
3609 SMESH::SMESH_Mesh_var aMesh =
3610 myComponentMesh->Import(myStudyId, filename.latin1(),
3611 myExtension.c_str());
3613 if (!aMesh->_is_nil())
3615 SALOMEDS::SObject_var SM = myStudyAPI.AddNewMesh(aMesh);
3616 myStudyAPI.SetName(SM, filename);
3620 catch(const SALOME::SALOME_Exception & S_ex)
3622 QtCatchCorbaException(S_ex);
3624 myActiveStudy->updateObjBrowser(true);
3625 QApplication::restoreOverrideCursor();
3629 //=============================================================================
3633 //=============================================================================
3634 bool SMESHGUI::OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
3635 QAD_StudyFrame * studyFrame)
3637 SMESHGUI::GetOrCreateSMESHGUI(parent);
3641 //=============================================================================
3645 //=============================================================================
3646 bool SMESHGUI::OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
3647 QAD_StudyFrame * studyFrame)
3649 SMESHGUI::GetOrCreateSMESHGUI(parent);
3654 //=============================================================================
3658 //=============================================================================
3659 bool SMESHGUI::OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
3660 QAD_StudyFrame * studyFrame)
3662 SMESHGUI::GetOrCreateSMESHGUI(parent);
3667 //=============================================================================
3671 //=============================================================================
3672 bool SMESHGUI::SetSettings(QAD_Desktop * parent)
3674 SMESHGUI::GetOrCreateSMESHGUI(parent);
3677 QString DisplayMode = QAD_CONFIG->getSetting("SMESH:DisplayMode");
3678 if (DisplayMode.compare("") == 0)
3680 DisplayMode = "Shading";
3681 QAD_CONFIG->addSetting("SMESH:DisplayMode", "Shading");
3684 if (DisplayMode.compare("Wireframe") == 0)
3686 parent->menuBar()->setItemChecked(10003, false);
3687 parent->menuBar()->setItemChecked(10002, false);
3688 parent->menuBar()->setItemChecked(10001, true);
3690 else if (DisplayMode.compare("Shading") == 0)
3692 parent->menuBar()->setItemChecked(10003, false);
3693 parent->menuBar()->setItemChecked(10002, true);
3694 parent->menuBar()->setItemChecked(10001, false);
3696 else if (DisplayMode.compare("Shrink") == 0)
3698 parent->menuBar()->setItemChecked(10003, true);
3699 parent->menuBar()->setItemChecked(10002, false);
3700 parent->menuBar()->setItemChecked(10001, false);
3703 /* Automatic Update */
3704 QString AutoUpdate = QAD_CONFIG->getSetting("SMESH:AutomaticUpdate");
3705 if (AutoUpdate.compare("true") == 0)
3707 parent->menuBar()->setItemChecked(1001, true);
3708 smeshGUI->myAutomaticUpdate = true;
3712 parent->menuBar()->setItemChecked(1001, false);
3713 smeshGUI->myAutomaticUpdate = false;
3719 //=============================================================================
3723 //=============================================================================
3724 void SMESHGUI::DefinePopup(QString & theContext, QString & theParent,
3725 QString & theObject)
3727 /* Create or retrieve an object SMESHGUI */
3728 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
3730 // NRI : Temporary added
3731 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3732 // theObject = "NothingSelected";
3733 // theContext = "NothingSelected";
3737 SALOME_Selection *Sel =
3738 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3739 int nbSel = Sel->IObjectCount();
3742 if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() ==
3745 vtkScalarBarActor *aScalarBar = smeshGUI->GetScalarBar();
3746 if ((aScalarBar != NULL) && (aScalarBar->GetVisibility() == 1))
3748 theObject = "ScalarBar";
3753 theObject = "NothingSelected";
3754 theContext = "NothingSelected";
3759 theObject = "NothingSelected";
3760 theContext = "NothingSelected";
3763 else if (nbSel == 1)
3765 theObject = smeshGUI->CheckTypeObject(Sel->firstIObject());
3770 theObject = smeshGUI->CheckHomogeneousSelection();
3775 //=============================================================================
3779 //=============================================================================
3780 bool SMESHGUI::CustomPopup(QAD_Desktop * parent,
3782 const QString & theContext,
3783 const QString & theParent, const QString & theObject)
3785 // Popup should be customized for any viewer since some meaningless commands may be present in the popup
3786 //if (smeshGUI->myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK) //Test du type de viewer true=OCC false=VTK
3788 /* Create or retrieve an object SMESHGUI */
3789 SMESHGUI::GetOrCreateSMESHGUI(parent);
3791 // NRI : Temporary added
3792 // if ( smeshGUI->myStudy->GetProperties()->IsLocked() ) {
3797 SALOME_Selection *Sel =
3798 SALOME_Selection::Selection(smeshGUI->myActiveStudy->getSelection());
3799 QAD_StudyFrame *studyFrame = smeshGUI->myActiveStudy->getActiveStudyFrame();
3800 int nbSel = Sel->IObjectCount();
3804 if (studyFrame->getTypeView() != VIEW_VTK)
3808 else if (nbSel == 1)
3810 QString parentComp =
3811 ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3812 // First check type of active viewer (VTK required)
3813 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3814 parent->getActiveComponent())
3816 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3819 int id = popup->idAt(0);
3820 if (id <= QAD_TopLabel_Popup_ID)
3821 popup->removeItemAt(0);
3825 if (theObject.compare("Component") == 0)
3827 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3832 // Remove common popup items for Submesh, Hypothesis and Algorithm
3833 if (theObject.compare("SubMesh") == 0 ||
3834 theObject.compare("Hypothesis") == 0 ||
3835 theObject.compare("Algorithm") == 0)
3837 popup->removeItem(QAD_Display_Popup_ID);
3838 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3839 popup->removeItem(QAD_Erase_Popup_ID);
3840 int id = popup->idAt(popup->count() - 1); // last item
3841 if (id < 0 && id != -1)
3842 popup->removeItem(id); // separator
3845 if (theObject.compare("Component") == 0)
3847 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3851 int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3852 QFont f = QApplication::font();
3855 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
3857 if (theParent.compare("Viewer") == 0)
3859 if (popup->idAt(0) == id)
3861 popup->removeItem(id);
3862 popup->insertItem(new CustomItem(QString(IObject->getName()),
3866 Standard_Boolean res;
3868 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3869 if (res && studyFrame->getTypeView() == VIEW_VTK)
3871 VTKViewer_RenderWindowInteractor *myRenderInter =
3872 ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3873 getViewFrame())->getRWInteractor();
3874 if (myRenderInter->isVisible(IObject))
3876 popup->removeItem(QAD_Display_Popup_ID);
3880 popup->removeItem(QAD_Erase_Popup_ID);
3885 popup->removeItem(QAD_Erase_Popup_ID);
3887 { // mesh not computed -> can't display it
3888 popup->removeItem(QAD_Display_Popup_ID);
3889 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3890 popup->removeItemAt(popup->count() - 1); //separator
3894 else if (theParent.compare("ObjectBrowser") == 0)
3896 if (theObject.compare("Mesh") == 0 ||
3897 theObject.compare("SubMesh") == 0 ||
3898 theObject.compare("Hypothesis") == 0 ||
3899 theObject.compare("Algorithm") == 0)
3901 popup->removeItemAt(0);
3905 if (popup->idAt(0) == id)
3907 popup->removeItem(id);
3908 popup->removeItemAt(0); //separator
3912 Standard_Boolean res;
3914 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
3915 if (res && studyFrame->getTypeView() == VIEW_VTK)
3917 VTKViewer_RenderWindowInteractor *myRenderInter =
3918 ((VTKViewer_ViewFrame *) studyFrame->getRightFrame()->
3919 getViewFrame())->getRWInteractor();
3920 if (myRenderInter->isVisible(IObject))
3922 popup->removeItem(QAD_Display_Popup_ID);
3926 popup->removeItem(QAD_Erase_Popup_ID);
3931 if (theObject.compare("Mesh") == 0 ||
3932 theObject.compare("SubMesh") == 0 ||
3933 theObject.compare("Hypothesis") == 0 ||
3934 theObject.compare("Algorithm") == 0)
3939 popup->removeItem(QAD_Erase_Popup_ID);
3941 { // mesh not computed -> can't display it
3942 popup->removeItem(QAD_Display_Popup_ID);
3943 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3944 popup->removeItemAt(popup->count() - 1); //separator
3952 QString parentComp =
3953 ((SALOMEGUI_Desktop *) parent)->getComponentFromSelection();
3954 QAD_StudyFrame *studyFrame =
3955 smeshGUI->myActiveStudy->getActiveStudyFrame();
3956 if ( /*studyFrame->getTypeView() != VIEW_VTK || */ parentComp !=
3957 parent->getActiveComponent())
3959 //MESSAGE("CustomPopup(): VTK viewer required, removing all SMESH-specific popup menu items")
3962 int id = popup->idAt(0);
3963 if (id <= QAD_TopLabel_Popup_ID && id != -1)
3964 popup->removeItemAt(0);
3968 if (parentComp.isNull())
3969 { // objects from several components are selected
3970 popup->removeItem(QAD_DisplayOnly_Popup_ID);
3971 popup->removeItem(QAD_Display_Popup_ID);
3972 popup->removeItem(QAD_Erase_Popup_ID);
3973 int id = popup->idAt(popup->count() - 1); // last item
3974 if (id < 0 && id != -1)
3975 popup->removeItem(id); // separator
3980 QString type = smeshGUI->CheckHomogeneousSelection();
3981 if (type.compare("Heterogeneous Selection") != 0)
3983 int id = QAD_TopLabel_Popup_ID; //popup->idAt(0);
3984 QFont f = QApplication::font();
3986 popup->removeItem(id);
3987 popup->insertItem(new CustomItem(QString("%1 ").arg(nbSel) + type +
3988 " (s) ", f), id, 0);
3995 * Ensures that the actor for the given <theIO> exists in the active VTK view
3996 * @TODO Handle multiple selection.
3998 void SMESHGUI::BuildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
4000 MESSAGE("SMESHGUI::BuildPresentation("<<theIO->getEntry()<<")");
4001 /* Create or retrieve an object SMESHGUI */
4002 SMESHGUI::GetOrCreateSMESHGUI(QAD_Application::getDesktop());
4004 QAD_StudyFrame *activeFrame =
4005 smeshGUI->myActiveStudy->getActiveStudyFrame();
4006 if (activeFrame->getTypeView() == VIEW_VTK)
4009 // Some ideas to handle multiple selection...
4010 /*SALOMEDS::SObject_var fatherSF =
4011 smeshGUI->myStudy->FindObjectID(activeFrame->entry());
4013 SALOME_Selection *Sel =
4014 SALOME_Selection::Selection(smeshGUI->myActiveStudy->
4016 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
4018 for(;It.More();It.Next()) {
4019 Handle(SALOME_InteractiveObject) IObject = It.Value();*/
4020 Handle(SALOME_InteractiveObject) IObject = theIO;
4021 if (IObject->hasEntry())
4023 // Look for the actor in all views
4024 Standard_Boolean res;
4026 smeshGUI->FindActorByEntry(IObject->getEntry(), res, false);
4030 SALOMEDS::SObject_var aMorSM=smeshGUI->myStudy->FindObjectID( IObject->getEntry());
4031 SALOMEDS::GenericAttribute_var anAttr;
4032 SALOMEDS::AttributeIOR_var anIOR;
4033 if(aMorSM->FindAttribute(anAttr, "AttributeIOR"))
4035 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
4036 SMESH::SMESH_Mesh_var aM =
4037 SMESH::SMESH_Mesh::_narrow( _orb->string_to_object(anIOR->Value()));
4040 smeshGUI->InitActor(aM);
4041 ac = smeshGUI->ReadScript(aM);
4042 smeshGUI->DisplayActor( ac, true );
4043 smeshGUI->DisplayEdges( ac );
4044 smeshGUI->ChangeRepresentation( ac, ac->getDisplayMode() );
4048 MESSAGE("Do not know how to display something which is not a SMESH_Mesh");
4053 MESSAGE("The object "<<theIO->getEntry()<<
4054 " do not have \"AttributeIOR\" attribute");
4059 // The actor exists in some view
4060 // Check whether the actor belongs to the active view
4061 VTKViewer_RenderWindowInteractor *rwInter =
4062 ((VTKViewer_ViewFrame *) activeFrame->getRightFrame()->
4063 getViewFrame())->getRWInteractor();
4065 // The actor belongs to inactive view -> create a copy and display it in the active view
4066 if (!rwInter->isInViewer(IObject))
4068 if(ac->GetMapper()==NULL)
4070 SMESH::SMESH_Mesh_var aMesh = smeshGUI->ConvertIOinMesh(theIO, res);
4071 ac=smeshGUI->ReadScript(aMesh);
4073 SMESH_Actor *acCopy = SMESH_Actor::New();
4074 acCopy->ShallowCopy(ac);
4077 smeshGUI->DisplayActor(ac, false);
4078 smeshGUI->DisplayEdges(ac);
4079 smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
4085 MESSAGE("BuildPresentation() must not be called while non-VTK view is active");
4089 //=============================================================================
4093 //=============================================================================
4094 void SMESHGUI::setOrb()
4098 ORB_INIT & init = *SINGLETON_ < ORB_INIT >::Instance();
4099 ASSERT(SINGLETON_ < ORB_INIT >::IsAlreadyExisting());
4103 INFOS("internal error : orb not found");
4106 ASSERT(!CORBA::is_nil(_orb));
4110 * Get the history of all commands made in the SMESH server. This list of command
4111 * is used to display the mesh in the VTK view
4112 * @TODO Handle the REMOVE_ALL command.
4114 SMESH_Actor *SMESHGUI::ReadScript(SMESH::SMESH_Mesh_ptr aMesh)
4116 MESSAGE("SMESHGUI::ReadScript");
4117 SMESH_Actor *MeshActor;
4118 if (!aMesh->_is_nil())
4120 Standard_Boolean result;
4121 MeshActor = FindActor(aMesh, result, false);
4124 SMESH::log_array_var aSeq = aMesh->GetLog(true);
4125 MESSAGE("SMESHGUI::ReadScript: The log contains "<<aSeq->length()
4128 for (unsigned int ind = 0; ind < aSeq->length(); ind++)
4130 switch (aSeq[ind].commandType)
4132 case SMESH::ADD_NODE:
4134 AddNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4138 case SMESH::ADD_EDGE:
4140 AddEdges( MeshActor, aSeq[ind].number, aSeq[ind].coords, aSeq[ind].indexes );
4143 case SMESH::ADD_TRIANGLE:
4145 AddTriangles(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4149 case SMESH::ADD_QUADRANGLE:
4151 AddQuadrangles(MeshActor, aSeq[ind].number,
4152 aSeq[ind].coords, aSeq[ind].indexes);
4155 case SMESH::ADD_TETRAHEDRON:
4157 AddTetras(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4161 case SMESH::ADD_PYRAMID:
4165 case SMESH::ADD_PRISM:
4169 case SMESH::ADD_HEXAHEDRON:
4171 AddHexaedres(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4175 case SMESH::REMOVE_NODE:
4177 RemoveNodes(MeshActor, aSeq[ind].number, aSeq[ind].coords,
4181 case SMESH::REMOVE_ELEMENT:
4183 RemoveElements(MeshActor, aSeq[ind].number,
4184 aSeq[ind].coords, aSeq[ind].indexes);
4187 case SMESH::REMOVE_ALL:
4188 MESSAGE("REMOVE_ALL command not yet implemented");
4190 default: MESSAGE("Warning: Unknown script command.");
4199 //=============================================================================
4203 //=============================================================================
4204 void SMESHGUI::Dump(SMESH_Actor * Mactor)
4206 vtkUnstructuredGrid *ugrid =
4207 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
4208 vtkPoints *Pts = ugrid->GetPoints();
4209 int nbPts = Pts->GetNumberOfPoints();
4210 int nbCells = ugrid->GetNumberOfCells();
4214 In = fopen("/tmp/dumpMesh", "w+");
4215 fprintf(In, "%d %d\n", nbPts, nbCells);
4216 for (int i = 0; i < nbPts; i++)
4218 float *p = ugrid->GetPoint(i);
4219 fprintf(In, "%d %e %e %e\n", i, p[0], p[1], p[2]);
4222 for (int i = 0; i < nbCells; i++)
4224 fprintf(In, "%d %d", i, ugrid->GetCell(i)->GetCellType());
4225 vtkIdList *Id = ugrid->GetCell(i)->GetPointIds();
4226 for (j = 0; j < Id->GetNumberOfIds(); j++)
4228 fprintf(In, " %d", Id->GetId(j));
4235 //=============================================================================
4239 //=============================================================================
4240 void SMESHGUI::AddNodes(SMESH_Actor * Mactor, int number,
4241 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4243 //MESSAGE("SMESHGUI::AddNodes(number="<<number<<", indexes.length()="<<indexes.length()<<")");
4244 QApplication::setOverrideCursor(Qt::waitCursor);
4245 if (Mactor->GetMapper() == NULL)
4247 vtkPoints *Pts = vtkPoints::New();
4248 SMESH_Grid *ugrid = SMESH_Grid::New();
4256 Pts->InsertNextPoint(coords[j - 1], coords[j], coords[j + 1]);
4257 //Mactor->AddNode( indexes[i-1], idVTK );
4258 ugrid->AddNode(indexes[i - 1], idVTK);
4262 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4263 ugrid->SetPoints(Pts);
4264 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4265 PtsMapper->SetInput(ugrid);
4266 Mactor->DataSource = PtsMapper->GetInput();
4267 Mactor->SetMapper(PtsMapper);
4271 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4272 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4278 ugrid->GetPoints()->InsertNextPoint(coords[j - 1], coords[j],
4280 ugrid->AddNode(indexes[i - 1], idVTK);
4284 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4285 PtsMapper->SetInput(ugrid);
4286 Mactor->DataSource = PtsMapper->GetInput();
4287 Mactor->SetMapper(PtsMapper);
4289 QApplication::restoreOverrideCursor();
4292 //=============================================================================
4296 //=============================================================================
4297 void SMESHGUI::AddNode(SMESH_Actor * Mactor, int idnode, float x, float y,
4300 QApplication::setOverrideCursor(Qt::waitCursor);
4301 MESSAGE("SMESHGUI::AddNode " << idnode << " : " << x << ";" << y << ";" << z);
4303 if (Mactor->GetMapper() == NULL)
4305 vtkPoints *Pts = vtkPoints::New();
4306 int idVTK = Pts->InsertNextPoint(x, y, z);
4307 //Mactor->AddNode( idnode, idVTK );
4308 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::New();
4309 SMESH_Grid *ugrid = SMESH_Grid::New();
4311 ugrid->AddNode(idnode, idVTK);
4312 ugrid->SetPoints(Pts);
4313 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4314 PtsMapper->SetInput(ugrid);
4315 Mactor->DataSource = PtsMapper->GetInput();
4316 Mactor->SetMapper(PtsMapper);
4320 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4321 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4322 int idVTK = ugrid->GetPoints()->InsertNextPoint(x, y, z);
4323 //Mactor->AddNode( idnode, idVTK );
4324 ugrid->AddNode(idnode, idVTK);
4325 vtkDataSetMapper *PtsMapper = vtkDataSetMapper::New();
4326 PtsMapper->SetInput(ugrid);
4327 Mactor->DataSource = PtsMapper->GetInput();
4328 Mactor->SetMapper(PtsMapper);
4330 QApplication::restoreOverrideCursor();
4333 //=============================================================================
4337 //=============================================================================
4338 void SMESHGUI::RemoveNode(SMESH_Actor * Mactor, int idnode)
4340 MESSAGE(" OLD RemoveNode method ")
4341 // int id = Mactor->GetIdVTKNode( idnode );
4342 // MESSAGE ( " RemoveNode id VTK " << id )
4343 // if ( Mactor->GetMapper() != NULL ) {
4344 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4345 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4346 // vtkPoints *Pts = ugrid->GetPoints();
4347 // vtkPoints *newPts = vtkPoints::New();
4348 // int nbPts = Pts->GetNumberOfPoints();
4349 // bool findPt = false;
4350 // for ( int i = 0; i < nbPts; i++ ) {
4353 // newPts->InsertPoint(i, Pts->GetPoint(i) );
4355 // newPts->InsertPoint(i-1, Pts->GetPoint(i) );
4358 // Mactor->RemoveNode( idnode );
4361 // newUgrid->SetPoints(newPts);
4362 // int nbCells = ugrid->GetNumberOfCells();
4363 // for ( int i = 0; i < nbCells; i++ ) {
4364 // vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4365 // vtkIdList *newIds = vtkIdList::New();
4366 // int nbIds = Ids->GetNumberOfIds();
4367 // newIds->SetNumberOfIds(nbIds);
4368 // for ( int j = 0; j < nbIds; j++ ) {
4369 // int theid = Ids->GetId(j);
4370 // if ( theid > id ) {
4371 // newIds->SetId( j, theid-1 );
4373 // newIds->SetId( j, theid );
4375 // int idSMDSel = Mactor->GetIdSMESHDSElement( i );
4376 // Mactor->RemoveElement( idSMDSel, false );
4377 // int idVTKel = newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(), newIds );
4378 // Mactor->AddElement( idSMDSel, idVTKel );
4380 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4381 // Mapper->SetInput( newUgrid );
4382 // Mactor->DataSource = Mapper->GetInput();
4383 // Mactor->SetMapper(Mapper);
4388 //=============================================================================
4392 //=============================================================================
4393 void SMESHGUI::RemoveNodes(SMESH_Actor * Mactor, int number,
4394 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4396 QApplication::setOverrideCursor(Qt::waitCursor);
4400 Mactor->RemoveNode(indexes[i - 1]);
4404 TColStd_DataMapOfIntegerInteger newMapVTKNodes;
4405 TColStd_DataMapOfIntegerInteger newMapSMESHDSNodes;
4406 TColStd_DataMapOfIntegerInteger MapOldNodesToNewNodes;
4408 if (Mactor->GetMapper() != NULL)
4410 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4411 SMESH_Grid *newUgrid = SMESH_Grid::New();
4412 newUgrid->CopyMaps(ugrid);
4414 vtkPoints *Pts = ugrid->GetPoints();
4415 vtkPoints *newPts = vtkPoints::New();
4416 int nbPts = Pts->GetNumberOfPoints();
4418 for (int i = 0; i < nbPts; i++)
4420 int idSMESHDSNode = Mactor->GetIdSMESHDSNode(i);
4421 if (idSMESHDSNode != -1)
4423 newPts->InsertPoint(j, Pts->GetPoint(i));
4425 newMapVTKNodes.Bind(j, idSMESHDSNode);
4426 newMapSMESHDSNodes.Bind(idSMESHDSNode, j);
4428 MapOldNodesToNewNodes.Bind(i, j);
4433 newUgrid->SetIdsVTKNode(newMapVTKNodes);
4434 newUgrid->SetIdsSMESHDSNode(newMapSMESHDSNodes);
4435 newUgrid->SetPoints(newPts);
4437 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4438 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4440 int nbCells = ugrid->GetNumberOfCells();
4441 for (int i = 0; i < nbCells; i++)
4443 vtkIdList *Ids = ugrid->GetCell(i)->GetPointIds();
4444 vtkIdList *newIds = vtkIdList::New();
4445 int nbIds = Ids->GetNumberOfIds();
4446 newIds->SetNumberOfIds(nbIds);
4448 for (int j = 0; j < nbIds; j++)
4450 int theid = Ids->GetId(j);
4451 if (MapOldNodesToNewNodes.IsBound(theid))
4453 newIds->SetId(j, MapOldNodesToNewNodes.Find(theid));
4462 // Filtering out cells based on non-existing nodes
4465 int idSMDSel = Mactor->GetIdSMESHDSElement(i);
4467 newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4470 newMapElementSMDStoVTK.Bind(idSMDSel, idVTKel);
4471 newMapElementVTKtoSMDS.Bind(idVTKel, idSMDSel);
4475 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4476 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4478 // Copy new data to the old DatSource: keep the single DataSource for all actors
4479 ugrid->DeepCopy(newUgrid);
4481 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4482 Mapper->SetInput(ugrid);
4483 Mactor->SetMapper(Mapper);
4485 // Commented to avoid multiple viewer updates when called by ReadScript()
4489 QApplication::restoreOverrideCursor();
4492 //=============================================================================
4496 //=============================================================================
4497 void SMESHGUI::RemoveNodes(SMESH::SMESH_Mesh_ptr aMesh,
4498 const TColStd_MapOfInteger & MapIndex)
4500 QApplication::setOverrideCursor(Qt::waitCursor);
4501 Standard_Boolean result;
4502 SMESH_Actor *ac = FindActor(aMesh, result, true);
4505 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4506 anArrayOfIdeces->length(MapIndex.Extent());
4507 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4509 for (; ite.More(); ite.Next())
4511 // MESSAGE ( " RemoveNode : id " << ac->GetIdSMESHDSNode(ite.Key()) )
4512 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
4515 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4516 aMeshEditor->RemoveNodes(anArrayOfIdeces);
4519 if (myAutomaticUpdate)
4521 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4524 smeshGUI->DisplayActor(Mesh);
4525 smeshGUI->DisplayEdges(Mesh);
4526 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4527 AddActorInSelection(Mesh);
4530 QApplication::restoreOverrideCursor();
4533 //=============================================================================
4537 //=============================================================================
4538 void SMESHGUI::RemoveElement(SMESH_Actor * Mactor, int idelement)
4540 MESSAGE(" OLD RemoveElement method ")
4541 // int id = Mactor->GetIdVTKElement( idelement );
4542 // MESSAGE ( " RemoveElement id VTK : " << id )
4543 // if ( Mactor->GetMapper() != NULL ) {
4544 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4545 // vtkUnstructuredGrid* newUgrid = vtkUnstructuredGrid::New();
4546 // int nbCells = ugrid->GetNumberOfCells();
4547 // for ( int i = 0; i < nbCells; i++ ) {
4549 // newUgrid->InsertNextCell( ugrid->GetCell(i)->GetCellType(),
4550 // ugrid->GetCell(i)->GetPointIds() );
4552 // Mactor->RemoveElement( idelement );
4554 // newUgrid->SetPoints(ugrid->GetPoints());
4555 // vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4556 // Mapper->SetInput( newUgrid );
4557 // Mactor->DataSource = Mapper->GetInput();
4558 // Mactor->SetMapper(Mapper);
4563 //=============================================================================
4567 //=============================================================================
4568 void SMESHGUI::RemoveElements(SMESH_Actor * Mactor, int number,
4569 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4571 QApplication::setOverrideCursor(Qt::waitCursor);
4575 Mactor->RemoveElement(indexes[i - 1]);
4578 TColStd_DataMapOfIntegerInteger newMapElementSMDStoVTK;
4579 TColStd_DataMapOfIntegerInteger newMapElementVTKtoSMDS;
4581 if (Mactor->GetMapper() != NULL)
4583 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4584 SMESH_Grid *newUgrid = SMESH_Grid::New();
4585 newUgrid->CopyMaps(ugrid);
4587 int nbCells = ugrid->GetNumberOfCells();
4588 for (int i = 0; i < nbCells; i++)
4590 int idSMESHDSElement = Mactor->GetIdSMESHDSElement(i);
4591 if (idSMESHDSElement != -1)
4594 newUgrid->InsertNextCell(ugrid->GetCell(i)->GetCellType(),
4595 ugrid->GetCell(i)->GetPointIds());
4596 newMapElementSMDStoVTK.Bind(idSMESHDSElement, newId);
4597 newMapElementVTKtoSMDS.Bind(newId, idSMESHDSElement);
4601 newUgrid->SetIdsVTKElement(newMapElementVTKtoSMDS);
4602 newUgrid->SetIdsSMESHDSElement(newMapElementSMDStoVTK);
4604 newUgrid->SetPoints(ugrid->GetPoints());
4606 // Copy new data to the old DatSource: keep the single DataSource for all actors
4607 ugrid->DeepCopy(newUgrid);
4609 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
4610 Mapper->SetInput(ugrid);
4611 Mactor->SetMapper(Mapper);
4613 // Commented to avoid multiple viewer updates when called by ReadScript()
4616 QApplication::restoreOverrideCursor();
4619 //=============================================================================
4623 //=============================================================================
4624 void SMESHGUI::RemoveElements(SMESH::SMESH_Mesh_ptr aMesh,
4625 const TColStd_MapOfInteger & MapIndex)
4627 QApplication::setOverrideCursor(Qt::waitCursor);
4628 Standard_Boolean result;
4629 SMESH_Actor *ac = FindActor(aMesh, result, true);
4632 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
4633 anArrayOfIdeces->length(MapIndex.Extent());
4634 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4636 for (; ite.More(); ite.Next())
4638 // MESSAGE ( " RemoveElement : id " << ite.Key() << "," << ac->GetIdSMESHDSElement(ite.Key()) )
4639 anArrayOfIdeces[i] = ac->GetIdSMESHDSElement(ite.Key());
4643 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
4644 aMeshEditor->RemoveElements(anArrayOfIdeces);
4647 if (myAutomaticUpdate)
4649 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
4652 smeshGUI->DisplayActor(Mesh);
4653 smeshGUI->DisplayEdges(Mesh);
4654 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
4655 AddActorInSelection(Mesh);
4661 QApplication::restoreOverrideCursor();
4664 //=============================================================================
4668 //=============================================================================
4669 void SMESHGUI::OrientationElements(SMESH::SMESH_Mesh_ptr aMesh,
4670 const TColStd_MapOfInteger & MapIndex)
4672 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4675 vtkRenderer *theRenderer =
4676 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4677 getRightFrame()->getViewFrame())->getRenderer();
4678 Standard_Boolean result;
4679 SMESH_Actor *ac = FindActor(aMesh, result, true);
4682 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4683 SMESH_Grid *UGrid = SMESH_Grid::New();
4684 SMESH_Grid *oldGrid = SMESH_Grid::SafeDownCast(ac->DataSource);
4685 UGrid->CopyMaps(oldGrid);
4687 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4688 gf->SetInput(ac->DataSource);
4690 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4691 Mapper->SetInput(gf->GetOutput());
4694 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4695 for (; ite.More(); ite.Next())
4697 Mapper->GetInput()->ReverseCell(ite.Key());
4700 UGrid->SetPoints(Mapper->GetInput()->GetPoints());
4701 int nbCells = Mapper->GetInput()->GetNumberOfCells();
4702 for (int i = 0; i < nbCells; i++)
4704 UGrid->InsertNextCell(Mapper->GetInput()->GetCellType(i),
4705 Mapper->GetInput()->GetCell(i)->GetPointIds());
4708 // Copy new data to the old DatSource: keep the single DataSource for all actors
4709 oldGrid->DeepCopy(UGrid);
4711 vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4712 //NewMapper->SetInput( UGrid );
4713 NewMapper->SetInput(oldGrid);
4714 NewMapper->Update();
4716 //ac->DataSource = NewMapper->GetInput();
4717 ac->SetMapper(NewMapper);
4719 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4721 QApplication::restoreOverrideCursor();
4724 //=============================================================================
4728 //=============================================================================
4729 void SMESHGUI::DiagonalInversion(SMESH::SMESH_Mesh_ptr aMesh,
4730 const TColStd_MapOfInteger & MapIndex)
4732 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
4735 QApplication::setOverrideCursor(Qt::waitCursor);
4736 vtkRenderer *theRenderer =
4737 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
4738 getRightFrame()->getViewFrame())->getRenderer();
4739 Standard_Boolean result;
4741 SMESH_Actor *ac = FindActor(aMesh, result, true);
4744 //vtkUnstructuredGrid* UGrid = vtkUnstructuredGrid::New();
4745 SMESH_Grid *UGrid = SMESH_Grid::New();
4746 vtkGeometryFilter *gf = vtkGeometryFilter::New();
4747 gf->SetInput(ac->DataSource);
4749 vtkExtractEdges *edges = vtkExtractEdges::New();
4750 edges->SetInput(ac->DataSource);
4752 vtkPolyDataMapper *Mapper = vtkPolyDataMapper::New();
4753 Mapper->SetInput(edges->GetOutput());
4756 int nb = Mapper->GetInput()->GetNumberOfCells();
4757 //MESSAGE ( "nb : " << nb )
4759 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
4760 for (; ite.More(); ite.Next())
4762 vtkCell *StartEdge = Mapper->GetInput()->GetCell(ite.Key());
4763 //MESSAGE( "DCQ : Edge Id = " << ite.Key())
4764 int CellType = StartEdge->GetCellType();
4765 //MESSAGE( "DCQ : Cell Type = " << CellType)
4766 int nbPoints = StartEdge->GetNumberOfPoints();
4768 //MESSAGE( "DCQ : Nb Point = " << nbPoints)
4771 vtkUnstructuredGrid *StartUGrid =
4772 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
4774 vtkIdList *IdCells = vtkIdList::New();
4775 vtkIdList *IdPoints = StartEdge->GetPointIds();
4779 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(0),
4781 Mapper->GetInput()->GetPoints()->GetPoint(IdPoints->GetId(1),
4784 int idp1 = StartUGrid->FindPoint(p1);
4785 int idp2 = StartUGrid->FindPoint(p2);
4787 StartUGrid->GetPointCells(idp1, IdCells);
4789 //MESSAGE ( " pt 0 : " << IdPoints->GetId(0) )
4790 //MESSAGE ( " pt 1 : " << IdPoints->GetId(1) )
4792 //MESSAGE ( " pt 0 : " << idp1 )
4793 //MESSAGE ( " pt 1 : " << idp2 )
4795 vtkIdList *IdPts = vtkIdList::New();
4796 if (IdCells->GetNumberOfIds() >= 2)
4798 int nbCells = IdCells->GetNumberOfIds();
4799 //MESSAGE ( " nbCells : " << nbCells )
4800 for (int j = 0; j < nbCells; j++)
4802 StartUGrid->GetCellPoints(IdCells->GetId(j), IdPts);
4803 if (IdPts->IsId(idp2) == -1)
4805 IdCells->DeleteId(IdCells->GetId(j));
4809 //MESSAGE ( " IdCells " << IdCells->GetNumberOfIds() )
4811 vtkIdList *IdPts0 = vtkIdList::New();
4812 vtkIdList *IdPts1 = vtkIdList::New();
4814 if (IdCells->GetNumberOfIds() == 2)
4816 StartUGrid->GetCellPoints(IdCells->GetId(0), IdPts0);
4817 StartUGrid->GetCellPoints(IdCells->GetId(1), IdPts1);
4820 TColStd_MapOfInteger EndMapIndex;
4821 for (int j = 0; j < 3; j++)
4823 if (IdPts0->GetId(j) != idp1 &&
4824 IdPts0->GetId(j) != idp2)
4826 EndMapIndex.Add(IdPts0->GetId(j));
4828 if (IdPts1->GetId(j) != idp1 &&
4829 IdPts1->GetId(j) != idp2)
4831 EndMapIndex.Add(IdPts1->GetId(j));
4835 bool MyAU = myAutomaticUpdate;
4836 myAutomaticUpdate = false;
4838 EndMapIndex.Add(idp1);
4839 TColStd_MapIteratorOfMapOfInteger ite1(EndMapIndex);
4843 if (ite1.Key() == idp1)
4848 bool reverse1 = (i == 2);
4849 this->AddFace(aMesh, EndMapIndex, reverse1);
4851 EndMapIndex.Remove(idp1);
4852 EndMapIndex.Add(idp2);
4853 TColStd_MapIteratorOfMapOfInteger ite2(EndMapIndex);
4857 if (ite2.Key() == idp2)
4862 bool reverse2 = (i == 2);
4863 this->AddFace(aMesh, EndMapIndex,
4864 !(reverse1 == reverse2));
4866 myAutomaticUpdate = MyAU;
4867 //MESSAGE ( " myAutomaticUpdate = " << MyAU )
4870 TColStd_MapOfInteger StartMapIndex;
4871 StartMapIndex.Add(IdCells->GetId(0));
4872 StartMapIndex.Add(IdCells->GetId(1));
4873 this->RemoveElements(aMesh, StartMapIndex);
4881 // UGrid->SetPoints( Mapper->GetInput()->GetPoints() );
4882 // int nbCells = Mapper->GetInput()->GetNumberOfCells();
4883 // for ( int i = 0; i < nbCells; i++ ) {
4884 // UGrid->InsertNextCell( Mapper->GetInput()->GetCellType(i), Mapper->GetInput()->GetCell(i)->GetPointIds() );
4887 // vtkDataSetMapper *NewMapper = vtkDataSetMapper::New();
4888 // NewMapper->SetInput( UGrid );
4889 // NewMapper->Update();
4891 // ac->DataSource = NewMapper->GetInput();
4892 // ac->SetMapper( NewMapper );
4894 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
4896 QApplication::restoreOverrideCursor();
4899 //=============================================================================
4903 //=============================================================================
4904 void SMESHGUI::AddEdges(SMESH_Actor * Mactor, int number,
4905 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4907 QApplication::setOverrideCursor(Qt::waitCursor);
4908 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4909 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4914 vtkIdList *Ids = vtkIdList::New();
4915 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
4916 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
4917 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4918 Mactor->AddElement(indexes[j - 1], id);
4922 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4923 EdgeMapper->SetInput(ugrid);
4924 Mactor->DataSource = EdgeMapper->GetInput();
4925 Mactor->SetMapper(EdgeMapper);
4926 QApplication::restoreOverrideCursor();
4929 //=============================================================================
4933 //=============================================================================
4934 void SMESHGUI::AddEdge(SMESH_Actor * Mactor, int idedge, int idnode1,
4937 QApplication::setOverrideCursor(Qt::waitCursor);
4938 MESSAGE("SMESHGUI::AddEdge " << idedge << " : " << idnode1 << ";" <<
4939 idnode2) vtkIdList *Ids = vtkIdList::New();
4940 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
4941 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
4943 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4944 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4945 int id = ugrid->InsertNextCell(VTK_LINE, Ids);
4946 Mactor->AddElement(idedge, id);
4948 MESSAGE(" Edge VTK id " << id)
4949 vtkDataSetMapper *EdgeMapper = vtkDataSetMapper::New();
4950 EdgeMapper->SetInput(ugrid);
4951 Mactor->DataSource = EdgeMapper->GetInput();
4952 Mactor->SetMapper(EdgeMapper);
4953 QApplication::restoreOverrideCursor();
4956 //=============================================================================
4960 //=============================================================================
4961 void SMESHGUI::AddTriangles(SMESH_Actor * Mactor, int number,
4962 const SMESH::double_array & coords, const SMESH::long_array & indexes)
4964 // MESSAGE("SMESHGUI::AddTriangles(number="<<number<<", indexes.length="
4965 // <<indexes.length()<<")");
4967 QApplication::setOverrideCursor(Qt::waitCursor);
4968 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4969 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
4974 vtkIdList *Ids = vtkIdList::New();
4975 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
4976 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
4977 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
4978 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
4979 Mactor->AddElement(indexes[j - 1], id);
4983 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
4984 TriMapper->SetInput(ugrid);
4985 Mactor->DataSource = TriMapper->GetInput();
4986 Mactor->SetMapper(TriMapper);
4987 QApplication::restoreOverrideCursor();
4989 void SMESHGUI::AddTriangle(SMESH_Actor * Mactor, int idtri, int idnode1,
4990 int idnode2, int idnode3)
4992 QApplication::setOverrideCursor(Qt::waitCursor);
4993 vtkIdList *Ids = vtkIdList::New();
4994 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
4995 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
4996 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
4998 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
4999 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5000 int id = ugrid->InsertNextCell(VTK_TRIANGLE, Ids);
5001 Mactor->AddElement(idtri, id);
5003 vtkDataSetMapper *TriMapper = vtkDataSetMapper::New();
5004 TriMapper->SetInput(ugrid);
5005 Mactor->DataSource = TriMapper->GetInput();
5006 Mactor->SetMapper(TriMapper);
5007 QApplication::restoreOverrideCursor();
5010 //=============================================================================
5014 //=============================================================================
5015 void SMESHGUI::AddQuadrangles(SMESH_Actor * Mactor, int number,
5016 const SMESH::double_array & coords, const SMESH::long_array & indexes)
5018 QApplication::setOverrideCursor(Qt::waitCursor);
5019 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5020 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5025 vtkIdList *Ids = vtkIdList::New();
5026 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5027 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5028 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5029 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5030 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5031 Mactor->AddElement(indexes[j - 1], id);
5035 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5036 QuadMapper->SetInput(ugrid);
5037 Mactor->DataSource = QuadMapper->GetInput();
5038 Mactor->SetMapper(QuadMapper);
5039 QApplication::restoreOverrideCursor();
5042 //=============================================================================
5046 //=============================================================================
5047 void SMESHGUI::AddQuadrangle(SMESH_Actor * Mactor, int idquad, int idnode1,
5048 int idnode2, int idnode3, int idnode4)
5050 QApplication::setOverrideCursor(Qt::waitCursor);
5051 vtkIdList *Ids = vtkIdList::New();
5052 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5053 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5054 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5055 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5057 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5058 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5059 int id = ugrid->InsertNextCell(VTK_QUAD, Ids);
5060 Mactor->AddElement(idquad, id);
5062 vtkDataSetMapper *QuadMapper = vtkDataSetMapper::New();
5063 QuadMapper->SetInput(ugrid);
5064 Mactor->DataSource = QuadMapper->GetInput();
5065 Mactor->SetMapper(QuadMapper);
5066 QApplication::restoreOverrideCursor();
5069 //=============================================================================
5073 //=============================================================================
5074 void SMESHGUI::AddTetras(SMESH_Actor * Mactor, int number,
5075 const SMESH::double_array & coords, const SMESH::long_array & indexes)
5077 QApplication::setOverrideCursor(Qt::waitCursor);
5078 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5079 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5084 vtkIdList *Ids = vtkIdList::New();
5085 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5086 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5087 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5088 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5089 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5090 Mactor->AddElement(indexes[j - 1], id);
5094 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5095 TetraMapper->SetInput(ugrid);
5096 Mactor->DataSource = TetraMapper->GetInput();
5097 Mactor->SetMapper(TetraMapper);
5098 QApplication::restoreOverrideCursor();
5101 //=============================================================================
5105 //=============================================================================
5106 void SMESHGUI::AddTetra(SMESH_Actor * Mactor, int idtetra, int idnode1,
5107 int idnode2, int idnode3, int idnode4)
5109 QApplication::setOverrideCursor(Qt::waitCursor);
5110 MESSAGE("SMESHGUI::AddTetra " << idtetra << " : " << idnode1 << ";" <<
5111 idnode2 << ";" << idnode3 << ";" << idnode4) vtkIdList *Ids =
5113 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5114 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5115 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5116 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5118 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5119 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5120 int id = ugrid->InsertNextCell(VTK_TETRA, Ids);
5121 Mactor->AddElement(idtetra, id);
5123 MESSAGE(" Tetra VTK id " << id)
5124 vtkDataSetMapper *TetraMapper = vtkDataSetMapper::New();
5125 TetraMapper->SetInput(ugrid);
5126 Mactor->DataSource = TetraMapper->GetInput();
5127 Mactor->SetMapper(TetraMapper);
5128 QApplication::restoreOverrideCursor();
5131 //=============================================================================
5135 //=============================================================================
5136 void SMESHGUI::AddHexaedres(SMESH_Actor * Mactor, int number,
5137 const SMESH::double_array & coords, const SMESH::long_array & indexes)
5139 QApplication::setOverrideCursor(Qt::waitCursor);
5140 //vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5141 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5146 vtkIdList *Ids = vtkIdList::New();
5147 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j]));
5148 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 1]));
5149 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 2]));
5150 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 3]));
5151 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 4]));
5152 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 5]));
5153 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 6]));
5154 Ids->InsertNextId(Mactor->GetIdVTKNode(indexes[j + 7]));
5155 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5156 Mactor->AddElement(indexes[j - 1], id);
5160 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5161 HexaMapper->SetInput(ugrid);
5162 Mactor->DataSource = HexaMapper->GetInput();
5163 Mactor->SetMapper(HexaMapper);
5164 QApplication::restoreOverrideCursor();
5167 //=============================================================================
5171 //=============================================================================
5172 void SMESHGUI::AddHexaedre(SMESH_Actor * Mactor, int idhexa, int idnode1,
5173 int idnode2, int idnode3, int idnode4, int idnode5, int idnode6,
5174 int idnode7, int idnode8)
5176 QApplication::setOverrideCursor(Qt::waitCursor);
5177 MESSAGE("SMESHGUI::AddHexaedre " << idhexa << " : " << idnode1 << ";" <<
5178 idnode2 << ";" << idnode3 << ";" << idnode4 << ";" << idnode5 << ";" <<
5179 idnode6 << ";" << idnode7 << ";" << idnode8) vtkIdList *Ids =
5181 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode1));
5182 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode2));
5183 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode3));
5184 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode4));
5185 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode5));
5186 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode6));
5187 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode7));
5188 Ids->InsertNextId(Mactor->GetIdVTKNode(idnode8));
5190 //vtkUnstructuredGrid *ugrid = vtkUnstructuredGrid::SafeDownCast( Mactor->DataSource );
5191 SMESH_Grid *ugrid = SMESH_Grid::SafeDownCast(Mactor->DataSource);
5192 int id = ugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
5193 Mactor->AddElement(idhexa, id);
5195 MESSAGE(" Hexa VTK id " << id)
5196 vtkDataSetMapper *HexaMapper = vtkDataSetMapper::New();
5197 HexaMapper->SetInput(ugrid);
5198 Mactor->DataSource = HexaMapper->GetInput();
5199 Mactor->SetMapper(HexaMapper);
5200 QApplication::restoreOverrideCursor();
5203 //=====================================================================================
5205 //=====================================================================================
5208 bool OnGUIEvent(int theCommandID, QAD_Desktop * parent)
5210 return SMESHGUI::OnGUIEvent(theCommandID, parent);
5213 bool OnKeyPress(QKeyEvent * pe, QAD_Desktop * parent,
5214 QAD_StudyFrame * studyFrame)
5216 return SMESHGUI::OnKeyPress(pe, parent, studyFrame);
5219 bool OnMousePress(QMouseEvent * pe, QAD_Desktop * parent,
5220 QAD_StudyFrame * studyFrame)
5222 return SMESHGUI::OnMousePress(pe, parent, studyFrame);
5225 bool OnMouseMove(QMouseEvent * pe, QAD_Desktop * parent,
5226 QAD_StudyFrame * studyFrame)
5228 return SMESHGUI::OnMouseMove(pe, parent, studyFrame);
5231 bool SetSettings(QAD_Desktop * parent)
5233 return SMESHGUI::SetSettings(parent);
5236 bool customPopup(QAD_Desktop * parent, QPopupMenu * popup,
5237 const QString & theContext, const QString & theParent,
5238 const QString & theObject)
5240 return SMESHGUI::CustomPopup(parent, popup, theContext, theParent,
5244 void definePopup(QString & theContext, QString & theParent,
5245 QString & theObject)
5247 SMESHGUI::DefinePopup(theContext, theParent, theObject);
5250 bool activeStudyChanged(QAD_Desktop * parent)
5252 SMESHGUI::activeStudyChanged(parent);
5255 void buildPresentation(const Handle(SALOME_InteractiveObject) & theIO)
5257 SMESHGUI::BuildPresentation(theIO);
5260 void supportedViewType(int *buffer, int bufferSize)
5262 if (!buffer || !bufferSize)
5264 buffer[0] = (int)VIEW_VTK;
5269 //=============================================================================
5273 //=============================================================================
5274 void SMESHGUI::ViewNodes()
5276 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5279 EraseSimulationActors();
5280 mySimulationActors = vtkActorCollection::New();
5281 vtkRenderer *theRenderer =
5282 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5283 getRightFrame()->getViewFrame())->getRenderer();
5284 vtkActorCollection *theActors = theRenderer->GetActors();
5285 theActors->InitTraversal();
5286 vtkActor *ac = theActors->GetNextActor();
5287 while (!(ac == NULL))
5289 if (ac->IsA("SMESH_Actor"))
5291 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5292 if (anActor->GetVisibility() == 1)
5294 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5295 gf->SetInput(anActor->DataSource);
5296 vtkMaskPoints *verts = vtkMaskPoints::New();
5297 verts->SetInput(gf->GetOutput());
5298 verts->GenerateVerticesOn();
5299 verts->SetOnRatio(1);
5301 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
5302 vertMapper->SetInput(verts->GetOutput());
5303 vertMapper->ScalarVisibilityOff();
5305 vtkActor *vertActor = vtkActor::New();
5306 vertActor->SetMapper(vertMapper);
5309 anActor->GetNodeColor(r, g, b);
5310 vertActor->GetProperty()->SetColor(r, g, b);
5312 vertActor->GetProperty()->SetPointSize(anActor->GetNodeSize());
5314 vertActor->PickableOff();
5316 mySimulationActors->AddItem(vertActor);
5317 theRenderer->AddActor(vertActor);
5320 ac = theActors->GetNextActor();
5323 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5327 //=============================================================================
5331 //=============================================================================
5332 void SMESHGUI::Control(int theCommandID)
5334 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5337 QApplication::setOverrideCursor(Qt::waitCursor);
5338 DisplayScalarBar(false);
5340 vtkDoubleArray *scalars = vtkDoubleArray::New();
5341 scalars->SetNumberOfComponents(1);
5343 vtkDataSetMapper *meshMapper = 0;
5344 SALOME_Selection *Sel =
5345 SALOME_Selection::Selection(myActiveStudy->getSelection());
5346 int nbSel = Sel->IObjectCount();
5347 Standard_Boolean result;
5348 Handle(SALOME_InteractiveObject) IObject = Sel->firstIObject();
5349 SMESH_Actor *MeshActor =
5350 FindActorByEntry(IObject->getEntry(), result, true);
5352 // Mesh may be not updated after Compute
5353 if (!MeshActor->DataSource || !MeshActor->GetMapper())
5355 QApplication::restoreOverrideCursor();
5359 vtkDataSet *aDataSet = MeshActor->DataSource;
5360 typedef double (*TScalarFun) (vtkCell * theCell);
5361 TScalarFun aScalarFun;
5365 switch (theCommandID)
5369 type = tr("SMESH_CONTROL_LENGTH_EDGES");
5370 aDataSet = MeshActor->EdgeDevice->GetMapper()->GetInput();
5371 aScalarFun = &(SMESHGUI_ComputeScalarValue::LengthEdges);
5372 MESSAGE(" init minimum length " << aDataSet->GetNumberOfCells());
5373 if (MeshActor->getDisplayMode() != 0)
5374 ChangeRepresentation(MeshActor, 1); // limitation; in Wireframe, colored edges are not visible
5379 type = tr("SMESH_CONTROL_AREA_ELEMENTS");
5380 aScalarFun = &(SMESHGUI_ComputeScalarValue::AreaElements);
5381 if (MeshActor->getDisplayMode() != 1)
5382 ChangeRepresentation(MeshActor, 1);
5387 type = tr("SMESH_CONTROL_TAPER_ELEMENTS");
5388 aScalarFun = &(SMESHGUI_ComputeScalarValue::Taper);
5393 type = tr("SMESH_CONTROL_ASPECTRATIO_ELEMENTS");
5394 aScalarFun = &(SMESHGUI_ComputeScalarValue::AspectRatio);
5395 if (MeshActor->getDisplayMode() != 1)
5396 ChangeRepresentation(MeshActor, 1);
5401 type = tr("SMESH_CONTROL_MINIMUMANGLE_ELEMENTS");
5402 aScalarFun = &(SMESHGUI_ComputeScalarValue::MinimumAngle);
5403 if (MeshActor->getDisplayMode() != 1)
5404 ChangeRepresentation(MeshActor, 1);
5409 type = tr("SMESH_CONTROL_WARP_ELEMENTS");
5410 aScalarFun = &(SMESHGUI_ComputeScalarValue::Warp);
5415 type = tr("SMESH_CONTROL_SKEW_ELEMENTS");
5416 aScalarFun = &(SMESHGUI_ComputeScalarValue::Skew);
5421 for (int i = 0, iEnd = aDataSet->GetNumberOfCells(); i < iEnd; i++)
5422 scalars->InsertTuple1(i, aScalarFun(aDataSet->GetCell(i)));
5425 scalars->GetRange(range);
5427 vtkLookupTable *wat = vtkLookupTable::New();
5428 wat->SetRange(range);
5431 scalars->SetLookupTable(wat);
5434 meshMapper = (vtkDataSetMapper *) (MeshActor->getMapper());
5435 meshMapper->SetScalarModeToUseCellData();
5436 MeshActor->DataSource->GetCellData()->SetScalars(scalars);
5437 meshMapper->SetScalarRange(range);
5438 meshMapper->ScalarVisibilityOn();
5440 vtkScalarBarActor *aScalarBar = GetScalarBar();
5441 if (aScalarBar == NULL)
5443 aScalarBar = vtkScalarBarActor::New();
5444 QString Bold = QAD_CONFIG->getSetting("ScalarBar:Bold");
5445 QString Italic = QAD_CONFIG->getSetting("ScalarBar:Italic");
5446 QString Shadow = QAD_CONFIG->getSetting("ScalarBar:Shadow");
5447 QString FontFamily = QAD_CONFIG->getSetting("ScalarBar:FontFamily");
5448 QString Orientation =
5449 QAD_CONFIG->getSetting("ScalarBar:Orientation");
5450 float Width = QAD_CONFIG->getSetting("ScalarBar:Width").toFloat();
5451 float Height = QAD_CONFIG->getSetting("ScalarBar:Height").toFloat();
5452 int NumberOfLabels =
5453 QAD_CONFIG->getSetting("ScalarBar:NumberOfLabels").toInt();
5454 int NumberOfColors =
5455 QAD_CONFIG->getSetting("ScalarBar:NumberOfColors").toInt();
5457 SetSettingsScalarBar(aScalarBar, Bold, Italic, Shadow, FontFamily,
5458 Orientation, Width, Height, NumberOfColors, NumberOfLabels);
5459 vtkRenderer *theRenderer =
5460 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5461 getRightFrame()->getViewFrame())->getRenderer();
5462 theRenderer->AddActor2D(aScalarBar);
5464 aScalarBar->SetLookupTable(wat);
5465 aScalarBar->SetTitle(type.latin1());
5469 DisplayScalarBar(true);
5471 QApplication::restoreOverrideCursor();
5474 //=============================================================================
5478 //=============================================================================
5479 void SMESHGUI::SetSettingsScalarBar(vtkScalarBarActor * theScalarBar,
5480 QString Bold, QString Italic,
5481 QString Shadow, QString FontFamily,
5482 QString Orientation, float Width, float Height, int NbColors, int NbLabels)
5484 if (Bold.isNull() || Bold.isEmpty() || (Bold.compare("true") == 0))
5485 theScalarBar->BoldOn();
5487 theScalarBar->BoldOff();
5489 if (Italic.isNull() || Italic.isEmpty() || (Italic.compare("true") == 0))
5490 theScalarBar->ItalicOn();
5492 theScalarBar->ItalicOff();
5494 if (Shadow.isNull() || Shadow.isEmpty() || (Shadow.compare("true") == 0))
5495 theScalarBar->ShadowOn();
5497 theScalarBar->ShadowOff();
5499 if (FontFamily.compare("Arial") == 0)
5500 theScalarBar->SetFontFamilyToArial();
5501 else if (FontFamily.compare("Courier") == 0)
5502 theScalarBar->SetFontFamilyToCourier();
5503 else if (FontFamily.compare("Times") == 0)
5504 theScalarBar->SetFontFamilyToTimes();
5506 theScalarBar->SetFontFamilyToArial();
5508 if (Orientation.isNull() || Orientation.isEmpty() ||
5509 (Orientation.compare("Vertical") == 0))
5510 theScalarBar->SetOrientationToVertical();
5512 theScalarBar->SetOrientationToHorizontal();
5514 theScalarBar->SetWidth((Width == 0) ? 0.17 : Width);
5515 theScalarBar->SetHeight((Height == 0) ? 0.8 : Height);
5517 theScalarBar->SetNumberOfLabels((NbLabels == 0) ? 5 : NbLabels);
5518 theScalarBar->SetMaximumNumberOfColors((NbColors == 0) ? 64 : NbColors);
5521 //=============================================================================
5525 //=============================================================================
5526 void SMESHGUI::DisplayScalarBar(bool visibility)
5528 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5531 vtkRenderer *theRenderer =
5532 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5533 getRightFrame()->getViewFrame())->getRenderer();
5534 vtkScalarBarActor *aScalarBar = GetScalarBar();
5536 if (aScalarBar == NULL)
5538 MESSAGE("myScalarBar is NULL");
5543 aScalarBar->VisibilityOn();
5546 aScalarBar->VisibilityOff();
5547 //Turn off mesh coloring (influences on all views)
5548 vtkActorCollection *actorList = theRenderer->GetActors();
5549 actorList->InitTraversal();
5550 vtkActor *ac = actorList->GetNextActor();
5553 if (ac->GetMapper() != NULL)
5555 ac->GetMapper()->ScalarVisibilityOff();
5557 ac = actorList->GetNextActor();
5559 // Turn off ScalarBar in all views
5560 /*QList<QAD_StudyFrame> aFrames = myActiveStudy->getStudyFrames();
5561 * for ( QAD_StudyFrame* aFrame = aFrames.first(); aFrame; aFrame = aFrames.next() ) {
5562 * if (aFrame->getTypeView() == VIEW_VTK) {
5563 * vtkRenderer *aRenderer = ((VTKViewer_ViewFrame*) aFrame->getRightFrame()->getViewFrame())->getRenderer();
5564 * vtkActor2DCollection* actor2DList = aRenderer->GetActors2D();
5565 * actor2DList->InitTraversal();
5566 * vtkActor2D* aActor2d = actor2DList->GetNextActor2D();
5567 * while (aActor2d != NULL) {
5568 * if (aActor2d->IsA("vtkScalarBarActor")) {
5569 * aActor2d->VisibilityOff();
5572 * actor2DList->GetNextActor2D();
5577 myActiveStudy->update3dViewers();
5580 //=============================================================================
5584 //=============================================================================
5585 void SMESHGUI::UpdateScalarBar(float MinRange, float MaxRange)
5587 vtkScalarBarActor *aScalarBar = GetScalarBar();
5588 if (aScalarBar == NULL)
5590 MESSAGE("myScalarBar is NULL");
5593 DisplayScalarBar(false);
5595 aScalarBar->GetLookupTable()->SetRange(MinRange, MaxRange);
5596 vtkRenderer *aRenderer =
5597 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5598 getRightFrame()->getViewFrame())->getRenderer();
5599 vtkActorCollection *aActorList = aRenderer->GetActors();
5600 aActorList->InitTraversal();
5601 vtkActor *aActor = aActorList->GetNextActor();
5602 while (aActor != NULL)
5604 if (aActor->IsA("SMESH_Actor"))
5606 SMESH_Actor *aMeshActor = SMESH_Actor::SafeDownCast(aActor);
5607 vtkDataSetMapper *aMeshMapper =
5608 (vtkDataSetMapper *) (aMeshActor->getMapper());
5609 if ((aMeshMapper != NULL))
5611 aMeshMapper->SetScalarRange(MinRange, MaxRange);
5612 aMeshMapper->ScalarVisibilityOn();
5615 aActor = aActorList->GetNextActor();
5617 DisplayScalarBar(true);
5620 //=============================================================================
5624 //=============================================================================
5625 void SMESHGUI::SetDisplaySettings()
5627 EmitSignalDeactivateDialog();
5628 SMESHGUI_Preferences_ColorDlg *aDlg =
5629 new SMESHGUI_Preferences_ColorDlg(QAD_Application::getDesktop(), "");
5631 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsFillColorRed");
5632 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsFillColorGreen");
5633 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsFillColorBlue");
5634 QColor color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5635 aDlg->SetColor(1, color);
5637 SCr = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed");
5638 SCg = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen");
5639 SCb = QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue");
5640 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5641 aDlg->SetColor(2, color);
5643 SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
5644 SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
5645 SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
5646 color = QColor(SCr.toInt(), SCg.toInt(), SCb.toInt());
5647 aDlg->SetColor(3, color);
5649 QString SBr = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorRed");
5650 QString SBg = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorGreen");
5651 QString SBb = QAD_CONFIG->getSetting("SMESH:SettingsBackFaceColorBlue");
5652 color = QColor(SBr.toInt(), SBg.toInt(), SBb.toInt());
5653 aDlg->SetColor(4, color);
5655 QString intValue = QAD_CONFIG->getSetting("SMESH:SettingsWidth");
5656 aDlg->SetIntValue(1, intValue.toInt());
5657 intValue = QAD_CONFIG->getSetting("SMESH:SettingsNodesSize");
5658 aDlg->SetIntValue(2, intValue.toInt());
5659 intValue = QAD_CONFIG->getSetting("SMESH:SettingsShrinkCoeff");
5660 aDlg->SetIntValue(3, intValue.toInt());
5664 QColor colorFill = aDlg->GetColor(1);
5665 QAD_CONFIG->addSetting("SMESH:SettingsFillColorRed", colorFill.red());
5666 QAD_CONFIG->addSetting("SMESH:SettingsFillColorGreen",
5668 QAD_CONFIG->addSetting("SMESH:SettingsFillColorBlue", colorFill.blue());
5670 QColor colorOutline = aDlg->GetColor(2);
5671 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorRed",
5672 colorOutline.red());
5673 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorGreen",
5674 colorOutline.green());
5675 QAD_CONFIG->addSetting("SMESH:SettingsOutlineColorBlue",
5676 colorOutline.blue());
5678 QColor colorNode = aDlg->GetColor(3);
5679 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorRed", colorNode.red());
5680 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorGreen",
5682 QAD_CONFIG->addSetting("SMESH:SettingsNodeColorBlue", colorNode.blue());
5684 QColor colorBackFace = aDlg->GetColor(4);
5685 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorRed",
5686 colorBackFace.red());
5687 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorGreen",
5688 colorBackFace.green());
5689 QAD_CONFIG->addSetting("SMESH:SettingsBackFaceColorBlue",
5690 colorBackFace.blue());
5692 int width = aDlg->GetIntValue(1);
5693 QAD_CONFIG->addSetting("SMESH:SettingsWidth", width);
5695 int nodes_size = aDlg->GetIntValue(2);
5696 QAD_CONFIG->addSetting("SMESH:SettingsNodesSize", nodes_size);
5698 int shrink_coeff = aDlg->GetIntValue(3);
5699 QAD_CONFIG->addSetting("SMESH:SettingsShrinkCoeff", shrink_coeff);
5705 //=======================================================================
5706 // function : Parameter()
5707 // purpose : return a parameter (double) from a dialog box
5709 // aValue : is a double used as a default value displayed
5710 // aLabel : is the title for aValue1
5711 // aTitle : is the main title
5712 // bottom : maximum value to be entered
5713 // top : minimum value to be entered
5714 // decimals : number of decimals
5715 //=======================================================================
5716 double SMESHGUI::Parameter(Standard_Boolean & res,
5717 const double aValue,
5720 const double bottom, const double top, const int decimals)
5722 SMESHGUI_aParameterDlg *Dialog =
5723 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5726 bottom, top, decimals,
5728 Dialog->setValue(aValue);
5730 res = (Dialog->exec() == QDialog::Accepted);
5732 X = Dialog->getDblValue();
5736 //=======================================================================
5737 // function : Parameter()
5738 // purpose : return a parameter (int) from a dialog box
5740 // aValue : is a int used as a default value displayed
5741 // aLabel : is the title for aValue1
5742 // aTitle : is the main title
5743 // bottom : maximum value to be entered
5744 // top : minimum value to be entered
5745 //=======================================================================
5746 int SMESHGUI::Parameter(Standard_Boolean & res,
5748 const char *aLabel, const char *aTitle, const int bottom, const int top)
5750 SMESHGUI_aParameterDlg *Dialog =
5751 new SMESHGUI_aParameterDlg(QAD_Application::getDesktop(),
5756 Dialog->setValue(aValue);
5758 res = (Dialog->exec() == QDialog::Accepted);
5760 X = Dialog->getIntValue();
5764 //=============================================================================
5768 //=============================================================================
5769 void SMESHGUI::DisplayEdges(SMESH_Actor * ac, bool visibility)
5771 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5773 if (ac->DataSource == NULL || ac->GetMapper() == NULL)
5776 vtkGeometryFilter *gf = vtkGeometryFilter::New();
5777 gf->SetInput(ac->DataSource);
5778 vtkFeatureEdges *edges = vtkFeatureEdges::New();
5779 edges->SetInput(gf->GetOutput());
5780 edges->BoundaryEdgesOn();
5781 edges->ManifoldEdgesOn();
5783 vtkPolyDataMapper *edgeMapper = vtkPolyDataMapper::New();
5784 edgeMapper->SetInput(edges->GetOutput());
5785 edgeMapper->ScalarVisibilityOff();
5787 vtkRenderer *theRenderer =
5788 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5789 getRightFrame()->getViewFrame())->getRenderer();
5790 vtkActorCollection *actorList = theRenderer->GetActors();
5792 int test = actorList->IsItemPresent(ac->EdgeDevice);
5795 vtkProperty *prop = vtkProperty::New();
5796 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5798 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5800 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5802 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5804 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5806 ac->EdgeDevice->SetProperty(prop);
5807 ac->SetEdgeColor(QAD_CONFIG->
5808 getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5809 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5811 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5813 ac->EdgeDevice->SetMapper(edgeMapper);
5815 theRenderer->AddActor(ac->EdgeDevice);
5819 ac->EdgeDevice->SetMapper(edgeMapper);
5820 edgeMapper->Update();
5823 vtkShrinkFilter *shrink = vtkShrinkFilter::New();
5824 shrink->SetInput(ac->DataSource);
5825 shrink->SetShrinkFactor(ac->GetShrinkFactor());
5826 vtkGeometryFilter *Shrinkgf = vtkGeometryFilter::New();
5827 Shrinkgf->SetInput(shrink->GetOutput());
5828 vtkFeatureEdges *ShrinkEdges = vtkFeatureEdges::New();
5829 ShrinkEdges->SetInput(Shrinkgf->GetOutput());
5830 ShrinkEdges->BoundaryEdgesOn();
5831 ShrinkEdges->ManifoldEdgesOn();
5833 vtkPolyDataMapper *ShrinkEdgeMapper = vtkPolyDataMapper::New();
5834 ShrinkEdgeMapper->SetInput(ShrinkEdges->GetOutput());
5835 ShrinkEdgeMapper->ScalarVisibilityOff();
5837 test = actorList->IsItemPresent(ac->EdgeShrinkDevice);
5840 vtkProperty *prop = vtkProperty::New();
5841 prop->SetColor(QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorRed").
5843 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5845 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5847 prop->SetPointSize(QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").
5849 prop->SetLineWidth(QAD_CONFIG->getSetting("SMESH:SettingsWidth").
5851 ac->EdgeShrinkDevice->SetProperty(prop);
5852 ac->SetEdgeColor(QAD_CONFIG->
5853 getSetting("SMESH:SettingsOutlineColorRed").toFloat() / 255.,
5854 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorGreen").
5856 QAD_CONFIG->getSetting("SMESH:SettingsOutlineColorBlue").toFloat() /
5858 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5860 theRenderer->AddActor(ac->EdgeShrinkDevice);
5864 ac->EdgeShrinkDevice->SetMapper(ShrinkEdgeMapper);
5865 ShrinkEdgeMapper->Update();
5868 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5872 //=============================================================================
5876 //=============================================================================
5877 void SMESHGUI::InitActor(SMESH::SMESH_Mesh_ptr aMesh)
5879 SALOMEDS::SObject_var aSO_M = myStudyAPI.FindMesh(aMesh);
5880 SALOMEDS::GenericAttribute_var anAttr;
5881 SALOMEDS::AttributeName_var aName;
5882 if (!aSO_M->_is_nil())
5884 if (aSO_M->FindAttribute(anAttr, "AttributeName"))
5886 aName = SALOMEDS::AttributeName::_narrow(anAttr);
5887 Standard_Boolean result;
5888 SMESH_Actor *MeshActor =
5889 smeshGUI->FindActorByEntry(aSO_M->GetID(), result, true);
5892 SMESH_Actor *amesh = SMESH_Actor::New();
5893 Handle(SALOME_InteractiveObject) IO =
5894 new SALOME_InteractiveObject(aSO_M->GetID(), "MESH",
5897 amesh->setName(aName->Value());
5898 DisplayActor(amesh, false);
5904 //=============================================================================
5908 //=============================================================================
5909 void SMESHGUI::Update()
5911 MESSAGE("SMESHGUI::Update");
5912 if (myActiveStudy->getActiveStudyFrame()->getTypeView() == VIEW_VTK)
5914 vtkRenderer *theRenderer =
5915 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
5916 getRightFrame()->getViewFrame())->getRenderer();
5918 SALOME_Selection *Sel =
5919 SALOME_Selection::Selection(myActiveStudy->getSelection());
5920 int nbSel = Sel->IObjectCount();
5923 vtkActorCollection *actorList = theRenderer->GetActors();
5924 actorList->InitTraversal();
5925 vtkActor *ac = actorList->GetNextActor();
5926 while (!(ac == NULL))
5928 if (ac->IsA("SMESH_Actor"))
5930 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
5931 if (anActor->hasIO())
5933 Handle(SALOME_InteractiveObject) IO = anActor->getIO();
5937 ac = actorList->GetNextActor();
5942 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
5943 for (; It.More(); It.Next())
5945 Handle(SALOME_InteractiveObject) IO = It.Value();
5949 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
5952 QApplication::restoreOverrideCursor();
5955 //=============================================================================
5959 //=============================================================================
5960 void SMESHGUI::Update(const Handle(SALOME_InteractiveObject) & IO)
5962 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
5967 Standard_Boolean res;
5968 SMESH::SMESH_Mesh_var aMesh = ConvertIOinMesh(IO, res);
5971 SMESH_Actor *ac = FindActorByEntry(IO->getEntry(), res, false);
5974 // Check whether the actor belongs to the active view
5975 VTKViewer_RenderWindowInteractor *rwInter =
5976 ((VTKViewer_ViewFrame *) myActiveStudy->
5977 getActiveStudyFrame()->getRightFrame()->getViewFrame())->
5980 ac = ReadScript(aMesh);
5981 // The actor belongs to inactive view -> create a copy and display it in the active view
5982 if (!rwInter->isInViewer(IO))
5984 SMESH_Actor *acCopy = SMESH_Actor::New();
5985 acCopy->ShallowCopy(ac);
5996 smeshGUI->ChangeRepresentation(ac, ac->getDisplayMode());
6003 //=============================================================================
6007 //=============================================================================
6008 vtkActor *SMESHGUI::SimulationMoveNode(SMESH_Actor * Mactor, int idnode)
6010 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6013 mySimulationActors = vtkActorCollection::New();
6014 vtkRenderer *theRenderer =
6015 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6016 getRightFrame()->getViewFrame())->getRenderer();
6018 vtkUnstructuredGrid *ugrid =
6019 vtkUnstructuredGrid::SafeDownCast(Mactor->DataSource);
6020 vtkIdList *IdCells = vtkIdList::New();
6021 ugrid->GetPointCells(idnode, IdCells);
6023 vtkPoints *Pts = vtkPoints::New();
6024 Pts = ugrid->GetPoints();
6026 vtkUnstructuredGrid *ugridSimulation = vtkUnstructuredGrid::New();
6027 ugridSimulation->SetPoints(Pts);
6028 vtkIdList *IdPts = vtkIdList::New();
6029 for (int j = 0; j < IdCells->GetNumberOfIds(); j++)
6031 ugrid->GetCellPoints(IdCells->GetId(j), IdPts);
6032 ugridSimulation->InsertNextCell(ugrid->GetCellType(IdCells->GetId(j)),
6036 vtkProperty *prop = vtkProperty::New();
6037 prop->SetColor(1., 0., 0.);
6038 prop->SetRepresentationToWireframe();
6040 int Edgewidth = (int)Mactor->EdgeDevice->GetProperty()->GetLineWidth();
6043 prop->SetLineWidth(Edgewidth + 1);
6045 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6046 Mapper->SetInput(ugridSimulation);
6047 vtkActor *ac = vtkActor::New();
6048 ac->SetMapper(Mapper);
6049 ac->SetProperty(prop);
6051 ac->GetMapper()->SetResolveCoincidentTopologyToShiftZBuffer();
6052 ac->GetMapper()->SetResolveCoincidentTopologyZShift(0.02);
6054 mySimulationActors->AddItem(ac);
6055 theRenderer->AddActor(ac);
6057 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6063 //=============================================================================
6067 //=============================================================================
6068 void SMESHGUI::DisplaySimulationNode(SMESH::SMESH_Mesh_ptr aMesh, float x,
6071 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6074 EraseSimulationActors();
6075 mySimulationActors = vtkActorCollection::New();
6076 vtkRenderer *theRenderer =
6077 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6078 getRightFrame()->getViewFrame())->getRenderer();
6079 Standard_Boolean result;
6080 SMESH_Actor *ac = FindActor(aMesh, result, true);
6084 vtkUnstructuredGrid *ugrid =
6085 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6086 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6088 vtkPoints *Pts = ugrid->GetPoints();
6089 vtkPoints *newPts = vtkPoints::New();
6090 int nbPts = Pts->GetNumberOfPoints();
6091 for (int i = 0; i < nbPts; i++)
6093 newPts->InsertPoint(i, Pts->GetPoint(i));
6096 newugrid->SetPoints(newPts);
6097 newugrid->GetPoints()->InsertNextPoint(x, y, z);
6099 vtkMaskPoints *verts = vtkMaskPoints::New();
6100 verts->SetInput(newugrid);
6101 verts->SetGenerateVertices(1);
6102 verts->SetOnRatio(1);
6104 vtkPolyDataMapper *vertMapper = vtkPolyDataMapper::New();
6105 vertMapper->SetInput(verts->GetOutput());
6106 vertMapper->ScalarVisibilityOff();
6108 vtkActor *node = vtkActor::New();
6109 node->SetMapper(vertMapper);
6111 QString SCr = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorRed");
6112 QString SCg = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorGreen");
6113 QString SCb = QAD_CONFIG->getSetting("SMESH:SettingsNodeColorBlue");
6114 QColor nodecolor(SCr.toInt(), SCg.toInt(), SCb.toInt());
6115 if (!nodecolor.isValid())
6116 // nodecolor = QColor(0.,1.,0.);
6117 nodecolor = QColor(0, 1, 0);
6119 node->GetProperty()->SetColor(float (nodecolor.red()) / 255.,
6120 float (nodecolor.green()) / 255., float (nodecolor.blue()) / 255.);
6123 QAD_CONFIG->getSetting("SMESH:SettingsNodesSize").toInt();
6127 node->GetProperty()->SetPointSize(intValue);
6129 node->VisibilityOn();
6131 mySimulationActors->AddItem(node);
6132 theRenderer->AddActor(node);
6135 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6139 //=============================================================================
6143 //=============================================================================
6144 void SMESHGUI::DisplaySimulationMoveNode(vtkActor * ac, int idnode, float x,
6147 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6150 vtkRenderer *theRenderer =
6151 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6152 getRightFrame()->getViewFrame())->getRenderer();
6153 float *pt = ac->GetMapper()->GetInput()->GetPoint(idnode);
6158 ac->GetMapper()->ImmediateModeRenderingOn();
6159 ac->GetProperty()->SetRepresentationToWireframe();
6161 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6166 //=============================================================================
6170 //=============================================================================
6171 void SMESHGUI::MoveNode(SMESH::SMESH_Mesh_ptr aMesh, int idnode, float x,
6174 Standard_Boolean result;
6176 SMESH_Actor *MeshActor = FindActor(aMesh, result, true);
6182 //=============================================================================
6186 //=============================================================================
6187 void SMESHGUI::ScalarVisibilityOff()
6189 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6192 vtkRenderer *theRenderer =
6193 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6194 getRightFrame()->getViewFrame())->getRenderer();
6195 vtkActorCollection *actorList = theRenderer->GetActors();
6197 actorList->InitTraversal();
6198 vtkActor *ac = actorList->GetNextActor();
6199 while (!(ac == NULL))
6201 if (ac->IsA("SMESH_Actor"))
6203 SMESH_Actor *anActor = SMESH_Actor::SafeDownCast(ac);
6204 if (anActor->GetVisibility() == 1)
6206 vtkDataSetMapper *meshMapper =
6207 (vtkDataSetMapper *) (anActor->getMapper());
6208 meshMapper->ScalarVisibilityOff();
6209 meshMapper->SetInput(anActor->DataSource);
6210 ChangeRepresentation(anActor, anActor->getDisplayMode());
6213 ac = actorList->GetNextActor();
6216 theRenderer->Render();
6219 //=============================================================================
6223 //=============================================================================
6224 void SMESHGUI::DisplaySimulationEdge(SMESH::SMESH_Mesh_ptr aMesh,
6225 const TColStd_MapOfInteger & MapIndex)
6227 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6230 EraseSimulationActors();
6231 mySimulationActors = vtkActorCollection::New();
6232 vtkRenderer *theRenderer =
6233 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6234 getRightFrame()->getViewFrame())->getRenderer();
6235 Standard_Boolean result;
6236 SMESH_Actor *ac = FindActor(aMesh, result, true);
6239 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6243 vtkIdList *Ids = vtkIdList::New();
6244 for (; ite.More(); ite.Next())
6246 idNodes[i] = ite.Key();
6250 Ids->InsertId(0, idNodes[0]);
6251 pts[0] = idNodes[0];
6252 Ids->InsertId(1, idNodes[1]);
6253 pts[1] = idNodes[1];
6255 vtkUnstructuredGrid *ugrid =
6256 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6257 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6258 newugrid->SetPoints(ugrid->GetPoints());
6259 newugrid->InsertNextCell(VTK_LINE, 2, pts);
6261 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6262 Mapper->SetInput(newugrid);
6265 vtkActor *edge = vtkActor::New();
6266 edge->SetMapper(Mapper);
6267 edge->SetProperty(ac->GetProperty());
6268 edge->SetBackfaceProperty(ac->GetBackfaceProperty());
6269 edge->VisibilityOn();
6270 mySimulationActors->AddItem(edge);
6271 theRenderer->AddActor(edge);
6274 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6278 //=============================================================================
6282 //=============================================================================
6283 void SMESHGUI::DisplaySimulationTriangle(SMESH::SMESH_Mesh_ptr aMesh,
6284 const TColStd_MapOfInteger & MapIndex, bool reverse)
6286 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6289 EraseSimulationActors();
6290 mySimulationActors = vtkActorCollection::New();
6291 vtkRenderer *theRenderer =
6292 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6293 getRightFrame()->getViewFrame())->getRenderer();
6294 Standard_Boolean result;
6295 SMESH_Actor *ac = FindActor(aMesh, result, true);
6298 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6302 vtkIdList *Ids = vtkIdList::New();
6303 for (; ite.More(); ite.Next())
6305 idNodes[i] = ite.Key();
6311 Ids->InsertId(0, idNodes[2]);
6312 pts[0] = idNodes[2];
6313 Ids->InsertId(1, idNodes[1]);
6314 pts[1] = idNodes[1];
6315 Ids->InsertId(2, idNodes[0]);
6316 pts[2] = idNodes[0];
6320 Ids->InsertId(0, idNodes[0]);
6321 pts[0] = idNodes[0];
6322 Ids->InsertId(1, idNodes[1]);
6323 pts[1] = idNodes[1];
6324 Ids->InsertId(2, idNodes[2]);
6325 pts[2] = idNodes[2];
6327 vtkUnstructuredGrid *ugrid =
6328 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6329 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6330 newugrid->SetPoints(ugrid->GetPoints());
6331 newugrid->InsertNextCell(VTK_TRIANGLE, 3, pts);
6333 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6334 Mapper->SetInput(newugrid);
6337 vtkActor *tri = vtkActor::New();
6338 tri->SetMapper(Mapper);
6339 tri->SetProperty(ac->GetProperty());
6340 tri->SetBackfaceProperty(ac->GetBackfaceProperty());
6341 tri->VisibilityOn();
6342 mySimulationActors->AddItem(tri);
6343 theRenderer->AddActor(tri);
6346 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6350 //=============================================================================
6354 //=============================================================================
6355 void SMESHGUI::DisplaySimulationQuadrangle(SMESH::SMESH_Mesh_ptr aMesh,
6356 const TColStd_MapOfInteger & MapIndex, bool reverse)
6358 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6361 EraseSimulationActors();
6362 mySimulationActors = vtkActorCollection::New();
6363 vtkRenderer *theRenderer =
6364 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6365 getRightFrame()->getViewFrame())->getRenderer();
6366 Standard_Boolean result;
6367 SMESH_Actor *ac = FindActor(aMesh, result, true);
6369 vtkUnstructuredGrid *ugrid =
6370 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6374 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6377 vtkIdList *Ids = vtkIdList::New();
6378 for (; ite.More(); ite.Next())
6380 idNodes[i] = ite.Key();
6384 float *p0 = ugrid->GetPoint(idNodes[0]);
6385 float *p1 = ugrid->GetPoint(idNodes[1]);
6386 float *p2 = ugrid->GetPoint(idNodes[2]);
6387 float *p3 = ugrid->GetPoint(idNodes[3]);
6389 gp_Pnt P0(p0[0], p0[1], p0[2]);
6391 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6392 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6393 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6395 gp_Vec Cross1 = V1 ^ V2;
6396 gp_Vec Cross2 = V2 ^ V3;
6399 if (Cross1.Dot(Cross2) < 0)
6401 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6402 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6406 if (Cross1.Dot(Cross2) < 0)
6409 idNodes[2] = idNodes[3];
6415 idNodes[1] = idNodes[2];
6422 Ids->InsertId(0, idNodes[3]);
6423 Ids->InsertId(1, idNodes[2]);
6424 Ids->InsertId(2, idNodes[1]);
6425 Ids->InsertId(3, idNodes[0]);
6429 Ids->InsertId(0, idNodes[0]);
6430 Ids->InsertId(1, idNodes[1]);
6431 Ids->InsertId(2, idNodes[2]);
6432 Ids->InsertId(3, idNodes[3]);
6435 // vtkUnstructuredGrid* ugrid = vtkUnstructuredGrid::SafeDownCast( ac->DataSource );
6436 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6437 newugrid->SetPoints(ugrid->GetPoints());
6438 newugrid->InsertNextCell(VTK_QUAD, Ids);
6440 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6441 Mapper->SetInput(newugrid);
6444 vtkActor *quad = vtkActor::New();
6445 quad->SetMapper(Mapper);
6446 quad->SetProperty(ac->GetProperty());
6447 quad->SetBackfaceProperty(ac->GetBackfaceProperty());
6448 quad->VisibilityOn();
6449 mySimulationActors->AddItem(quad);
6450 theRenderer->AddActor(quad);
6452 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6456 //=============================================================================
6460 //=============================================================================
6461 void SMESHGUI::DisplaySimulationTetra(SMESH::SMESH_Mesh_ptr aMesh,
6462 const TColStd_MapOfInteger & MapIndex)
6464 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6467 EraseSimulationActors();
6468 mySimulationActors = vtkActorCollection::New();
6469 vtkRenderer *theRenderer =
6470 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6471 getRightFrame()->getViewFrame())->getRenderer();
6472 Standard_Boolean result;
6473 SMESH_Actor *ac = FindActor(aMesh, result, true);
6476 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6479 vtkIdList *Ids = vtkIdList::New();
6480 for (; ite.More(); ite.Next())
6482 idNodes[i] = ite.Key();
6486 Ids->InsertId(0, idNodes[0]);
6487 Ids->InsertId(1, idNodes[1]);
6488 Ids->InsertId(2, idNodes[2]);
6489 Ids->InsertId(3, idNodes[3]);
6491 vtkUnstructuredGrid *ugrid =
6492 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6493 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6494 newugrid->SetPoints(ugrid->GetPoints());
6495 newugrid->InsertNextCell(VTK_TETRA, Ids);
6497 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6498 Mapper->SetInput(newugrid);
6501 vtkActor *tetra = vtkActor::New();
6502 tetra->SetMapper(Mapper);
6503 tetra->SetProperty(ac->GetProperty());
6504 tetra->SetBackfaceProperty(ac->GetBackfaceProperty());
6505 tetra->VisibilityOn();
6506 mySimulationActors->AddItem(tetra);
6507 theRenderer->AddActor(tetra);
6509 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6513 //=============================================================================
6517 //=============================================================================
6518 void SMESHGUI::DisplaySimulationHexa(SMESH::SMESH_Mesh_ptr aMesh,
6519 const TColStd_MapOfInteger & MapIndex)
6521 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6524 EraseSimulationActors();
6525 mySimulationActors = vtkActorCollection::New();
6526 vtkRenderer *theRenderer =
6527 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6528 getRightFrame()->getViewFrame())->getRenderer();
6529 Standard_Boolean result;
6530 SMESH_Actor *ac = FindActor(aMesh, result, true);
6533 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6536 vtkIdList *Ids = vtkIdList::New();
6537 for (; ite.More(); ite.Next())
6539 idNodes[i] = ite.Key();
6543 Ids->InsertId(0, idNodes[0]);
6544 Ids->InsertId(1, idNodes[1]);
6545 Ids->InsertId(2, idNodes[2]);
6546 Ids->InsertId(3, idNodes[3]);
6547 Ids->InsertId(4, idNodes[4]);
6548 Ids->InsertId(5, idNodes[5]);
6549 Ids->InsertId(6, idNodes[6]);
6550 Ids->InsertId(7, idNodes[7]);
6552 vtkUnstructuredGrid *ugrid =
6553 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6554 vtkUnstructuredGrid *newugrid = vtkUnstructuredGrid::New();
6555 newugrid->SetPoints(ugrid->GetPoints());
6556 newugrid->InsertNextCell(VTK_HEXAHEDRON, Ids);
6558 vtkDataSetMapper *Mapper = vtkDataSetMapper::New();
6559 Mapper->SetInput(newugrid);
6562 vtkActor *hexa = vtkActor::New();
6563 hexa->SetMapper(Mapper);
6564 hexa->SetProperty(ac->GetProperty());
6565 hexa->SetBackfaceProperty(ac->GetBackfaceProperty());
6566 hexa->VisibilityOn();
6567 mySimulationActors->AddItem(hexa);
6568 theRenderer->AddActor(hexa);
6570 vtkRenderWindow *renWin = theRenderer->GetRenderWindow();
6574 //=============================================================================
6578 //=============================================================================
6579 void SMESHGUI::AddFace(SMESH::SMESH_Mesh_ptr aMesh,
6580 const TColStd_MapOfInteger & MapIndex, bool reverse)
6582 QApplication::setOverrideCursor(Qt::waitCursor);
6583 Standard_Boolean result;
6584 SMESH_Actor *ac = FindActor(aMesh, result, true);
6587 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6588 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6589 anArrayOfIdeces->length(MapIndex.Extent());
6592 for (; ite.More(); ite.Next())
6594 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6599 if (MapIndex.Extent() == 4)
6603 TColStd_MapIteratorOfMapOfInteger ite1(MapIndex);
6604 for (; ite1.More(); ite1.Next())
6606 idNodes[i] = ite1.Key();
6610 vtkUnstructuredGrid *ugrid =
6611 vtkUnstructuredGrid::SafeDownCast(ac->DataSource);
6612 float *p0 = ugrid->GetPoint(idNodes[0]);
6613 float *p1 = ugrid->GetPoint(idNodes[1]);
6614 float *p2 = ugrid->GetPoint(idNodes[2]);
6615 float *p3 = ugrid->GetPoint(idNodes[3]);
6617 gp_Pnt P0(p0[0], p0[1], p0[2]);
6619 gp_Vec V1(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6620 gp_Vec V2(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6621 gp_Vec V3(P0, gp_Pnt(p3[0], p3[1], p3[2]));
6623 gp_Vec Cross1 = V1 ^ V2;
6624 gp_Vec Cross2 = V2 ^ V3;
6626 if (Cross1.Dot(Cross2) < 0)
6629 V1 = gp_Vec(P0, gp_Pnt(p2[0], p2[1], p2[2]));
6630 V2 = gp_Vec(P0, gp_Pnt(p1[0], p1[1], p1[2]));
6634 if (Cross1.Dot(Cross2) < 0)
6636 tmp = anArrayOfIdeces[2];
6637 anArrayOfIdeces[2] = anArrayOfIdeces[3];
6638 anArrayOfIdeces[3] = tmp;
6642 tmp = anArrayOfIdeces[1];
6643 anArrayOfIdeces[1] = anArrayOfIdeces[2];
6644 anArrayOfIdeces[2] = tmp;
6652 for (i = 0; i < (MapIndex.Extent() / 2); i++)
6654 tmp = anArrayOfIdeces[i];
6655 anArrayOfIdeces[i] = anArrayOfIdeces[MapIndex.Extent() - i - 1];
6656 anArrayOfIdeces[MapIndex.Extent() - i - 1] = tmp;
6659 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6660 aMeshEditor->AddFace(anArrayOfIdeces);
6662 if (myAutomaticUpdate)
6664 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6667 smeshGUI->DisplayActor(Mesh);
6668 smeshGUI->DisplayEdges(Mesh);
6669 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6670 AddActorInSelection(Mesh);
6673 QApplication::restoreOverrideCursor();
6676 //=============================================================================
6680 //=============================================================================
6681 void SMESHGUI::AddVolume(SMESH::SMESH_Mesh_ptr aMesh,
6682 const TColStd_MapOfInteger & MapIndex)
6684 QApplication::setOverrideCursor(Qt::waitCursor);
6685 Standard_Boolean result;
6686 SMESH_Actor *ac = FindActor(aMesh, result, true);
6689 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6690 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6691 anArrayOfIdeces->length(MapIndex.Extent());
6694 for (; ite.More(); ite.Next())
6696 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6700 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6701 aMeshEditor->AddVolume(anArrayOfIdeces);
6703 if (myAutomaticUpdate)
6705 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6708 smeshGUI->DisplayActor(Mesh);
6709 smeshGUI->DisplayEdges(Mesh);
6710 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6711 AddActorInSelection(Mesh);
6714 QApplication::restoreOverrideCursor();
6717 //=============================================================================
6721 //=============================================================================
6722 void SMESHGUI::AddEdge(SMESH::SMESH_Mesh_ptr aMesh,
6723 const TColStd_MapOfInteger & MapIndex)
6725 QApplication::setOverrideCursor(Qt::waitCursor);
6726 Standard_Boolean result;
6727 SMESH_Actor *ac = FindActor(aMesh, result, true);
6730 TColStd_MapIteratorOfMapOfInteger ite(MapIndex);
6731 SMESH::long_array_var anArrayOfIdeces = new SMESH::long_array;
6732 anArrayOfIdeces->length(MapIndex.Extent());
6735 for (; ite.More(); ite.Next())
6737 anArrayOfIdeces[i] = ac->GetIdSMESHDSNode(ite.Key());
6741 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6742 aMeshEditor->AddEdge(anArrayOfIdeces);
6744 if (myAutomaticUpdate)
6746 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6749 smeshGUI->DisplayActor(Mesh);
6750 smeshGUI->DisplayEdges(Mesh);
6751 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6752 AddActorInSelection(Mesh);
6755 QApplication::restoreOverrideCursor();
6758 //=============================================================================
6762 //=============================================================================
6763 void SMESHGUI::AddNode(SMESH::SMESH_Mesh_ptr aMesh, float x, float y, float z)
6765 QApplication::setOverrideCursor(Qt::waitCursor);
6766 Standard_Boolean result;
6767 SMESH_Actor *ac = FindActor(aMesh, result, true);
6770 SMESH::SMESH_MeshEditor_var aMeshEditor = aMesh->GetMeshEditor();
6771 aMeshEditor->AddNode(x, y, z);
6773 if (myAutomaticUpdate)
6775 SMESH_Actor *Mesh = smeshGUI->ReadScript(aMesh);
6778 smeshGUI->DisplayActor(Mesh);
6779 smeshGUI->DisplayEdges(Mesh);
6780 smeshGUI->ChangeRepresentation(Mesh, Mesh->getDisplayMode());
6781 AddActorInSelection(Mesh);
6785 QApplication::restoreOverrideCursor();
6788 //=============================================================================
6792 //=============================================================================
6793 void SMESHGUI::DisplayEdgesConnectivityLegendBox(vtkActor * ac)
6795 if (myActiveStudy->getActiveStudyFrame()->getTypeView() != VIEW_VTK)
6798 EraseSimulationActors();
6799 mySimulationActors2D = vtkActor2DCollection::New();
6801 vtkRenderer *theRenderer =
6802 ((VTKViewer_ViewFrame *) myActiveStudy->getActiveStudyFrame()->
6803 getRightFrame()->getViewFrame())->getRenderer();
6805 vtkGlyphSource2D *gs2 = vtkGlyphSource2D::New();
6806 gs2->SetGlyphTypeToTriangle();
6809 vtkLegendBoxActor *legend = vtkLegendBoxActor::New();
6810 legend->GetPositionCoordinate()->SetValue(0.025, 0.025, 0.);
6811 legend->GetPosition2Coordinate()->SetValue(0.3, 0.3, 0.); //relative to Position
6813 legend->SetNumberOfEntries(4);
6814 legend->SetEntryString(0, tr("SMESH_BOUNDARYEDGES"));
6815 legend->SetEntrySymbol(0, gs2->GetOutput());
6816 legend->SetEntryColor(0, ac->GetMapper()->GetLookupTable()->GetColor(0.));
6817 legend->SetEntryString(1, tr("SMESH_MANIFOLDEDGES"));
6818 legend->SetEntrySymbol(1, gs2->GetOutput());
6819 legend->SetEntryColor(1,
6820 ac->GetMapper()->GetLookupTable()->GetColor(0.666667));
6821 legend->SetEntryString(2, tr("SMESH_NONMANIFOLDEDGES"));
6822 legend->SetEntrySymbol(2, gs2->GetOutput());
6823 legend->SetEntryColor(2,
6824 ac->GetMapper()->GetLookupTable()->GetColor(0.222222));
6825 legend->SetEntryString(3, tr("SMESH_FEATUREEDGES"));
6826 legend->SetEntrySymbol(3, gs2->GetOutput());
6827 legend->SetEntryColor(3,
6828 ac->GetMapper()->GetLookupTable()->GetColor(0.444444));
6829 legend->SetPadding(5);
6830 // legend->GetProperty()->SetColor();
6832 mySimulationActors2D->AddItem(legend);
6833 theRenderer->AddActor2D(legend);
6836 myActiveStudy->getActiveStudyFrame()->getRightFrame()->getViewFrame()->
6840 //===============================================================================
6841 // function : OnEditDelete()
6843 //===============================================================================
6844 void SMESHGUI::OnEditDelete()
6846 if (QAD_MessageBox::warn2
6847 (QAD_Application::getDesktop(),
6848 tr("SMESH_WRN_WARNING"),
6849 tr("SMESH_REALLY_DELETE"),
6850 tr("SMESH_BUT_YES"), tr("SMESH_BUT_NO"), 1, 0, 0) != 1)
6853 int nbSf = myActiveStudy->getStudyFramesCount();
6855 Standard_Boolean found;
6856 SALOMEDS::Study_var aStudy = myActiveStudy->getStudyDocument();
6857 SALOMEDS::StudyBuilder_var aStudyBuilder = myStudy->NewBuilder();
6858 SALOMEDS::GenericAttribute_var anAttr;
6859 SALOMEDS::AttributeIOR_var anIOR;
6861 SALOME_Selection *Sel =
6862 SALOME_Selection::Selection(myActiveStudy->getSelection());
6863 SALOME_ListIteratorOfListIO It(Sel->StoredIObjects());
6864 for (; It.More(); It.Next())
6866 Handle(SALOME_InteractiveObject) IObject = It.Value();
6867 if (IObject->hasEntry())
6869 SALOMEDS::SObject_var SO =
6870 myStudy->FindObjectID(IObject->getEntry());
6872 /* Erase child graphical objects */
6873 SALOMEDS::ChildIterator_var it = aStudy->NewChildIterator(SO);
6874 for (; it->More(); it->Next())
6876 SALOMEDS::SObject_var CSO = it->Value();
6877 if (CSO->FindAttribute(anAttr, "AttributeIOR"))
6879 anIOR = SALOMEDS::AttributeIOR::_narrow(anAttr);
6881 for (int i = 0; i < nbSf; i++)
6883 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6884 if (sf->getTypeView() == VIEW_VTK)
6886 vtkRenderer *Renderer =
6887 ((VTKViewer_ViewFrame *) smeshGUI->
6888 myActiveStudy->getActiveStudyFrame()->
6889 getRightFrame()->getViewFrame())->getRenderer();
6891 smeshGUI->FindActorByEntry(CSO->GetID(), found,
6895 Renderer->RemoveActor(ac->EdgeDevice);
6896 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6897 Renderer->RemoveActor(ac);
6904 /* Erase main graphical object */
6905 for (int i = 0; i < nbSf; i++)
6907 QAD_StudyFrame *sf = myActiveStudy->getStudyFrame(i);
6908 if (sf->getTypeView() == VIEW_VTK)
6910 vtkRenderer *Renderer =
6911 ((VTKViewer_ViewFrame *) smeshGUI->myActiveStudy->
6912 getActiveStudyFrame()->getRightFrame()->
6913 getViewFrame())->getRenderer();
6914 VTKViewer_RenderWindowInteractor *myRenderInter =
6915 ((VTKViewer_ViewFrame *) sf->getRightFrame()->
6916 getViewFrame())->getRWInteractor();
6918 smeshGUI->FindActorByEntry(IObject->getEntry(), found,
6922 Renderer->RemoveActor(ac->EdgeDevice);
6923 Renderer->RemoveActor(ac->EdgeShrinkDevice);
6925 myRenderInter->Remove(IObject);
6929 /* Erase objects in Study */
6930 SALOMEDS::SObject_var obj =
6931 myStudy->FindObjectID(IObject->getEntry());
6932 if (!obj->_is_nil())
6935 new SALOMEGUI_ImportOperation(myActiveStudy);
6937 aStudyBuilder->RemoveObject(obj);
6941 } /* IObject->hasEntry() */
6944 /* Clear any previous selection */
6945 Sel->ClearIObjects();
6946 myActiveStudy->updateObjBrowser();