Back to index

salome-geom  6.5.0
MeasureGUI_CheckSelfIntersectionsDlg.cxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 // This library is free software; you can redistribute it and/or
00007 // modify it under the terms of the GNU Lesser General Public
00008 // License as published by the Free Software Foundation; either
00009 // version 2.1 of the License.
00010 //
00011 // This library is distributed in the hope that it will be useful,
00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 // Lesser General Public License for more details.
00015 //
00016 // You should have received a copy of the GNU Lesser General Public
00017 // License along with this library; if not, write to the Free Software
00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 
00023 // GEOM GEOMGUI : GUI for Geometry component
00024 // File   : MeasureGUI_CheckSelfIntersectionsDlg.cxx
00025 // Author : Vladimir KLYACHIN, Open CASCADE S.A.S. (vladimir.klyachin@opencascade.com)
00026 
00027 #include "MeasureGUI_CheckSelfIntersectionsDlg.h"
00028 #include "MeasureGUI_Widgets.h"
00029 
00030 #include <SUIT_Session.h>
00031 #include <SUIT_ResourceMgr.h>
00032 #include <LightApp_SelectionMgr.h>
00033 #include <SalomeApp_Tools.h>
00034 #include <SalomeApp_Application.h>
00035 
00036 #include <TopTools_IndexedMapOfShape.hxx>
00037 #include <TopExp.hxx>
00038 #include <TColStd_MapOfInteger.hxx>
00039 
00040 #include <DlgRef.h>
00041 #include <GeometryGUI.h>
00042 #include <GEOMBase.h>
00043 #include <GEOMImpl_Types.hxx>
00044 
00045 #define TEXTEDIT_FONT_FAMILY "Courier"
00046 #define TEXTEDIT_FONT_SIZE 11
00047 
00048 //=================================================================================
00049 // class    : MeasureGUI_CheckSelfIntersectionsDlg()
00050 // purpose  : Constructs a MeasureGUI_CheckSelfIntersectionsDlg which is a child of 'parent', with the
00051 //            name 'name' and widget flags set to 'f'.
00052 //            The dialog will by default be modeless, unless you set 'modal' to
00053 //            true to construct a modal dialog.
00054 //=================================================================================
00055 MeasureGUI_CheckSelfIntersectionsDlg::MeasureGUI_CheckSelfIntersectionsDlg (GeometryGUI* GUI, QWidget* parent)
00056   : MeasureGUI_Skeleton(GUI, parent, false)
00057 {
00058   SUIT_ResourceMgr* aResMgr = SUIT_Session::session()->resourceMgr();
00059   QPixmap image0 (aResMgr->loadPixmap("GEOM", tr("ICON_DLG_CHECK_SELF_INTERSECTIONS")));
00060   QPixmap image1 (aResMgr->loadPixmap("GEOM", tr("ICON_SELECT")));
00061 
00062   setWindowTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
00063 
00064   /***************************************************************/
00065   mainFrame()->GroupConstructors->setTitle(tr("GEOM_CHECK_SELF_INTERSECTIONS"));
00066   mainFrame()->RadioButton1->setIcon(image0);
00067 
00068   myGrp = new MeasureGUI_1Sel1TextView2ListBox (centralWidget());
00069   myGrp->GroupBox1->setTitle(tr("GEOM_CHECK_INFOS"));
00070   myGrp->TextLabel1->setText(tr("GEOM_OBJECT"));
00071 
00072   myGrp->TextView1->setReadOnly(true);
00073   QFont aFont (TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE);
00074   aFont.setStyleHint(QFont::TypeWriter, QFont::PreferAntialias);
00075   myGrp->TextView1->setFont(aFont);
00076 
00077   myGrp->PushButton1->setIcon(image1);
00078   myGrp->LineEdit1->setReadOnly(true);
00079 
00080   myGrp->TextLabel2->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_ERRORS"));
00081   myGrp->TextLabel3->setText(tr("GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES"));
00082 
00083   myGrp->ListBox2->setSelectionMode(QAbstractItemView::ExtendedSelection);
00084 
00085   QVBoxLayout* layout = new QVBoxLayout (centralWidget());
00086   layout->setMargin(0); layout->setSpacing(6);
00087   layout->addWidget(myGrp);
00088 
00089   /***************************************************************/
00090 
00091   myHelpFileName = "using_measurement_tools_page.html#check_self_intersections_anchor";
00092 
00093   /* Initialisation */
00094   Init();
00095 }
00096 
00097 //=================================================================================
00098 // function : ~MeasureGUI_CheckSelfIntersectionsDlg()
00099 // purpose  : Destroys the object and frees any allocated resources
00100 //=================================================================================
00101 MeasureGUI_CheckSelfIntersectionsDlg::~MeasureGUI_CheckSelfIntersectionsDlg()
00102 {
00103 }
00104 
00105 //=================================================================================
00106 // function : Init()
00107 // purpose  :
00108 //=================================================================================
00109 void MeasureGUI_CheckSelfIntersectionsDlg::Init()
00110 {
00111   mySelBtn = myGrp->PushButton1;
00112   mySelEdit = myGrp->LineEdit1;
00113   MeasureGUI_Skeleton::Init();
00114 
00115   connect(myGrp->ListBox1, SIGNAL(itemSelectionChanged()), SLOT(onErrorsListSelectionChanged()));
00116   connect(myGrp->ListBox2, SIGNAL(itemSelectionChanged()), SLOT(onSubShapesListSelectionChanged()));
00117 }
00118 
00119 //=================================================================================
00120 // function : processObject
00121 // purpose  :
00122 //=================================================================================
00123 void MeasureGUI_CheckSelfIntersectionsDlg::processObject()
00124 {
00125   myGrp->ListBox1->clear();
00126   myGrp->ListBox2->clear();
00127   erasePreview();
00128 
00129   if (myObj->_is_nil())
00130     return;
00131 
00132   QString aMsg ("");
00133   GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow(getOperation());
00134   bool isGood = false, isFailed = false;
00135   int nbPairs = 0;
00136   try {
00137     isGood = anOper->CheckSelfIntersections(myObj, myInters);
00138     nbPairs = myInters->length()/2;
00139     if (nbPairs*2 != myInters->length()) {
00140       isFailed = true;
00141     }
00142   }
00143   catch (const SALOME::SALOME_Exception& e) {
00144     SalomeApp_Tools::QtCatchCorbaException(e);
00145     isFailed = true;
00146   }
00147   if (isFailed) {
00148     aMsg += tr("GEOM_CHECK_SELF_INTERSECTIONS_FAILED");
00149     myGrp->TextView1->setText(aMsg);
00150     return;
00151   }
00152 
00153   // Status
00154   if (isGood) {
00155     aMsg += tr("GEOM_NO_SELF_INTERSECTIONS");
00156   }
00157   else {
00158     aMsg += tr("GEOM_SELF_INTERSECTIONS_FOUND");
00159   }
00160   myGrp->TextView1->setText(aMsg);
00161 
00162   // Pairs
00163   QStringList aErrList;
00164   QString aErrStr ("");
00165   for (int i = 1; i <= nbPairs; i++) {
00166     aErrStr = "Intersection # ";
00167     aErrStr += QString::number(i);
00168     aErrList.append(aErrStr);
00169   }
00170 
00171   myGrp->ListBox1->addItems(aErrList);
00172 }
00173 
00174 //=================================================================================
00175 // function : onErrorsListSelectionChanged
00176 // purpose  :
00177 //=================================================================================
00178 void MeasureGUI_CheckSelfIntersectionsDlg::onErrorsListSelectionChanged()
00179 {
00180   erasePreview();
00181   int aCurItem = myGrp->ListBox1->currentRow();
00182   if (aCurItem < 0)
00183     return;
00184 
00185   //int nbPairs = myInters->length()/2;
00186 
00187   QStringList aSubShapeList;
00188   TopoDS_Shape aSelShape;
00189   if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
00190     TopTools_IndexedMapOfShape anIndices;
00191     TopExp::MapShapes(aSelShape, anIndices);
00192 
00193     TopoDS_Shape aSubShape = anIndices.FindKey(myInters[aCurItem*2]);
00194     QString aType = GEOMBase::GetShapeTypeString(aSubShape);
00195     if (!aType.isEmpty())
00196       aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2]));
00197     aSubShape = anIndices.FindKey(myInters[aCurItem*2 + 1]);
00198     aType = GEOMBase::GetShapeTypeString(aSubShape);
00199     if (!aType.isEmpty())
00200       aSubShapeList.append(QString("%1_%2").arg(aType).arg(myInters[aCurItem*2 + 1]));
00201   }
00202   myGrp->ListBox2->clear();
00203   myGrp->ListBox2->addItems(aSubShapeList);
00204 }
00205 
00206 //=================================================================================
00207 // function : onSubShapesListSelectionChanged
00208 // purpose  :
00209 //=================================================================================
00210 void MeasureGUI_CheckSelfIntersectionsDlg::onSubShapesListSelectionChanged()
00211 {
00212   erasePreview();
00213 
00214   // Current pair
00215   int aErrCurItem = myGrp->ListBox1->currentRow();
00216   if (aErrCurItem < 0)
00217     return;
00218 
00219   // Selected IDs
00220   QList<int> aIds;
00221   for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) {
00222     if (myGrp->ListBox2->item(i)->isSelected())
00223       aIds.append(i);
00224   }
00225   if (aIds.count() < 1)
00226     return;
00227 
00228   TopoDS_Shape aSelShape;
00229   TopoDS_Shape aSubShape;
00230   TopTools_IndexedMapOfShape anIndices;
00231   if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
00232     SALOME_Prs* aPrs = 0;
00233     TopExp::MapShapes(aSelShape, anIndices);
00234     QList<int>::iterator it;
00235     for (it = aIds.begin(); it != aIds.end(); ++it) {
00236       aSubShape = anIndices.FindKey(myInters[aErrCurItem*2 + (*it)]);
00237       try {
00238         getDisplayer()->SetColor(Quantity_NOC_RED);
00239         getDisplayer()->SetWidth(3);
00240         getDisplayer()->SetToActivate(false);
00241         aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0;
00242         if (aPrs)
00243           displayPreview(aPrs, true);
00244       }
00245       catch (const SALOME::SALOME_Exception& e) {
00246         SalomeApp_Tools::QtCatchCorbaException(e);
00247       }
00248     }
00249   }
00250 }