]> SALOME platform Git repositories - modules/geom.git/blob - src/MeasureGUI/MeasureGUI_CheckSelfIntersectionsDlg.cxx
Salome HOME
EDF 2281 : Add 2 primitives for hexa mesh
[modules/geom.git] / src / MeasureGUI / MeasureGUI_CheckSelfIntersectionsDlg.cxx
1 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
2 //
3 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
5 //
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.
10 //
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.
15 //
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
19 //
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File   : MeasureGUI_CheckSelfIntersectionsDlg.cxx
24
25 #include "MeasureGUI_CheckSelfIntersectionsDlg.h"
26 #include "MeasureGUI_Widgets.h"
27
28 #include <SUIT_Session.h>
29 #include <SUIT_ResourceMgr.h>
30 #include <LightApp_SelectionMgr.h>
31 #include <SalomeApp_Tools.h>
32 #include <SalomeApp_Application.h>
33
34 #include <TopTools_IndexedMapOfShape.hxx>
35 #include <TopExp.hxx>
36 #include <TColStd_MapOfInteger.hxx>
37
38 #include <DlgRef.h>
39 #include <GeometryGUI.h>
40 #include <GEOMBase.h>
41 #include <GEOMImpl_Types.hxx>
42
43 #define TEXTEDIT_FONT_FAMILY "Courier"
44 #define TEXTEDIT_FONT_SIZE 11
45
46 //=================================================================================
47 // class    : MeasureGUI_CheckSelfIntersectionsDlg()
48 // purpose  : Constructs a MeasureGUI_CheckSelfIntersectionsDlg which is a child of 'parent', with the
49 //            name 'name' and widget flags set to 'f'.
50 //            The dialog will by default be modeless, unless you set 'modal' to
51 //            true to construct a modal dialog.
52 //=================================================================================
53 MeasureGUI_CheckSelfIntersectionsDlg::MeasureGUI_CheckSelfIntersectionsDlg (GeometryGUI* GUI, QWidget* parent)
54   : MeasureGUI_Skeleton(GUI, parent, false)
55 {
56   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
57   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHECK_SELF_INTERSECTIONS")));
58   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
59
60   setWindowTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
61
62   /***************************************************************/
63   mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
64   mainFrame()->RadioButton1->setIcon(image0);
65
66   myGrp = new MeasureGUI_1Sel1TextView2ListBox (centralWidget());
67   myGrp->GroupBox1->setTitle(tr("GEOM_CHECK_INFOS"));
68   myGrp->TextLabel1->setText(tr("GEOM_OBJECT"));
69
70   myGrp->TextView1->setReadOnly(true);
71   QFont aFont (TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE);
72   aFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);
73   myGrp->TextView1->setFont(aFont);
74
75   myGrp->PushButton1->setIcon(image1);
76   myGrp->LineEdit1->setReadOnly(true);
77
78   myGrp->TextLabel2->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_ERRORS"));
79   myGrp->TextLabel3->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES"));
80
81   myGrp->ListBox2->setSelectionMode(QAbstractItemView::ExtendedSelection);
82
83   QVBoxLayout* layout = new QVBoxLayout (centralWidget());
84   layout->setMargin(0); layout->setSpacing(6);
85   layout->addWidget(myGrp);
86
87   /***************************************************************/
88
89   myHelpFileName = "using_measurement_tools_page.html#check_self_intersections_anchor";
90
91   /* Initialisation */
92   Init();
93 }
94
95 //=================================================================================
96 // function : ~MeasureGUI_CheckSelfIntersectionsDlg()
97 // purpose  : Destroys the object and frees any allocated resources
98 //=================================================================================
99 MeasureGUI_CheckSelfIntersectionsDlg::~MeasureGUI_CheckSelfIntersectionsDlg()
100 {
101 }
102
103 //=================================================================================
104 // function : Init()
105 // purpose  :
106 //=================================================================================
107 void MeasureGUI_CheckSelfIntersectionsDlg::Init()
108 {
109   mySelBtn = myGrp->PushButton1;
110   mySelEdit = myGrp->LineEdit1;
111   MeasureGUI_Skeleton::Init();
112
113   connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), SLOT(onErrorsListSelectionChanged()));
114   connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), SLOT(onSubShapesListSelectionChanged()));
115 }
116
117 //=================================================================================
118 // function : processObject
119 // purpose  :
120 //=================================================================================
121 void MeasureGUI_CheckSelfIntersectionsDlg::processObject()
122 {
123   myGrp->ListBox1->clear();
124   myGrp->ListBox2->clear();
125   erasePreview();
126
127   if (myObj->_is_nil())
128     return;
129
130   QString aMsg ("");
131   GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
132   bool isGood = false, isFailed = false;
133   int nbPairs = 0;
134   try {
135     isGood = anOper->CheckSelfIntersections(myObj, myInters);
136     nbPairs = myInters->length()/2;
137     if (nbPairs*2 != myInters->length()) {
138       isFailed = true;
139     }
140   }
141   catch (const SALOME::SALOME_Exception& e) {
142     SalomeApp_Tools::QtCatchCorbaException(e);
143     isFailed = true;
144   }
145
146   if (!anOper->IsDone()) {
147     aMsg += tr(anOper->GetErrorCode());
148     myGrp->TextView1->setText(aMsg);
149     return;
150   }
151   else if (isFailed) {
152     aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED");
153     myGrp->TextView1->setText(aMsg);
154     return;
155   }
156
157   // Status
158   if (isGood) {
159     aMsg += tr("GEOM_NO_SELF_INTERSECTIONS");
160   }
161   else {
162     aMsg += tr("GEOM_SELF_INTERSECTIONS_FOUND");
163   }
164   myGrp->TextView1->setText(aMsg);
165
166   // Pairs
167   QStringList aErrList;
168   QString aErrStr ("");
169   for (int i = 1; i <= nbPairs; i++) {
170     aErrStr = "Intersection # ";
171     aErrStr += QString::number(i);
172     aErrList.append(aErrStr);
173   }
174
175   myGrp->ListBox1->addItems(aErrList);
176 }
177
178 //=================================================================================
179 // function : onErrorsListSelectionChanged
180 // purpose  :
181 //=================================================================================
182 void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged()
183 {
184   erasePreview();
185   int aCurItem = myGrp->ListBox1->currentRow();
186   if (aCurItem < 0)
187     return;
188
189   //int nbPairs = myInters->length()/2;
190
191   QStringList aSubShapeList;
192   TopoDS_Shape aSelShape;
193   if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
194     TopTools_IndexedMapOfShape anIndices;
195     TopExp::MapShapes(aSelShape, anIndices);
196
197     TopoDS_Shape aSubShape = anIndices.FindKey(myInters[aCurItem*2]);
198     QString aType = GEOMBase::GetShapeTypeString(aSubShape);
199     if (!aType.isEmpty())
200       aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2]));
201     aSubShape = anIndices.FindKey(myInters[aCurItem*2 + 1]);
202     aType = GEOMBase::GetShapeTypeString(aSubShape);
203     if (!aType.isEmpty())
204       aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2 + 1]));
205   }
206   myGrp->ListBox2->clear();
207   myGrp->ListBox2->addItems(aSubShapeList);
208 }
209
210 //=================================================================================
211 // function : onSubShapesListSelectionChanged
212 // purpose  :
213 //=================================================================================
214 void MeasureGUI_CheckSelfIntersectionsDlg::onSubShapesListSelectionChanged()
215 {
216   erasePreview();
217
218   // Current pair
219   int aErrCurItem = myGrp->ListBox1->currentRow();
220   if (aErrCurItem < 0)
221     return;
222
223   // Selected IDs
224   QList<int> aIds;
225   for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) {
226     if (myGrp->ListBox2->item(i)->isSelected())
227       aIds.append(i);
228   }
229   if (aIds.count() < 1)
230     return;
231
232   TopoDS_Shape aSelShape;
233   TopoDS_Shape aSubShape;
234   TopTools_IndexedMapOfShape anIndices;
235   if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
236     SALOME_Prs* aPrs = 0;
237     TopExp::MapShapes(aSelShape, anIndices);
238     QList<int>::iterator it;
239     for (it = aIds.begin(); it != aIds.end(); ++it) {
240       aSubShape = anIndices.FindKey(myInters[aErrCurItem*2 + (*it)]);
241       try {
242         getDisplayer()->SetColor(Quantity_NOC_RED);
243         getDisplayer()->SetWidth(3);
244         getDisplayer()->SetToActivate(false);
245         aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0;
246         if (aPrs)
247           displayPreview(aPrs, true);
248       }
249       catch (const SALOME::SALOME_Exception& e) {
250         SalomeApp_Tools::QtCatchCorbaException(e);
251       }
252     }
253   }
254 }