1 // Copyright (C) 2007-2014 CEA/DEN, EDF R&D, OPEN CASCADE
3 // Copyright (C) 2003-2007 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, or (at your option) any later version.
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.salome-platform.org/ or email : webmaster.salome@opencascade.com
23 // GEOM GEOMGUI : GUI for Geometry component
24 // File : MeasureGUI_CheckSelfIntersectionsDlg.cxx
26 #include "MeasureGUI_CheckSelfIntersectionsDlg.h"
27 #include "MeasureGUI_Widgets.h"
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>
35 #include <TopTools_IndexedMapOfShape.hxx>
37 #include <TColStd_MapOfInteger.hxx>
40 #include <GeometryGUI.h>
42 #include <GEOMImpl_Types.hxx>
44 #define TEXTEDIT_FONT_FAMILY "Courier"
45 #define TEXTEDIT_FONT_SIZE 11
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)
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")));
61 setWindowTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
63 /***************************************************************/
64 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
65 mainFrame()->RadioButton1->setIcon(image0);
67 myGrp = new MeasureGUI_1Sel1TextView2ListBox (centralWidget());
68 myGrp->GroupBox1->setTitle(tr("GEOM_CHECK_INFOS"));
69 myGrp->TextLabel1->setText(tr("GEOM_OBJECT"));
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);
76 myGrp->PushButton1->setIcon(image1);
77 myGrp->LineEdit1->setReadOnly(true);
79 myGrp->TextLabel2->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_ERRORS"));
80 myGrp->TextLabel3->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES"));
82 myGrp->ListBox2->setSelectionMode(QAbstractItemView::ExtendedSelection);
84 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
85 layout->setMargin(0); layout->setSpacing(6);
86 layout->addWidget(myGrp);
88 /***************************************************************/
90 myHelpFileName = "check_self_intersections_page.html";
96 //=================================================================================
97 // function : ~MeasureGUI_CheckSelfIntersectionsDlg()
98 // purpose : Destroys the object and frees any allocated resources
99 //=================================================================================
100 MeasureGUI_CheckSelfIntersectionsDlg::~MeasureGUI_CheckSelfIntersectionsDlg()
104 //=================================================================================
107 //=================================================================================
108 void MeasureGUI_CheckSelfIntersectionsDlg::Init()
110 mySelBtn = myGrp->PushButton1;
111 mySelEdit = myGrp->LineEdit1;
112 MeasureGUI_Skeleton::Init();
114 connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), SLOT(onErrorsListSelectionChanged()));
115 connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), SLOT(onSubShapesListSelectionChanged()));
118 //=================================================================================
119 // function : processObject
121 //=================================================================================
122 void MeasureGUI_CheckSelfIntersectionsDlg::processObject()
124 myGrp->ListBox1->clear();
125 myGrp->ListBox2->clear();
128 if (myObj->_is_nil())
132 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
133 bool isGood = false, isFailed = false;
136 isGood = anOper->CheckSelfIntersections(myObj, myInters);
137 nbPairs = myInters->length()/2;
138 if (nbPairs*2 != myInters->length()) {
142 catch (const SALOME::SALOME_Exception& e) {
143 SalomeApp_Tools::QtCatchCorbaException(e);
147 if (!anOper->IsDone() && myInters->length() == 0) {
148 aMsg += tr(anOper->GetErrorCode());
149 myGrp->TextView1->setText(aMsg);
153 aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED");
154 myGrp->TextView1->setText(aMsg);
160 aMsg += tr("GEOM_NO_SELF_INTERSECTIONS");
163 aMsg += tr("GEOM_SELF_INTERSECTIONS_FOUND");
166 if (!anOper->IsDone()) {
168 aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_ERRORS");
171 myGrp->TextView1->setText(aMsg);
174 QStringList aErrList;
175 QString aErrStr ("");
176 for (int i = 1; i <= nbPairs; i++) {
177 aErrStr = "Intersection # ";
178 aErrStr += QString::number(i);
179 aErrList.append(aErrStr);
182 myGrp->ListBox1->addItems(aErrList);
185 //=================================================================================
186 // function : onErrorsListSelectionChanged
188 //=================================================================================
189 void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged()
192 int aCurItem = myGrp->ListBox1->currentRow();
196 //int nbPairs = myInters->length()/2;
198 QStringList aSubShapeList;
199 TopoDS_Shape aSelShape;
200 if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
201 TopTools_IndexedMapOfShape anIndices;
202 TopExp::MapShapes(aSelShape, anIndices);
204 TopoDS_Shape aSubShape = anIndices.FindKey(myInters[aCurItem*2]);
205 QString aType = GEOMBase::GetShapeTypeString(aSubShape);
206 if (!aType.isEmpty())
207 aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2]));
208 aSubShape = anIndices.FindKey(myInters[aCurItem*2 + 1]);
209 aType = GEOMBase::GetShapeTypeString(aSubShape);
210 if (!aType.isEmpty())
211 aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2 + 1]));
213 myGrp->ListBox2->clear();
214 myGrp->ListBox2->addItems(aSubShapeList);
217 //=================================================================================
218 // function : onSubShapesListSelectionChanged
220 //=================================================================================
221 void MeasureGUI_CheckSelfIntersectionsDlg::onSubShapesListSelectionChanged()
226 int aErrCurItem = myGrp->ListBox1->currentRow();
232 for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) {
233 if (myGrp->ListBox2->item(i)->isSelected())
236 if (aIds.count() < 1)
239 TopoDS_Shape aSelShape;
240 TopoDS_Shape aSubShape;
241 TopTools_IndexedMapOfShape anIndices;
242 if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
243 SALOME_Prs* aPrs = 0;
244 TopExp::MapShapes(aSelShape, anIndices);
245 QList<int>::iterator it;
246 for (it = aIds.begin(); it != aIds.end(); ++it) {
247 aSubShape = anIndices.FindKey(myInters[aErrCurItem*2 + (*it)]);
249 getDisplayer()->SetColor(Quantity_NOC_RED);
250 getDisplayer()->SetWidth(3);
251 getDisplayer()->SetToActivate(false);
252 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0;
254 displayPreview(aPrs, true);
256 catch (const SALOME::SALOME_Exception& e) {
257 SalomeApp_Tools::QtCatchCorbaException(e);