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
22 // GEOM GEOMGUI : GUI for Geometry component
23 // File : MeasureGUI_CheckSelfIntersectionsDlg.cxx
25 #include "MeasureGUI_CheckSelfIntersectionsDlg.h"
26 #include "MeasureGUI_Widgets.h"
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>
34 #include <TopTools_IndexedMapOfShape.hxx>
36 #include <TColStd_MapOfInteger.hxx>
39 #include <GeometryGUI.h>
41 #include <GEOMImpl_Types.hxx>
43 #define TEXTEDIT_FONT_FAMILY "Courier"
44 #define TEXTEDIT_FONT_SIZE 11
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)
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")));
60 setWindowTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
62 /***************************************************************/
63 mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
64 mainFrame()->RadioButton1->setIcon(image0);
66 myGrp = new MeasureGUI_1Sel1TextView2ListBox (centralWidget());
67 myGrp->GroupBox1->setTitle(tr("GEOM_CHECK_INFOS"));
68 myGrp->TextLabel1->setText(tr("GEOM_OBJECT"));
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);
75 myGrp->PushButton1->setIcon(image1);
76 myGrp->LineEdit1->setReadOnly(true);
78 myGrp->TextLabel2->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_ERRORS"));
79 myGrp->TextLabel3->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES"));
81 myGrp->ListBox2->setSelectionMode(QAbstractItemView::ExtendedSelection);
83 QVBoxLayout* layout = new QVBoxLayout (centralWidget());
84 layout->setMargin(0); layout->setSpacing(6);
85 layout->addWidget(myGrp);
87 /***************************************************************/
89 myHelpFileName = "using_measurement_tools_page.html#check_self_intersections_anchor";
95 //=================================================================================
96 // function : ~MeasureGUI_CheckSelfIntersectionsDlg()
97 // purpose : Destroys the object and frees any allocated resources
98 //=================================================================================
99 MeasureGUI_CheckSelfIntersectionsDlg::~MeasureGUI_CheckSelfIntersectionsDlg()
103 //=================================================================================
106 //=================================================================================
107 void MeasureGUI_CheckSelfIntersectionsDlg::Init()
109 mySelBtn = myGrp->PushButton1;
110 mySelEdit = myGrp->LineEdit1;
111 MeasureGUI_Skeleton::Init();
113 connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), SLOT(onErrorsListSelectionChanged()));
114 connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), SLOT(onSubShapesListSelectionChanged()));
117 //=================================================================================
118 // function : processObject
120 //=================================================================================
121 void MeasureGUI_CheckSelfIntersectionsDlg::processObject()
123 myGrp->ListBox1->clear();
124 myGrp->ListBox2->clear();
127 if (myObj->_is_nil())
131 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
132 bool isGood = false, isFailed = false;
135 isGood = anOper->CheckSelfIntersections(myObj, myInters);
136 nbPairs = myInters->length()/2;
137 if (nbPairs*2 != myInters->length()) {
141 catch (const SALOME::SALOME_Exception& e) {
142 SalomeApp_Tools::QtCatchCorbaException(e);
146 if (!anOper->IsDone()) {
147 aMsg += tr(anOper->GetErrorCode());
148 myGrp->TextView1->setText(aMsg);
152 aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED");
153 myGrp->TextView1->setText(aMsg);
159 aMsg += tr("GEOM_NO_SELF_INTERSECTIONS");
162 aMsg += tr("GEOM_SELF_INTERSECTIONS_FOUND");
164 myGrp->TextView1->setText(aMsg);
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);
175 myGrp->ListBox1->addItems(aErrList);
178 //=================================================================================
179 // function : onErrorsListSelectionChanged
181 //=================================================================================
182 void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged()
185 int aCurItem = myGrp->ListBox1->currentRow();
189 //int nbPairs = myInters->length()/2;
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);
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]));
206 myGrp->ListBox2->clear();
207 myGrp->ListBox2->addItems(aSubShapeList);
210 //=================================================================================
211 // function : onSubShapesListSelectionChanged
213 //=================================================================================
214 void MeasureGUI_CheckSelfIntersectionsDlg::onSubShapesListSelectionChanged()
219 int aErrCurItem = myGrp->ListBox1->currentRow();
225 for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) {
226 if (myGrp->ListBox2->item(i)->isSelected())
229 if (aIds.count() < 1)
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)]);
242 getDisplayer()->SetColor(Quantity_NOC_RED);
243 getDisplayer()->SetWidth(3);
244 getDisplayer()->SetToActivate(false);
245 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0;
247 displayPreview(aPrs, true);
249 catch (const SALOME::SALOME_Exception& e) {
250 SalomeApp_Tools::QtCatchCorbaException(e);