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