1 // Copyright (C) 2007-2012 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.
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
25 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
27 #include "MeasureGUI_CheckSelfIntersectionsDlg.h"
28 #include "MeasureGUI_Widgets.h"
30 #include <SUIT_Session.h>
31 #include <SUIT_ResourceMgr.h>
32 #include <LightApp_SelectionMgr.h>
33 #include <SalomeApp_Tools.h>
34 #include <SalomeApp_Application.h>
36 #include <TopTools_IndexedMapOfShape.hxx>
38 #include <TColStd_MapOfInteger.hxx>
41 #include <GeometryGUI.h>
43 #include <GEOMImpl_Types.hxx>
45 #define TEXTEDIT_FONT_FAMILY "Courier"
46 #define TEXTEDIT_FONT_SIZE 11
48 //=================================================================================
49 // class : MeasureGUI_CheckSelfIntersectionsDlg()
50 // purpose : Constructs a MeasureGUI_CheckSelfIntersectionsDlg which is a child of 'parent', with the
51 // name 'name' and widget flags set to 'f'.
52 // The dialog will by default be modeless, unless you set 'modal' to
53 // true to construct a modal dialog.
54 //=================================================================================
55 MeasureGUI_CheckSelfIntersectionsDlg::MeasureGUI_CheckSelfIntersectionsDlg (GeometryGUI* GUI, QWidget* parent)
56 : MeasureGUI_Skeleton(GUI, parent, false)
58 SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
59 QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHECK_SELF_INTERSECTIONS")));
60 QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
62 setWindowTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
64 /***************************************************************/
65 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
66 mainFrame()->RadioButton1->setIcon(image0);
68 myGrp = new MeasureGUI_1Sel1TextView2ListBox (centralWidget());
69 myGrp->GroupBox1->setTitle(tr("GEOM_CHECK_INFOS"));
70 myGrp->TextLabel1->setText(tr("GEOM_OBJECT"));
72 myGrp->TextView1->setReadOnly(true);
73 QFont aFont (TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE);
74 aFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);
75 myGrp->TextView1->setFont(aFont);
77 myGrp->PushButton1->setIcon(image1);
78 myGrp->LineEdit1->setReadOnly(true);
80 myGrp->TextLabel2->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_ERRORS"));
81 myGrp->TextLabel3->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES"));
83 myGrp->ListBox2->setSelectionMode(QAbstractItemView::ExtendedSelection);
85 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
86 layout->setMargin(0); layout->setSpacing(6);
87 layout->addWidget(myGrp);
89 /***************************************************************/
91 myHelpFileName = "using_measurement_tools_page.html#check_self_intersections_anchor";
97 //=================================================================================
98 // function : ~MeasureGUI_CheckSelfIntersectionsDlg()
99 // purpose : Destroys the object and frees any allocated resources
100 //=================================================================================
101 MeasureGUI_CheckSelfIntersectionsDlg::~MeasureGUI_CheckSelfIntersectionsDlg()
105 //=================================================================================
108 //=================================================================================
109 void MeasureGUI_CheckSelfIntersectionsDlg::Init()
111 mySelBtn = myGrp->PushButton1;
112 mySelEdit = myGrp->LineEdit1;
113 MeasureGUI_Skeleton::Init();
115 connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), SLOT(onErrorsListSelectionChanged()));
116 connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), SLOT(onSubShapesListSelectionChanged()));
119 //=================================================================================
120 // function : processObject
122 //=================================================================================
123 void MeasureGUI_CheckSelfIntersectionsDlg::processObject()
125 myGrp->ListBox1->clear();
126 myGrp->ListBox2->clear();
129 if (myObj->_is_nil())
133 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
134 bool isGood = false, isFailed = false;
137 isGood = anOper->CheckSelfIntersections(myObj, myInters);
138 nbPairs = myInters->length()/2;
139 if (nbPairs*2 != myInters->length()) {
143 catch (const SALOME::SALOME_Exception& e) {
144 SalomeApp_Tools::QtCatchCorbaException(e);
148 aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED");
149 myGrp->TextView1->setText(aMsg);
155 aMsg += tr("GEOM_NO_SELF_INTERSECTIONS");
158 aMsg += tr("GEOM_SELF_INTERSECTIONS_FOUND");
160 myGrp->TextView1->setText(aMsg);
163 QStringList aErrList;
164 QString aErrStr ("");
165 for (int i = 1; i <= nbPairs; i++) {
166 aErrStr = "Intersection # ";
167 aErrStr += QString::number(i);
168 aErrList.append(aErrStr);
171 myGrp->ListBox1->addItems(aErrList);
174 //=================================================================================
175 // function : onErrorsListSelectionChanged
177 //=================================================================================
178 void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged()
181 int aCurItem = myGrp->ListBox1->currentRow();
185 //int nbPairs = myInters->length()/2;
187 QStringList aSubShapeList;
188 TopoDS_Shape aSelShape;
189 if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
190 TopTools_IndexedMapOfShape anIndices;
191 TopExp::MapShapes(aSelShape, anIndices);
193 TopoDS_Shape aSubShape = anIndices.FindKey(myInters[aCurItem*2]);
194 QString aType = GEOMBase::GetShapeTypeString(aSubShape);
195 if (!aType.isEmpty())
196 aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2]));
197 aSubShape = anIndices.FindKey(myInters[aCurItem*2 + 1]);
198 aType = GEOMBase::GetShapeTypeString(aSubShape);
199 if (!aType.isEmpty())
200 aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2 + 1]));
202 myGrp->ListBox2->clear();
203 myGrp->ListBox2->addItems(aSubShapeList);
206 //=================================================================================
207 // function : onSubShapesListSelectionChanged
209 //=================================================================================
210 void MeasureGUI_CheckSelfIntersectionsDlg::onSubShapesListSelectionChanged()
215 int aErrCurItem = myGrp->ListBox1->currentRow();
221 for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) {
222 if (myGrp->ListBox2->item(i)->isSelected())
225 if (aIds.count() < 1)
228 TopoDS_Shape aSelShape;
229 TopoDS_Shape aSubShape;
230 TopTools_IndexedMapOfShape anIndices;
231 if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
232 SALOME_Prs* aPrs = 0;
233 TopExp::MapShapes(aSelShape, anIndices);
234 QList<int>::iterator it;
235 for (it = aIds.begin(); it != aIds.end(); ++it) {
236 aSubShape = anIndices.FindKey(myInters[aErrCurItem*2 + (*it)]);
238 getDisplayer()->SetColor(Quantity_NOC_RED);
239 getDisplayer()->SetWidth(3);
240 getDisplayer()->SetToActivate(false);
241 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0;
243 displayPreview(aPrs, true);
245 catch (const SALOME::SALOME_Exception& e) {
246 SalomeApp_Tools::QtCatchCorbaException(e);