1 // Copyright (C) 2007-2015 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_CheckShapeDlg.cxx
25 // Author : Nicolas REJNERI, Open CASCADE S.A.S.
27 #include "MeasureGUI.h"
28 #include "MeasureGUI_CheckShapeDlg.h"
29 #include "MeasureGUI_Widgets.h"
31 #include <GeometryGUI.h>
33 #include <GEOMImpl_Types.hxx>
35 #include <SUIT_Session.h>
36 #include <SUIT_ResourceMgr.h>
37 #include <SalomeApp_Tools.h>
38 #include <SalomeApp_Application.h>
39 #include <LightApp_SelectionMgr.h>
41 #include <TColStd_IndexedMapOfInteger.hxx>
42 #include <TColStd_MapOfInteger.hxx>
43 #include <TopTools_IndexedMapOfShape.hxx>
46 #define TEXTEDIT_FONT_FAMILY "Courier"
47 #define TEXTEDIT_FONT_SIZE 11
49 //=================================================================================
50 // class : MeasureGUI_CheckShapeDlg()
51 // purpose : Constructs a MeasureGUI_CheckShapeDlg which is a child of 'parent', with the
52 // name 'name' and widget flags set to 'f'.
53 // The dialog will by default be modeless, unless you set 'modal' to
54 // true to construct a modal dialog.
55 //=================================================================================
56 MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg( GeometryGUI* GUI, QWidget* parent )
57 : GEOMBase_Skeleton( GUI, parent, false )
59 QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap(
60 "GEOM", tr( "ICON_DLG_CHECKSHAPE" ) ) );
61 QPixmap image1( SUIT_Session::session()->resourceMgr()->loadPixmap(
62 "GEOM", tr( "ICON_SELECT" ) ) );
64 setWindowTitle( tr( "GEOM_CHECK_TITLE" ) );
66 /***************************************************************/
68 mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_SHAPE" ) );
69 mainFrame()->RadioButton1->setIcon( image0 );
70 mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose );
71 mainFrame()->RadioButton2->close();
72 mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose );
73 mainFrame()->RadioButton3->close();
75 myGrp = new MeasureGUI_1Sel1Check1TextView2ListBox( centralWidget() );
76 myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) );
77 myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) );
78 myGrp->TextView1->setReadOnly( true );
80 QFont aFont( TEXTEDIT_FONT_FAMILY, TEXTEDIT_FONT_SIZE );
81 aFont.setStyleHint( QFont::TypeWriter, QFont::PreferAntialias );
82 myGrp->TextView1->setFont( aFont );
83 myGrp->PushButton1->setIcon( image1 );
84 myGrp->LineEdit1->setReadOnly( true );
86 myGrp->TextLabel2->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ) );
87 myGrp->TextLabel3->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ) );
89 myGrp->ListBox2->setSelectionMode( QAbstractItemView::ExtendedSelection );
91 QVBoxLayout* layout = new QVBoxLayout( centralWidget() );
92 layout->setMargin( 0 ); layout->setSpacing( 6 );
93 layout->addWidget( myGrp );
95 connect( myGrp->ListBox1, SIGNAL( itemSelectionChanged() ), SLOT( onErrorsListSelectionChanged() ) );
96 connect( myGrp->ListBox2, SIGNAL( itemSelectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) );
98 /***************************************************************/
100 myHelpFileName = "check_shape_page.html";
106 //=================================================================================
107 // function : ~MeasureGUI_CheckShapeDlg()
108 // purpose : Destroys the object and frees any allocated resources
109 //=================================================================================
110 MeasureGUI_CheckShapeDlg::~MeasureGUI_CheckShapeDlg()
115 //=================================================================================
118 //=================================================================================
119 void MeasureGUI_CheckShapeDlg::Init()
121 // signals and slots connections
122 connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) );
123 connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) );
125 connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) );
127 connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ),
128 this, SLOT( SelectionIntoArgument() ) );
130 connect( myGrp->CheckBox1, SIGNAL( toggled( bool) ),
131 this, SLOT( SelectionIntoArgument() ) );
133 initName( tr( "GEOM_CHECK_SHAPE_NAME") );
134 buttonOk()->setEnabled( false );
135 buttonApply()->setEnabled( false );
137 SelectionIntoArgument();
140 //=================================================================================
141 // function : ClickOnOk()
143 //=================================================================================
144 void MeasureGUI_CheckShapeDlg::ClickOnOk()
146 if ( ClickOnApply() )
150 //=================================================================================
151 // function : ClickOnApply()
153 //=================================================================================
154 bool MeasureGUI_CheckShapeDlg::ClickOnApply()
163 //=================================================================================
164 // function : SelectionIntoArgument
166 //=================================================================================
167 bool MeasureGUI_CheckShapeDlg::extractPrefix() const
172 //=================================================================================
173 // function : SelectionIntoArgument
175 //=================================================================================
176 void MeasureGUI_CheckShapeDlg::SelectionIntoArgument()
179 myObj = GEOM::GEOM_Object::_nil();
181 LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr();
182 SALOME_ListIO aSelList;
183 aSelMgr->selectedObjects(aSelList);
185 if (aSelList.Extent() != 1) {
186 myGrp->LineEdit1->setText( "" );
191 GEOM::GEOM_Object_var aSelectedObject =
192 GEOMBase::ConvertIOinGEOMObject( aSelList.First() );
194 if ( aSelectedObject->_is_nil() ) {
195 myGrp->LineEdit1->setText( "" );
200 myObj = aSelectedObject;
201 myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) );
203 DISPLAY_PREVIEW_MACRO;
206 //=================================================================================
207 // function : SetEditCurrentArgument
209 //=================================================================================
210 void MeasureGUI_CheckShapeDlg::SetEditCurrentArgument()
212 myGrp->LineEdit1->setFocus();
213 SelectionIntoArgument();
216 //=================================================================================
217 // function : ActivateThisDialog()
219 //=================================================================================
220 void MeasureGUI_CheckShapeDlg::ActivateThisDialog()
222 GEOMBase_Skeleton::ActivateThisDialog();
224 LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr();
226 connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) );
229 DISPLAY_PREVIEW_MACRO
232 //=================================================================================
233 // function : activateSelection
234 // purpose : activate selection of faces, shells, and solids
235 //=================================================================================
236 void MeasureGUI_CheckShapeDlg::activateSelection()
238 globalSelection( GEOM_ALLSHAPES );
241 //=================================================================================
242 // function : enterEvent()
244 //=================================================================================
245 void MeasureGUI_CheckShapeDlg::enterEvent( QEvent* )
247 if ( !mainFrame()->GroupConstructors->isEnabled() )
248 ActivateThisDialog();
251 //=================================================================================
252 // function : isValid
254 //=================================================================================
255 bool MeasureGUI_CheckShapeDlg::isValid( QString& )
257 return !myObj->_is_nil();
260 //=================================================================================
261 // function : getErrors
263 //=================================================================================
264 bool MeasureGUI_CheckShapeDlg::getErrors
266 GEOM::GEOM_IMeasureOperations::ShapeErrors& theErrors )
268 if ( myObj->_is_nil() ) {
271 GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() );
273 GEOM::GEOM_IMeasureOperations::ShapeErrors_var aErrs;
274 bool isCheckGeometry = myGrp->CheckBox1->isChecked();
275 if ( isCheckGeometry )
276 theIsValid = anOper->CheckShapeWithGeometry( myObj, aErrs );
278 theIsValid = anOper->CheckShape( myObj, aErrs );
280 if (anOper->IsDone() && aErrs->length() > 0)
283 catch( const SALOME::SALOME_Exception& e ) {
284 SalomeApp_Tools::QtCatchCorbaException( e );
288 return anOper->IsDone();
293 //=================================================================================
294 // function : processObject
296 //=================================================================================
297 void MeasureGUI_CheckShapeDlg::processObject()
300 GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs;
302 if ( !getErrors( isShapeValid, aErrs ) ) {
303 myGrp->TextView1->setText( "" );
304 myGrp->ListBox1->clear();
305 myGrp->ListBox2->clear();
311 if ( isShapeValid ) {
312 myGrp->TextView1->setText(tr("GEOM_CHECK_SHAPE_VALID"));
313 buttonOk()->setEnabled( false );
314 buttonApply()->setEnabled( false );
316 myGrp->TextView1->setText(tr("GEOM_CHECK_SHAPE_NOT_VALID"));
317 buttonOk()->setEnabled( true );
318 buttonApply()->setEnabled( true );
322 QStringList aErrList;
324 for ( int i = 0, n = aErrs.length(); i < n; i++ ) {
325 QString aErrStr("CHECK_ERROR_");
327 switch ( aErrs[i].error ) {
328 case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve:
329 aErrStr += "INVALID_POINT_ON_CURVE";
331 case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface:
332 aErrStr += "INVALID_POINT_ON_CURVE_ON_SURFACE";
334 case GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface:
335 aErrStr += "INVALID_POINT_ON_SURFACE";
337 case GEOM::GEOM_IMeasureOperations::No3DCurve:
338 aErrStr += "NO_3D_CURVE";
340 case GEOM::GEOM_IMeasureOperations::Multiple3DCurve:
341 aErrStr += "MULTIPLE_3D_CURVE";
343 case GEOM::GEOM_IMeasureOperations::Invalid3DCurve:
344 aErrStr += "INVALID_3D_CURVE";
346 case GEOM::GEOM_IMeasureOperations::NoCurveOnSurface:
347 aErrStr += "NO_CURVE_ON_SURFACE";
349 case GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface:
350 aErrStr += "INVALID_CURVE_ON_SURFACE";
352 case GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface:
353 aErrStr += "INVALID_CURVE_ON_CLOSED_SURFACE";
355 case GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag:
356 aErrStr += "INVALID_SAME_RANGE_FLAG";
358 case GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag:
359 aErrStr += "INVALID_SAME_PARAMETER_FLAG";
361 case GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag:
362 aErrStr += "INVALID_DEGENERATED_FLAG";
364 case GEOM::GEOM_IMeasureOperations::FreeEdge:
365 aErrStr += "FREE_EDGE";
367 case GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity:
368 aErrStr += "INVALID_MULTI_CONNEXITY";
370 case GEOM::GEOM_IMeasureOperations::InvalidRange:
371 aErrStr += "INVALID_RANGE";
373 case GEOM::GEOM_IMeasureOperations::EmptyWire:
374 aErrStr += "EMPTY_WIRE";
376 case GEOM::GEOM_IMeasureOperations::RedundantEdge:
377 aErrStr += "REDUNDANT_EDGE";
379 case GEOM::GEOM_IMeasureOperations::SelfIntersectingWire:
380 aErrStr += "SELF_INTERSECTING_WIRE";
382 case GEOM::GEOM_IMeasureOperations::NoSurface:
383 aErrStr += "NO_SURFACE";
385 case GEOM::GEOM_IMeasureOperations::InvalidWire:
386 aErrStr += "INVALID_WIRE";
388 case GEOM::GEOM_IMeasureOperations::RedundantWire:
389 aErrStr += "REDUNDANT_WIRE";
391 case GEOM::GEOM_IMeasureOperations::IntersectingWires:
392 aErrStr += "INTERSECTING_WIRES";
394 case GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires:
395 aErrStr += "INVALID_IMBRICATION_OF_WIRES";
397 case GEOM::GEOM_IMeasureOperations::EmptyShell:
398 aErrStr += "EMPTY_SHELL";
400 case GEOM::GEOM_IMeasureOperations::RedundantFace:
401 aErrStr += "REDUNDANT_FACE";
403 case GEOM::GEOM_IMeasureOperations::UnorientableShape:
404 aErrStr += "UNORIENTABLE_SHAPE";
406 case GEOM::GEOM_IMeasureOperations::NotClosed:
407 aErrStr += "NOT_CLOSED";
409 case GEOM::GEOM_IMeasureOperations::NotConnected:
410 aErrStr += "NOT_CONNECTED";
412 case GEOM::GEOM_IMeasureOperations::SubshapeNotInShape:
413 aErrStr += "SUBSHAPE_NOT_IN_SHAPE";
415 case GEOM::GEOM_IMeasureOperations::BadOrientation:
416 aErrStr += "BAD_ORIENTATION";
418 case GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape:
419 aErrStr += "BAD_ORIENTATION_OF_SUBSHAPE";
421 case GEOM::GEOM_IMeasureOperations::InvalidToleranceValue:
422 aErrStr += "INVALID_TOLERANCE_VALUE";
424 case GEOM::GEOM_IMeasureOperations::CheckFail:
425 aErrStr += "CHECK_FAIL";
432 if (!aErrStr.isEmpty()) {
433 aErrList.append(tr(aErrStr.toLatin1().constData()));
437 myGrp->ListBox1->clear();
438 myGrp->ListBox2->clear();
439 myGrp->ListBox1->addItems( aErrList );
442 //=================================================================================
443 // function : createOperation
445 //=================================================================================
446 GEOM::GEOM_IOperations_ptr MeasureGUI_CheckShapeDlg::createOperation()
448 return getGeomEngine()->GetIMeasureOperations( getStudyId() );
451 //=================================================================================
452 // function : onErrorsListSelectionChanged
454 //=================================================================================
455 void MeasureGUI_CheckShapeDlg::onErrorsListSelectionChanged()
459 int aCurItem = myGrp->ListBox1->currentRow();
461 if ( aCurItem < 0 ) {
466 GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs;
468 if ( !getErrors( isShapeValid, aErrs ) ) {
469 myGrp->TextView1->setText( "" );
470 myGrp->ListBox1->clear();
471 myGrp->ListBox2->clear();
476 myGrp->ListBox2->clear();
478 if (aCurItem < aErrs.length()) {
479 GEOM::GEOM_IMeasureOperations::ShapeError aErr = aErrs[aCurItem];
480 GEOM::ListOfLong aObjLst = aErr.incriminated;
481 QStringList aSubShapeList;
482 TopoDS_Shape aSelShape;
484 if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) {
485 TopTools_IndexedMapOfShape anIndices;
487 TopExp::MapShapes( aSelShape, anIndices );
489 for ( int i = 0, n = aObjLst.length(); i < n; i++ ) {
490 TopoDS_Shape aSubShape = anIndices.FindKey( aObjLst[i] );
491 QString aType = GEOMBase::GetShapeTypeString( aSubShape );
493 if ( !aType.isEmpty() ) {
494 aSubShapeList.append( QString( "%1_%2" ).arg( aType ).arg( aObjLst[i] ) );
499 myGrp->ListBox2->addItems( aSubShapeList );
503 //=================================================================================
504 // function : onSubShapesListSelectionChanged
506 //=================================================================================
507 void MeasureGUI_CheckShapeDlg::onSubShapesListSelectionChanged()
511 int aErrCurItem = myGrp->ListBox1->currentRow();
513 if (aErrCurItem < 0) {
519 for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) {
520 if (myGrp->ListBox2->item( i )->isSelected()) {
525 if (aIds.count() < 1) {
530 GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs;
532 if (!getErrors(isShapeValid, aErrs)) {
533 myGrp->TextView1->setText("");
534 myGrp->ListBox1->clear();
535 myGrp->ListBox2->clear();
540 GEOM::GEOM_IMeasureOperations::ShapeError aErr = aErrs[aErrCurItem];
541 GEOM::ListOfLong aObjLst = aErr.incriminated;
542 TopoDS_Shape aSelShape;
543 TopoDS_Shape aSubShape;
544 TopTools_IndexedMapOfShape anIndices;
546 if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) {
549 if (!isValid(aMess)) {
553 SALOME_Prs* aPrs = 0;
554 QList<int>::iterator it;
556 TopExp::MapShapes(aSelShape, anIndices);
558 for (it = aIds.begin(); it != aIds.end(); ++it) {
559 SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr();
560 int w = resMgr->integerValue("Geometry", "measures_line_width", 1);
562 aSubShape = anIndices.FindKey(aObjLst[(*it)]);
565 getDisplayer()->SetColor( Quantity_NOC_RED );
566 getDisplayer()->SetWidth( w );
567 getDisplayer()->SetToActivate( false );
568 aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0;
571 displayPreview(aPrs, true);
574 catch (const SALOME::SALOME_Exception& e) {
575 SalomeApp_Tools::QtCatchCorbaException(e);
581 //=================================================================================
582 // function : execute
584 //=================================================================================
585 bool MeasureGUI_CheckShapeDlg::execute( ObjectList& objects )
588 GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs;
590 if (!getErrors(isShapeValid, aErrs)) {
594 const int aNbErrsSelected = myGrp->ListBox1->selectedItems().size();
595 const bool isPublishAllErrors = (aNbErrsSelected < 1);
596 const bool isPublishAllShapes =
597 (aNbErrsSelected != 1 || myGrp->ListBox2->selectedItems().empty());
598 TColStd_IndexedMapOfInteger aMapIndex;
599 const int aNbErrs = aErrs.length();
602 // Collect indices of shapes to be published.
603 for (i = 0; i < aNbErrs; i++) {
604 if (isPublishAllErrors || myGrp->ListBox1->item(i)->isSelected()) {
605 GEOM::ListOfLong aObjLst = aErrs[i].incriminated;
606 const int aNbShapes = aObjLst.length();
609 for (j = 0; j < aNbShapes; j++) {
610 if (isPublishAllShapes || myGrp->ListBox2->item(j)->isSelected()) {
611 aMapIndex.Add(aObjLst[j]);
618 GEOM::ListOfLong_var anArray = new GEOM::ListOfLong;
619 const int aNbShapes = aMapIndex.Extent();
621 anArray->length(aNbShapes);
623 for (i = 1; i <= aNbShapes; i++) {
624 anArray[i - 1] = aMapIndex.FindKey(i);
627 if (myShapesOper->_is_nil()) {
628 myShapesOper = getGeomEngine()->GetIShapesOperations(getStudyId());
631 GEOM::ListOfGO_var aList = myShapesOper->MakeSubShapes(myObj, anArray);
632 const int aNbObj = aList->length();
634 for (i = 0; i < aNbObj; i++) {
635 objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i]));