From: skv Date: Fri, 4 Apr 2014 06:44:39 +0000 (+0400) Subject: 0022373: EDF 2691 GEOM: Publish the shapes with error in Check Shape X-Git-Tag: V7_4_0a1~1 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=6833ee2b3e774239b93e4d3ea1b2c3c9dfde61d3;p=modules%2Fgeom.git 0022373: EDF 2691 GEOM: Publish the shapes with error in Check Shape --- diff --git a/doc/salome/examples/check_shape.py b/doc/salome/examples/check_shape.py index 30793345e..a0e728967 100644 --- a/doc/salome/examples/check_shape.py +++ b/doc/salome/examples/check_shape.py @@ -8,8 +8,9 @@ geompy = geomBuilder.New(salome.myStudy) # create a box box = geompy.MakeBoxDXDYDZ(100,30,100) -IsValid = geompy.CheckShape(box) +(IsValid, err) = geompy.CheckShape(box, 0, 2) if IsValid == 0: + geompy.PrintShapeError(box, err) raise RuntimeError, "Invalid box created" else: print "\nBox is valid" diff --git a/doc/salome/gui/GEOM/images/measures9.png b/doc/salome/gui/GEOM/images/measures9.png index 38a29bb17..c5d7d331d 100755 Binary files a/doc/salome/gui/GEOM/images/measures9.png and b/doc/salome/gui/GEOM/images/measures9.png differ diff --git a/doc/salome/gui/GEOM/input/check_shape.doc b/doc/salome/gui/GEOM/input/check_shape.doc index 9ffbf5b9a..2d5e1dd37 100644 --- a/doc/salome/gui/GEOM/input/check_shape.doc +++ b/doc/salome/gui/GEOM/input/check_shape.doc @@ -6,10 +6,35 @@ True if it is valid. Check also geometry checkbox allows to test the geometry as well. -\n Result: Boolean. -\n TUI Command: geompy.CheckShape(theShape, theIsCheckGeom = 0), -where \em theShape is the shape checked for validity. - +\n Result: Boolean; highlight in the viewer. +\n TUI Commands: + See also a \ref tui_check_shape_page "TUI example". \image html measures9.png diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 9950494cb..ecf0308db 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -4002,23 +4002,104 @@ module GEOM out double EdgeMin, out double EdgeMax, out double VertMin, out double VertMax); + /*! + * \brief Enumeration of Shape defects coming from CheckShape algorithms. + */ + enum ShapeErrorType + { + /* for vertices */ + InvalidPointOnCurve, + InvalidPointOnCurveOnSurface, + InvalidPointOnSurface, + + /* for edges */ + No3DCurve, + Multiple3DCurve, + Invalid3DCurve, + NoCurveOnSurface, + InvalidCurveOnSurface, + InvalidCurveOnClosedSurface, + InvalidSameRangeFlag, + InvalidSameParameterFlag, + InvalidDegeneratedFlag, + + FreeEdge, + InvalidMultiConnexity, + InvalidRange, + + /* for wires */ + EmptyWire, + RedundantEdge, + SelfIntersectingWire, /* on a face */ + + /* for faces */ + NoSurface, + InvalidWire, + RedundantWire, + IntersectingWires, + InvalidImbricationOfWires, + + /* for shells */ + EmptyShell, + RedundantFace, + + /* for shapes */ + UnorientableShape, + NotClosed, + NotConnected, + + SubshapeNotInShape, + + BadOrientation, + BadOrientationOfSubshape, + + InvalidToleranceValue, + + /* for exception */ + CheckFail + }; + + /*! + * \brief Description of a shape defect: type and incriminated sub-shapes. + */ + struct ShapeError + { + ShapeErrorType error; + ListOfLong incriminated; + }; + + /*! + * \brief Sequence of all shape defects. + */ + typedef sequence ShapeErrors; + /*! * \brief Check a topology of the given shape. * \param theShape Shape to check validity of. - * \param theDescription Output. Description of problems in the shape, if they are. + * \param theErrors Structure, containing discovered errors and incriminated sub-shapes. * \return TRUE, if the shape "seems to be valid" from the topological point of view. */ - boolean CheckShape (in GEOM_Object theShape, - out string theDescription); + boolean CheckShape (in GEOM_Object theShape, + out ShapeErrors theErrors); /*! * \brief Check a topology and a geometry of the given shape. * \param theShape Shape to check validity of. - * \param theDescription Output. Description of problems in the shape, if they are. + * \param theErrors Structure, containing discovered errors and incriminated sub-shapes. * \return TRUE, if the shape "seems to be valid". */ - boolean CheckShapeWithGeometry (in GEOM_Object theShape, - out string theDescription); + boolean CheckShapeWithGeometry (in GEOM_Object theShape, + out ShapeErrors theErrors); + + /*! + * \brief Convert sequence of shape errors, returned by + * CheckShape() or CheckShapeWithGeometry(), into string. + * \param theShape the invalid shape. + * \param theErrors The sequence of \a theShape errors. + * \return String, describing all the errors in form, suitable for printing. + */ + string PrintShapeErrors (in GEOM_Object theShape, + in ShapeErrors theErrors); /*! * \brief Check a topology of the given shape on self-intersections presence. diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index 35cf49d7f..797c629ff 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -375,6 +375,26 @@ Please, select face, shell or solid and try again GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES Incriminated Sub-shapes + + GEOM_CHECK_BLOCKS_NOT_BLOCK + Not a Block + + + GEOM_CHECK_BLOCKS_EXTRA_EDGE + Extra Edge + + + GEOM_CHECK_BLOCKS_INVALID_CONNECTION + Invalid Connection # %1 + + + GEOM_CHECK_BLOCKS_NOT_CONNECTED + Not Connected + + + GEOM_CHECK_BLOCKS_NOT_GLUED + Not Glued # %1 + GEOM_GETNONBLOCKS_TITLE Get non-hexahedral solids and non-quadrangular faces @@ -391,14 +411,6 @@ Please, select face, shell or solid and try again GEOM_CHECK_INFOS Object And Its Topological Information - - GEOM_CHECK_SHAPE - Check Shape - - - GEOM_CHECK_TITLE - Check Shape Information - GEOM_CHECK_SELF_INTERSECTIONS Detect Self-intersections @@ -6314,6 +6326,161 @@ Do you want to continue? Please specify suitable arguments. + + MeasureGUI_CheckShapeDlg + + GEOM_CHECK_TITLE + Check Shape Information + + + GEOM_CHECK_SHAPE + Check Shape + + + GEOM_CHECK_SHAPE_NAME + Faulty + + + GEOM_CHECK_SHAPE_VALID + This Shape seems to be valid + + + GEOM_CHECK_SHAPE_NOT_VALID + This Shape has errors: + + + CHECK_ERROR_INVALID_POINT_ON_CURVE + Invalid Point on Curve + + + CHECK_ERROR_INVALID_POINT_ON_CURVE_ON_SURFACE + Invalid Point on Curve on Surface + + + CHECK_ERROR_INVALID_POINT_ON_SURFACE + Invalid Point on Surface + + + CHECK_ERROR_NO_3D_CURVE + No 3D Curve + + + CHECK_ERROR_MULTIPLE_3D_CURVE + Multiple 3D Curve + + + CHECK_ERROR_INVALID_3D_CURVE + Invalid 3D Curve + + + CHECK_ERROR_NO_CURVE_ON_SURFACE + No Curve on Surface + + + CHECK_ERROR_INVALID_CURVE_ON_SURFACE + Invalid Curve on Surface + + + CHECK_ERROR_INVALID_CURVE_ON_CLOSED_SURFACE + Invalid Curve on Closed Surface + + + CHECK_ERROR_INVALID_SAME_RANGE_FLAG + Invalid Same Range Flag + + + CHECK_ERROR_INVALID_SAME_PARAMETER_FLAG + Invalid Same Parameter Flag + + + CHECK_ERROR_INVALID_DEGENERATED_FLAG + Invalid Degenerated Flag + + + CHECK_ERROR_FREE_EDGE + Free Edge + + + CHECK_ERROR_INVALID_MULTI_CONNEXITY + Invalid Multi Connexity + + + CHECK_ERROR_INVALID_RANGE + Invalid Range + + + CHECK_ERROR_EMPTY_WIRE + Empty Wire + + + CHECK_ERROR_REDUNDANT_EDGE + Redundant Edge + + + CHECK_ERROR_SELF_INTERSECTING_WIRE + Self-Intersecting Wire + + + CHECK_ERROR_NO_SURFACE + No Surface + + + CHECK_ERROR_INVALID_WIRE + Invalid Wire + + + CHECK_ERROR_REDUNDANT_WIRE + Redundant Wire + + + CHECK_ERROR_INTERSECTING_WIRES + Intersecting Wires + + + CHECK_ERROR_INVALID_IMBRICATION_OF_WIRES + Invalid Imbrication of Wires + + + CHECK_ERROR_EMPTY_SHELL + Empty Shell + + + CHECK_ERROR_REDUNDANT_FACE + Redundant Face + + + CHECK_ERROR_UNORIENTABLE_SHAPE + Unorientable Shape + + + CHECK_ERROR_NOT_CLOSED + Not Closed + + + CHECK_ERROR_NOT_CONNECTED + Not Connected + + + CHECK_ERROR_SUBSHAPE_NOT_IN_SHAPE + Subshape not in Shape + + + CHECK_ERROR_BAD_ORIENTATION + Bad Orientation + + + CHECK_ERROR_BAD_ORIENTATION_OF_SUBSHAPE + Bad Orientation of Subshape + + + CHECK_ERROR_INVALID_TOLERANCE_VALUE + Invalid Tolerance Value + + + CHECK_ERROR_CHECK_FAIL + Check Fail + + OperationGUI_ChamferDlg diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx index 5a191cd6b..bc7111cb2 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.cxx @@ -20,96 +20,56 @@ // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // -#include - #include - -#include -#include #include -#include +#include +#include #include -#include +#include +#include #include -#include #include -#include - #include -#include -#include // OCCT Includes -#include -#include -#include -#include - +#include +#include +#include +#include +#include #include -#include -#include -#include -#include #include -#include +#include #include -#include #include #include #include #include #include #include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include +#include +#include #include #include - -#include - -#include -#include - #include #include - #include #include - -#include -#include - -#include -#include -#include -#include -#include -#include - -#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC //============================================================================= @@ -1298,11 +1258,12 @@ void GEOMImpl_IMeasureOperations::GetTolerance * CheckShape */ //============================================================================= -bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape, - const Standard_Boolean theIsCheckGeom, - TCollection_AsciiString& theDump) +bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape, + const Standard_Boolean theIsCheckGeom, + std::list &theErrors) { SetErrorCode(KO); + theErrors.clear(); if (theShape.IsNull()) return false; @@ -1323,10 +1284,9 @@ bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape, #endif BRepCheck_Analyzer ana (aShape, theIsCheckGeom); if (ana.IsValid()) { - theDump.Clear(); isValid = true; } else { - StructuralDump(ana, aShape, theDump); + FillErrors(ana, aShape, theErrors); } } catch (Standard_Failure) { @@ -1339,6 +1299,223 @@ bool GEOMImpl_IMeasureOperations::CheckShape (Handle(GEOM_Object) theShape, return isValid; } +//============================================================================= +/*! + * PrintShapeErrors + */ +//============================================================================= +TCollection_AsciiString GEOMImpl_IMeasureOperations::PrintShapeErrors + (Handle(GEOM_Object) theShape, + const std::list &theErrors) +{ + TCollection_AsciiString aDump; + + if (theShape.IsNull()) { + return aDump; + } + + Handle(GEOM_Function) aRefShape = theShape->GetLastFunction(); + + if (aRefShape.IsNull()) { + return aDump; + } + + TopoDS_Shape aShape = aRefShape->GetValue(); + + if (aShape.IsNull()) { + SetErrorCode("The Objects has NULL Shape"); + return aDump; + } + + if (!theErrors.empty()) { + // The shape is not valid. Prepare errors for dump. + TopTools_IndexedMapOfShape anIndices; + std::list::const_iterator anIter = theErrors.begin(); + Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo; + nbv = nbe = nbw = nbf = nbs = nbo = 0; + + // Map sub-shapes and their indices + TopExp::MapShapes(aShape, anIndices); + + const Standard_Integer aNbSubShapes = anIndices.Extent(); + TColStd_MapOfInteger aMapPbInd; + + aDump += " -- The Shape has problems :\n"; + aDump += " Check Count\n"; + aDump += " ------------------------------------------------\n"; + + for (; anIter != theErrors.end(); anIter++) { + Standard_Integer aNbShapes = anIter->incriminated.size(); + + switch(anIter->error) { + case BRepCheck_InvalidPointOnCurve: + aDump += " Invalid Point on Curve ................... "; + break; + case BRepCheck_InvalidPointOnCurveOnSurface: + aDump += " Invalid Point on CurveOnSurface .......... "; + break; + case BRepCheck_InvalidPointOnSurface: + aDump += " Invalid Point on Surface ................. "; + break; + case BRepCheck_No3DCurve: + aDump += " No 3D Curve .............................. "; + break; + case BRepCheck_Multiple3DCurve: + aDump += " Multiple 3D Curve ........................ "; + break; + case BRepCheck_Invalid3DCurve: + aDump += " Invalid 3D Curve ......................... "; + break; + case BRepCheck_NoCurveOnSurface: + aDump += " No Curve on Surface ...................... "; + break; + case BRepCheck_InvalidCurveOnSurface: + aDump += " Invalid Curve on Surface ................. "; + break; + case BRepCheck_InvalidCurveOnClosedSurface: + aDump += " Invalid Curve on closed Surface .......... "; + break; + case BRepCheck_InvalidSameRangeFlag: + aDump += " Invalid SameRange Flag ................... "; + break; + case BRepCheck_InvalidSameParameterFlag: + aDump += " Invalid SameParameter Flag ............... "; + break; + case BRepCheck_InvalidDegeneratedFlag: + aDump += " Invalid Degenerated Flag ................. "; + break; + case BRepCheck_FreeEdge: + aDump += " Free Edge ................................ "; + break; + case BRepCheck_InvalidMultiConnexity: + aDump += " Invalid MultiConnexity ................... "; + break; + case BRepCheck_InvalidRange: + aDump += " Invalid Range ............................ "; + break; + case BRepCheck_EmptyWire: + aDump += " Empty Wire ............................... "; + break; + case BRepCheck_RedundantEdge: + aDump += " Redundant Edge ........................... "; + break; + case BRepCheck_SelfIntersectingWire: + aDump += " Self Intersecting Wire ................... "; + break; + case BRepCheck_NoSurface: + aDump += " No Surface ............................... "; + break; + case BRepCheck_InvalidWire: + aDump += " Invalid Wire ............................. "; + break; + case BRepCheck_RedundantWire: + aDump += " Redundant Wire ........................... "; + break; + case BRepCheck_IntersectingWires: + aDump += " Intersecting Wires ....................... "; + break; + case BRepCheck_InvalidImbricationOfWires: + aDump += " Invalid Imbrication of Wires ............. "; + break; + case BRepCheck_EmptyShell: + aDump += " Empty Shell .............................. "; + break; + case BRepCheck_RedundantFace: + aDump += " Redundant Face ........................... "; + break; + case BRepCheck_UnorientableShape: + aDump += " Unorientable Shape ....................... "; + break; + case BRepCheck_NotClosed: + aDump += " Not Closed ............................... "; + break; + case BRepCheck_NotConnected: + aDump += " Not Connected ............................ "; + break; + case BRepCheck_SubshapeNotInShape: + aDump += " Sub-shape not in Shape ................... "; + break; + case BRepCheck_BadOrientation: + aDump += " Bad Orientation .......................... "; + break; + case BRepCheck_BadOrientationOfSubshape: + aDump += " Bad Orientation of Sub-shape ............. "; + break; + case BRepCheck_InvalidToleranceValue: + aDump += " Invalid Tolerance Value .................. "; + break; + case BRepCheck_CheckFail: + aDump += " Check Shape Failure ...................... "; + break; + default: + break; + } + + aDump += TCollection_AsciiString(aNbShapes) + "\n"; + + // Count types of shape. + std::list::const_iterator aShIter = anIter->incriminated.begin(); + + for (; aShIter != anIter->incriminated.end(); aShIter++) { + const Standard_Integer anIndex = *aShIter; + + if (anIndex > 0 && anIndex <= aNbSubShapes && aMapPbInd.Add(anIndex)) { + const TopoDS_Shape &aSubShape = anIndices.FindKey(anIndex); + const TopAbs_ShapeEnum aType = aSubShape.ShapeType(); + + switch (aType) { + case TopAbs_VERTEX : nbv++; break; + case TopAbs_EDGE : nbe++; break; + case TopAbs_WIRE : nbw++; break; + case TopAbs_FACE : nbf++; break; + case TopAbs_SHELL : nbs++; break; + case TopAbs_SOLID : nbo++; break; + default : break; + } + } + } + } + + const Standard_Integer aNbFaultyShapes = nbv + nbe + nbw + nbf + nbs + nbo; + aDump += " ------------------------------------------------\n"; + aDump += "*** Shapes with problems : "; + aDump += TCollection_AsciiString(aNbFaultyShapes) + "\n"; + + if (nbv > 0) { + aDump += "VERTEX : "; + if (nbv < 10) aDump += " "; + aDump += TCollection_AsciiString(nbv) + "\n"; + } + if (nbe > 0) { + aDump += "EDGE : "; + if (nbe < 10) aDump += " "; + aDump += TCollection_AsciiString(nbe) + "\n"; + } + if (nbw > 0) { + aDump += "WIRE : "; + if (nbw < 10) aDump += " "; + aDump += TCollection_AsciiString(nbw) + "\n"; + } + if (nbf > 0) { + aDump += "FACE : "; + if (nbf < 10) aDump += " "; + aDump += TCollection_AsciiString(nbf) + "\n"; + } + if (nbs > 0) { + aDump += "SHELL : "; + if (nbs < 10) aDump += " "; + aDump += TCollection_AsciiString(nbs) + "\n"; + } + if (nbo > 0) { + aDump += "SOLID : "; + if (nbo < 10) aDump += " "; + aDump += TCollection_AsciiString(nbo) + "\n"; + } + } + + return aDump; +} + //============================================================================= /*! * CheckSelfIntersections @@ -2297,362 +2474,157 @@ Standard_Real GEOMImpl_IMeasureOperations::MinSurfaceCurvatureByPoint return getSurfaceCurvatures(aSurf, UV.X(), UV.Y(), false); } - //======================================================================= -//function : StructuralDump -//purpose : Structural (data exchange) style of output. +//function : FillErrorsSub +//purpose : Fill the errors list of subshapes on shape. //======================================================================= -void GEOMImpl_IMeasureOperations::StructuralDump (const BRepCheck_Analyzer& theAna, - const TopoDS_Shape& theShape, - TCollection_AsciiString& theDump) +void GEOMImpl_IMeasureOperations::FillErrorsSub + (const BRepCheck_Analyzer &theAna, + const TopoDS_Shape &theShape, + const TopAbs_ShapeEnum theSubType, + TopTools_DataMapOfIntegerListOfShape &theMapErrors) const { - Standard_Integer i; - theDump.Clear(); - theDump += " -- The Shape has problems :\n"; - theDump += " Check Count\n"; - theDump += " ------------------------------------------------\n"; - - Standard_Integer last_stat = (Standard_Integer)BRepCheck_CheckFail; - Handle(TColStd_HArray1OfInteger) NbProblems = - new TColStd_HArray1OfInteger(1, last_stat); - for (i = 1; i <= last_stat; i++) - NbProblems->SetValue(i,0); - - Handle(TopTools_HSequenceOfShape) sl; - sl = new TopTools_HSequenceOfShape(); - TopTools_DataMapOfShapeListOfShape theMap; - theMap.Clear(); - GetProblemShapes(theAna, theShape, sl, NbProblems, theMap); - theMap.Clear(); - - Standard_Integer count = 0; - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurve); - if (count > 0) { - theDump += " Invalid Point on Curve ................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnCurveOnSurface); - if (count > 0) { - theDump += " Invalid Point on CurveOnSurface .......... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidPointOnSurface); - if (count > 0) { - theDump += " Invalid Point on Surface ................. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_No3DCurve); - if (count > 0) { - theDump += " No 3D Curve .............................. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_Multiple3DCurve); - if (count > 0) { - theDump += " Multiple 3D Curve ........................ "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_Invalid3DCurve); - if (count > 0) { - theDump += " Invalid 3D Curve ......................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_NoCurveOnSurface); - if (count > 0) { - theDump += " No Curve on Surface ...................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnSurface); - if (count > 0) { - theDump += " Invalid Curve on Surface ................. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidCurveOnClosedSurface); - if (count > 0) { - theDump += " Invalid Curve on closed Surface .......... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameRangeFlag); - if (count > 0) { - theDump += " Invalid SameRange Flag ................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidSameParameterFlag); - if (count > 0) { - theDump += " Invalid SameParameter Flag ............... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidDegeneratedFlag); - if (count > 0) { - theDump += " Invalid Degenerated Flag ................. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_FreeEdge); - if (count > 0) { - theDump += " Free Edge ................................ "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidMultiConnexity); - if (count > 0) { - theDump += " Invalid MultiConnexity ................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidRange); - if (count > 0) { - theDump += " Invalid Range ............................ "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyWire); - if (count > 0) { - theDump += " Empty Wire ............................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantEdge); - if (count > 0) { - theDump += " Redundant Edge ........................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_SelfIntersectingWire); - if (count > 0) { - theDump += " Self Intersecting Wire ................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_NoSurface); - if (count > 0) { - theDump += " No Surface ............................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidWire); - if (count > 0) { - theDump += " Invalid Wire ............................. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantWire); - if (count > 0) { - theDump += " Redundant Wire ........................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_IntersectingWires); - if (count > 0) { - theDump += " Intersecting Wires ....................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_InvalidImbricationOfWires); - if (count > 0) { - theDump += " Invalid Imbrication of Wires ............. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_EmptyShell); - if (count > 0) { - theDump += " Empty Shell .............................. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_RedundantFace); - if (count > 0) { - theDump += " Redundant Face ........................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_UnorientableShape); - if (count > 0) { - theDump += " Unorientable Shape ....................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_NotClosed); - if (count > 0) { - theDump += " Not Closed ............................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_NotConnected); - if (count > 0) { - theDump += " Not Connected ............................ "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_SubshapeNotInShape); - if (count > 0) { - theDump += " Sub-shape not in Shape .................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientation); - if (count > 0) { - theDump += " Bad Orientation .......................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_BadOrientationOfSubshape); - if (count > 0) { - theDump += " Bad Orientation of Sub-shape .............. "; - theDump += TCollection_AsciiString(count) + "\n"; - } - count = NbProblems->Value((Standard_Integer)BRepCheck_CheckFail); - if (count > 0) { - theDump += " checkshape failure ....................... "; - theDump += TCollection_AsciiString(count) + "\n"; - } - - theDump += " ------------------------------------------------\n"; - theDump += "*** Shapes with problems : "; - theDump += TCollection_AsciiString(sl->Length()) + "\n"; - - Standard_Integer nbv, nbe, nbw, nbf, nbs, nbo; - nbv = nbe = nbw = nbf = nbs = nbo = 0; - - for (i = 1; i <= sl->Length(); i++) { - TopoDS_Shape shi = sl->Value(i); - TopAbs_ShapeEnum sti = shi.ShapeType(); - switch (sti) { - case TopAbs_VERTEX : nbv++; break; - case TopAbs_EDGE : nbe++; break; - case TopAbs_WIRE : nbw++; break; - case TopAbs_FACE : nbf++; break; - case TopAbs_SHELL : nbs++; break; - case TopAbs_SOLID : nbo++; break; - default : break; - } - } + TopExp_Explorer anExp(theShape, theSubType); + TopTools_MapOfShape aMapSubShapes; - if (nbv > 0) { - theDump += "VERTEX : "; - if (nbv < 10) theDump += " "; - theDump += TCollection_AsciiString(nbv) + "\n"; - } - if (nbe > 0) { - theDump += "EDGE : "; - if (nbe < 10) theDump += " "; - theDump += TCollection_AsciiString(nbe) + "\n"; - } - if (nbw > 0) { - theDump += "WIRE : "; - if (nbw < 10) theDump += " "; - theDump += TCollection_AsciiString(nbw) + "\n"; - } - if (nbf > 0) { - theDump += "FACE : "; - if (nbf < 10) theDump += " "; - theDump += TCollection_AsciiString(nbf) + "\n"; - } - if (nbs > 0) { - theDump += "SHELL : "; - if (nbs < 10) theDump += " "; - theDump += TCollection_AsciiString(nbs) + "\n"; - } - if (nbo > 0) { - theDump += "SOLID : "; - if (nbo < 10) theDump += " "; - theDump += TCollection_AsciiString(nbo) + "\n"; - } -} + for (; anExp.More(); anExp.Next()) { + const TopoDS_Shape &aSubShape = anExp.Current(); + if (aMapSubShapes.Add(aSubShape)) { + const Handle(BRepCheck_Result) &aRes = theAna.Result(aSubShape); -//======================================================================= -//function : GetProblemShapes -// purpose : for StructuralDump -//======================================================================= -void GEOMImpl_IMeasureOperations::GetProblemShapes (const BRepCheck_Analyzer& theAna, - const TopoDS_Shape& theShape, - Handle(TopTools_HSequenceOfShape)& sl, - Handle(TColStd_HArray1OfInteger)& NbProblems, - TopTools_DataMapOfShapeListOfShape& theMap) -{ - for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) { - GetProblemShapes(theAna, iter.Value(), sl, NbProblems, theMap); - } - TopAbs_ShapeEnum styp = theShape.ShapeType(); - BRepCheck_ListIteratorOfListOfStatus itl; - TopTools_ListOfShape empty; - if (!theMap.IsBound(theShape)) { - theMap.Bind(theShape,empty); - - if (!theAna.Result(theShape).IsNull()) { - itl.Initialize(theAna.Result(theShape)->Status()); - // !!! May be, we have to print all the problems, not only the first one ? - if (itl.Value() != BRepCheck_NoError) { - sl->Append(theShape); - BRepCheck_Status stat = itl.Value(); - NbProblems->SetValue((Standard_Integer)stat, - NbProblems->Value((Standard_Integer)stat) + 1); + for (aRes->InitContextIterator(); + aRes->MoreShapeInContext(); + aRes->NextShapeInContext()) { + if (aRes->ContextualShape().IsSame(theShape)) { + BRepCheck_ListIteratorOfListOfStatus itl(aRes->StatusOnShape()); + + if (itl.Value() != BRepCheck_NoError) { + // Add all errors for theShape and its sub-shape. + for (;itl.More(); itl.Next()) { + const Standard_Integer aStat = (Standard_Integer)itl.Value(); + + if (!theMapErrors.IsBound(aStat)) { + TopTools_ListOfShape anEmpty; + + theMapErrors.Bind(aStat, anEmpty); + } + + TopTools_ListOfShape &theShapes = theMapErrors.ChangeFind(aStat); + + theShapes.Append(aSubShape); + theShapes.Append(theShape); + } + } + } + + break; } } } - - switch (styp) { - case TopAbs_EDGE: - GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap); - break; - case TopAbs_FACE: - GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_WIRE, theMap); - GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_EDGE, theMap); - GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_VERTEX, theMap); - break; - case TopAbs_SHELL: - break; - case TopAbs_SOLID: - GetProblemSub(theAna, theShape, sl, NbProblems, TopAbs_SHELL, theMap); - break; - default: - break; - } } //======================================================================= -//function : Contains +//function : FillErrors +//purpose : Fill the errors list. //======================================================================= -static Standard_Boolean Contains (const TopTools_ListOfShape& L, - const TopoDS_Shape& S) +void GEOMImpl_IMeasureOperations::FillErrors + (const BRepCheck_Analyzer &theAna, + const TopoDS_Shape &theShape, + TopTools_DataMapOfIntegerListOfShape &theMapErrors, + TopTools_MapOfShape &theMapShapes) const { - TopTools_ListIteratorOfListOfShape it; - for (it.Initialize(L); it.More(); it.Next()) { - if (it.Value().IsSame(S)) { - return Standard_True; + if (theMapShapes.Add(theShape)) { + // Fill errors of child shapes. + for (TopoDS_Iterator iter(theShape); iter.More(); iter.Next()) { + FillErrors(theAna, iter.Value(), theMapErrors, theMapShapes); + } + + // Fill errors of theShape. + const Handle(BRepCheck_Result) &aRes = theAna.Result(theShape); + + if (!aRes.IsNull()) { + BRepCheck_ListIteratorOfListOfStatus itl(aRes->Status()); + + if (itl.Value() != BRepCheck_NoError) { + // Add all errors for theShape. + for (;itl.More(); itl.Next()) { + const Standard_Integer aStat = (Standard_Integer)itl.Value(); + + if (!theMapErrors.IsBound(aStat)) { + TopTools_ListOfShape anEmpty; + + theMapErrors.Bind(aStat, anEmpty); + } + + theMapErrors.ChangeFind(aStat).Append(theShape); + } + } + } + + // Add errors of subshapes on theShape. + const TopAbs_ShapeEnum aType = theShape.ShapeType(); + + switch (aType) { + case TopAbs_EDGE: + FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors); + break; + case TopAbs_FACE: + FillErrorsSub(theAna, theShape, TopAbs_WIRE, theMapErrors); + FillErrorsSub(theAna, theShape, TopAbs_EDGE, theMapErrors); + FillErrorsSub(theAna, theShape, TopAbs_VERTEX, theMapErrors); + break; + case TopAbs_SOLID: + FillErrorsSub(theAna, theShape, TopAbs_SHELL, theMapErrors); + break; + default: + break; } } - return Standard_False; } //======================================================================= -//function : GetProblemSub -// purpose : for StructuralDump +//function : FillErrors +//purpose : Fill the errors list. //======================================================================= -void GEOMImpl_IMeasureOperations::GetProblemSub (const BRepCheck_Analyzer& theAna, - const TopoDS_Shape& theShape, - Handle(TopTools_HSequenceOfShape)& sl, - Handle(TColStd_HArray1OfInteger)& NbProblems, - const TopAbs_ShapeEnum Subtype, - TopTools_DataMapOfShapeListOfShape& theMap) +void GEOMImpl_IMeasureOperations::FillErrors + (const BRepCheck_Analyzer &theAna, + const TopoDS_Shape &theShape, + std::list &theErrors) const { - BRepCheck_ListIteratorOfListOfStatus itl; - TopExp_Explorer exp; - for (exp.Init(theShape, Subtype); exp.More(); exp.Next()) { - const TopoDS_Shape& sub = exp.Current(); - - const Handle(BRepCheck_Result)& res = theAna.Result(sub); - for (res->InitContextIterator(); - res->MoreShapeInContext(); - res->NextShapeInContext()) { - if (res->ContextualShape().IsSame(theShape) && !Contains(theMap(sub), theShape)) { - theMap(sub).Append(theShape); - itl.Initialize(res->StatusOnShape()); - - if (itl.Value() != BRepCheck_NoError) { - Standard_Integer ii = 0; - - for (ii = 1; ii <= sl->Length(); ii++) - if (sl->Value(ii).IsSame(sub)) break; - - if (ii > sl->Length()) { - sl->Append(sub); - BRepCheck_Status stat = itl.Value(); - NbProblems->SetValue((Standard_Integer)stat, - NbProblems->Value((Standard_Integer)stat) + 1); - } - for (ii = 1; ii <= sl->Length(); ii++) - if (sl->Value(ii).IsSame(theShape)) break; - if (ii > sl->Length()) { - sl->Append(theShape); - BRepCheck_Status stat = itl.Value(); - NbProblems->SetValue((Standard_Integer)stat, - NbProblems->Value((Standard_Integer)stat) + 1); - } - } - break; + // Fill the errors map. + TopTools_DataMapOfIntegerListOfShape aMapErrors; + TopTools_MapOfShape aMapShapes; + + FillErrors(theAna, theShape, aMapErrors, aMapShapes); + + // Map sub-shapes and their indices + TopTools_IndexedMapOfShape anIndices; + + TopExp::MapShapes(theShape, anIndices); + + TopTools_DataMapIteratorOfDataMapOfIntegerListOfShape aMapIter(aMapErrors); + + for (; aMapIter.More(); aMapIter.Next()) { + ShapeError anError; + + anError.error = (BRepCheck_Status)aMapIter.Key(); + + TopTools_ListIteratorOfListOfShape aListIter(aMapIter.Value()); + TopTools_MapOfShape aMapUnique; + + for (; aListIter.More(); aListIter.Next()) { + const TopoDS_Shape &aShape = aListIter.Value(); + + if (aMapUnique.Add(aShape)) { + const Standard_Integer anIndex = anIndices.FindIndex(aShape); + + anError.incriminated.push_back(anIndex); } } + + if (!anError.incriminated.empty()) { + theErrors.push_back(anError); + } } } diff --git a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx index 45015b8cb..86d0a9c7b 100644 --- a/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IMeasureOperations.hxx @@ -26,13 +26,13 @@ #include "GEOM_IOperations.hxx" #include +#include #include -#include -#include #include #include #include -#include +#include +#include #include #include @@ -127,9 +127,18 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { Standard_Real& EdgeMin, Standard_Real& EdgeMax, Standard_Real& VertMin, Standard_Real& VertMax); - Standard_EXPORT bool CheckShape (Handle(GEOM_Object) theShape, - const Standard_Boolean theIsCheckGeom, - TCollection_AsciiString& theDump); + struct ShapeError { + BRepCheck_Status error; + std::list incriminated; + }; + + Standard_EXPORT bool CheckShape (Handle(GEOM_Object) theShape, + const Standard_Boolean theIsCheckGeom, + std::list &theErrors); + + Standard_EXPORT TCollection_AsciiString PrintShapeErrors + (Handle(GEOM_Object) theShape, + const std::list &theErrors); Standard_EXPORT bool CheckSelfIntersections (Handle(GEOM_Object) theShape, Handle(TColStd_HSequenceOfInteger)& theIntersections); @@ -177,22 +186,21 @@ class GEOMImpl_IMeasureOperations : public GEOM_IOperations { Handle(GEOM_Object) thePoint); private: - void StructuralDump (const BRepCheck_Analyzer& theAna, - const TopoDS_Shape& theShape, - TCollection_AsciiString& theDump); - - void GetProblemShapes (const BRepCheck_Analyzer& theAna, - const TopoDS_Shape& theShape, - Handle(TopTools_HSequenceOfShape)& sl, - Handle(TColStd_HArray1OfInteger)& NbProblems, - TopTools_DataMapOfShapeListOfShape& theMap); - - void GetProblemSub (const BRepCheck_Analyzer& theAna, - const TopoDS_Shape& theShape, - Handle(TopTools_HSequenceOfShape)& sl, - Handle(TColStd_HArray1OfInteger)& NbProblems, - const TopAbs_ShapeEnum Subtype, - TopTools_DataMapOfShapeListOfShape& theMap); + + void FillErrorsSub + (const BRepCheck_Analyzer &theAna, + const TopoDS_Shape &theShape, + const TopAbs_ShapeEnum theSubType, + TopTools_DataMapOfIntegerListOfShape &theMapErrors) const; + void FillErrors + (const BRepCheck_Analyzer &theAna, + const TopoDS_Shape &theShape, + TopTools_DataMapOfIntegerListOfShape &theMapErrors, + TopTools_MapOfShape &theMapShapes) const; + + void FillErrors (const BRepCheck_Analyzer &theAna, + const TopoDS_Shape &theShape, + std::list &theErrors) const; Standard_Real getSurfaceCurvatures (const Handle(Geom_Surface)& aSurf, Standard_Real theUParam, diff --git a/src/GEOM_I/GEOM_Gen_i.cc b/src/GEOM_I/GEOM_Gen_i.cc old mode 100644 new mode 100755 index f51456c46..4732c1f5a --- a/src/GEOM_I/GEOM_Gen_i.cc +++ b/src/GEOM_I/GEOM_Gen_i.cc @@ -58,6 +58,7 @@ #include #include #include +#include #include #include diff --git a/src/GEOM_I/GEOM_Gen_i.hh b/src/GEOM_I/GEOM_Gen_i.hh index 4f12a3301..81771124b 100644 --- a/src/GEOM_I/GEOM_Gen_i.hh +++ b/src/GEOM_I/GEOM_Gen_i.hh @@ -60,6 +60,7 @@ //#include // CAREFUL ! position of this file is critic : see Lucien PIGNOLONI / OCC +class TopTools_SequenceOfShape; //===================================================================== // Generic operations creator (for plugins mechanism) diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.cc b/src/GEOM_I/GEOM_IMeasureOperations_i.cc index 7f0d3cac4..b6785bda9 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.cc +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.cc @@ -30,6 +30,291 @@ #include "GEOM_Engine.hxx" #include "GEOM_Object.hxx" +/** + * This function converts shape errors from theErrorsFrom to theErrorsTo. + * Note that theErrorsTo is not cleared at first. + * + * \param theErrorsFrom errors to be converted. + * \param theErrorsTo result errors. + */ +static void ConvertShapeError + (const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrorsFrom, + std::list &theErrorsTo) +{ + int aNbErr = theErrorsFrom.length(); + int i = 0; + + for (; i < aNbErr; i++) { + const GEOM::GEOM_IMeasureOperations::ShapeError anErr = theErrorsFrom[i]; + const GEOM::GEOM_IMeasureOperations::ShapeErrorType aType = anErr.error; + const GEOM::ListOfLong anIncrims = anErr.incriminated; + GEOMImpl_IMeasureOperations::ShapeError anErrStruct; + + switch (aType) { + case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve: + anErrStruct.error = BRepCheck_InvalidPointOnCurve; + break; + case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface: + anErrStruct.error = BRepCheck_InvalidPointOnCurveOnSurface; + break; + case GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface: + anErrStruct.error = BRepCheck_InvalidPointOnSurface; + break; + case GEOM::GEOM_IMeasureOperations::No3DCurve: + anErrStruct.error = BRepCheck_No3DCurve; + break; + case GEOM::GEOM_IMeasureOperations::Multiple3DCurve: + anErrStruct.error = BRepCheck_Multiple3DCurve; + break; + case GEOM::GEOM_IMeasureOperations::Invalid3DCurve: + anErrStruct.error = BRepCheck_Invalid3DCurve; + break; + case GEOM::GEOM_IMeasureOperations::NoCurveOnSurface: + anErrStruct.error = BRepCheck_NoCurveOnSurface; + break; + case GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface: + anErrStruct.error = BRepCheck_InvalidCurveOnSurface; + break; + case GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface: + anErrStruct.error = BRepCheck_InvalidCurveOnClosedSurface; + break; + case GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag: + anErrStruct.error = BRepCheck_InvalidSameRangeFlag; + break; + case GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag: + anErrStruct.error = BRepCheck_InvalidSameParameterFlag; + break; + case GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag: + anErrStruct.error = BRepCheck_InvalidDegeneratedFlag; + break; + case GEOM::GEOM_IMeasureOperations::FreeEdge: + anErrStruct.error = BRepCheck_FreeEdge; + break; + case GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity: + anErrStruct.error = BRepCheck_InvalidMultiConnexity; + break; + case GEOM::GEOM_IMeasureOperations::InvalidRange: + anErrStruct.error = BRepCheck_InvalidRange; + break; + case GEOM::GEOM_IMeasureOperations::EmptyWire: + anErrStruct.error = BRepCheck_EmptyWire; + break; + case GEOM::GEOM_IMeasureOperations::RedundantEdge: + anErrStruct.error = BRepCheck_RedundantEdge; + break; + case GEOM::GEOM_IMeasureOperations::SelfIntersectingWire: + anErrStruct.error = BRepCheck_SelfIntersectingWire; + break; + case GEOM::GEOM_IMeasureOperations::NoSurface: + anErrStruct.error = BRepCheck_NoSurface; + break; + case GEOM::GEOM_IMeasureOperations::InvalidWire: + anErrStruct.error = BRepCheck_InvalidWire; + break; + case GEOM::GEOM_IMeasureOperations::RedundantWire: + anErrStruct.error = BRepCheck_RedundantWire; + break; + case GEOM::GEOM_IMeasureOperations::IntersectingWires: + anErrStruct.error = BRepCheck_IntersectingWires; + break; + case GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires: + anErrStruct.error = BRepCheck_InvalidImbricationOfWires; + break; + case GEOM::GEOM_IMeasureOperations::EmptyShell: + anErrStruct.error = BRepCheck_EmptyShell; + break; + case GEOM::GEOM_IMeasureOperations::RedundantFace: + anErrStruct.error = BRepCheck_RedundantFace; + break; + case GEOM::GEOM_IMeasureOperations::UnorientableShape: + anErrStruct.error = BRepCheck_UnorientableShape; + break; + case GEOM::GEOM_IMeasureOperations::NotClosed: + anErrStruct.error = BRepCheck_NotClosed; + break; + case GEOM::GEOM_IMeasureOperations::NotConnected: + anErrStruct.error = BRepCheck_NotConnected; + break; + case GEOM::GEOM_IMeasureOperations::SubshapeNotInShape: + anErrStruct.error = BRepCheck_SubshapeNotInShape; + break; + case GEOM::GEOM_IMeasureOperations::BadOrientation: + anErrStruct.error = BRepCheck_BadOrientation; + break; + case GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape: + anErrStruct.error = BRepCheck_BadOrientationOfSubshape; + break; + case GEOM::GEOM_IMeasureOperations::InvalidToleranceValue: + anErrStruct.error = BRepCheck_InvalidToleranceValue; + break; + case GEOM::GEOM_IMeasureOperations::CheckFail: + anErrStruct.error = BRepCheck_CheckFail; + break; + default: + break; + } + + int ii = 0; + int aLen = anIncrims.length(); + + for (; ii < aLen; ii++) { + anErrStruct.incriminated.push_back(anIncrims[ii]); + } + + theErrorsTo.push_back(anErrStruct); + } +} + +/** + * This function converts shape errors from theErrorsFrom to theErrorsTo. + * Note that theErrorsTo is not cleared at first. + * + * \param theErrorsFrom errors to be converted. + * \param theErrorsTo result errors. + */ +static void ConvertShapeError + (const std::list &theErrorsFrom, + GEOM::GEOM_IMeasureOperations::ShapeErrors_out &theErrorsTo) +{ + const int aNbErr = theErrorsFrom.size(); + GEOM::GEOM_IMeasureOperations::ShapeErrors_var anErrArray = + new GEOM::GEOM_IMeasureOperations::ShapeErrors; + + anErrArray->length(aNbErr); + + // fill the local CORBA array with values from lists + std::list::const_iterator + anIt = theErrorsFrom.begin(); + int i = 0; + + for (; anIt != theErrorsFrom.end(); i++, anIt++) { + GEOM::GEOM_IMeasureOperations::ShapeError_var anErrStruct = + new GEOM::GEOM_IMeasureOperations::ShapeError; + + switch (anIt->error) { + case BRepCheck_InvalidPointOnCurve: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve; + break; + case BRepCheck_InvalidPointOnCurveOnSurface: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface; + break; + case BRepCheck_InvalidPointOnSurface: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface; + break; + case BRepCheck_No3DCurve: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::No3DCurve; + break; + case BRepCheck_Multiple3DCurve: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::Multiple3DCurve; + break; + case BRepCheck_Invalid3DCurve: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::Invalid3DCurve; + break; + case BRepCheck_NoCurveOnSurface: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoCurveOnSurface; + break; + case BRepCheck_InvalidCurveOnSurface: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface; + break; + case BRepCheck_InvalidCurveOnClosedSurface: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface; + break; + case BRepCheck_InvalidSameRangeFlag: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag; + break; + case BRepCheck_InvalidSameParameterFlag: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag; + break; + case BRepCheck_InvalidDegeneratedFlag: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag; + break; + case BRepCheck_FreeEdge: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::FreeEdge; + break; + case BRepCheck_InvalidMultiConnexity: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity; + break; + case BRepCheck_InvalidRange: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidRange; + break; + case BRepCheck_EmptyWire: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyWire; + break; + case BRepCheck_RedundantEdge: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantEdge; + break; + case BRepCheck_SelfIntersectingWire: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::SelfIntersectingWire; + break; + case BRepCheck_NoSurface: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::NoSurface; + break; + case BRepCheck_InvalidWire: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidWire; + break; + case BRepCheck_RedundantWire: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantWire; + break; + case BRepCheck_IntersectingWires: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::IntersectingWires; + break; + case BRepCheck_InvalidImbricationOfWires: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires; + break; + case BRepCheck_EmptyShell: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::EmptyShell; + break; + case BRepCheck_RedundantFace: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::RedundantFace; + break; + case BRepCheck_UnorientableShape: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::UnorientableShape; + break; + case BRepCheck_NotClosed: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotClosed; + break; + case BRepCheck_NotConnected: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::NotConnected; + break; + case BRepCheck_SubshapeNotInShape: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::SubshapeNotInShape; + break; + case BRepCheck_BadOrientation: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientation; + break; + case BRepCheck_BadOrientationOfSubshape: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape; + break; + case BRepCheck_InvalidToleranceValue: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::InvalidToleranceValue; + break; + case BRepCheck_CheckFail: + anErrStruct->error = GEOM::GEOM_IMeasureOperations::CheckFail; + break; + default: + break; + } + + std::list aIndList = anIt->incriminated; + GEOM::ListOfLong_var anIncrims = new GEOM::ListOfLong(); + anIncrims->length(aIndList.size()); + + std::list::iterator anIndIt = aIndList.begin(); + int jj = 0; + + for (; anIndIt != aIndList.end(); jj++, anIndIt++) { + anIncrims[jj] = *anIndIt; + } + + anErrStruct->incriminated = anIncrims; + + anErrArray[i] = anErrStruct; + } + + // initialize out-parameter with local array + theErrorsTo = anErrArray._retn(); +} + //============================================================================= /*! * constructor: @@ -332,15 +617,15 @@ void GEOM_IMeasureOperations_i::GetTolerance * CheckShape */ //============================================================================= -CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theShape, - CORBA::String_out theDescription) +CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape + (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors) { //Set a not done flag GetOperations()->SetNotDone(); if (CORBA::is_nil(theShape)) { - theDescription = CORBA::string_dup("null"); return 0; } @@ -349,30 +634,26 @@ CORBA::Boolean GEOM_IMeasureOperations_i::CheckShape (GEOM::GEOM_Object_ptr theS if (aShape.IsNull()) { - theDescription = CORBA::string_dup("null2"); return 0; } - // Get shape parameters - TCollection_AsciiString aDump; - if (GetOperations()->CheckShape(aShape, /*check_geom = */false, aDump)) - { - theDescription = CORBA::string_dup("OK"); - return 1; - } - theDescription = CORBA::string_dup(aDump.ToCString()); - return 0; + std::list anErrList; + bool isOk = GetOperations()->CheckShape(aShape, false, anErrList); + + ConvertShapeError(anErrList, theErrors); + + return isOk; } -CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape, - CORBA::String_out theDescription) +CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry + (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors) { //Set a not done flag GetOperations()->SetNotDone(); if (CORBA::is_nil(theShape)) { - theDescription = CORBA::string_dup("null"); return 0; } @@ -381,19 +662,42 @@ CORBA::Boolean GEOM_IMeasureOperations_i::CheckShapeWithGeometry (GEOM::GEOM_Obj if (aShape.IsNull()) { - theDescription = CORBA::string_dup("null2"); return 0; } - // Get shape parameters - TCollection_AsciiString aDump; - if (GetOperations()->CheckShape(aShape, /*check_geom = */true, aDump)) - { - theDescription = CORBA::string_dup("OK"); - return 1; + std::list anErrList; + bool isOk = GetOperations()->CheckShape(aShape, true, anErrList); + + ConvertShapeError(anErrList, theErrors); + + return isOk; +} + +//============================================================================= +/*! + * PrintShapeErrors + */ +//============================================================================= +char* GEOM_IMeasureOperations_i::PrintShapeErrors + ( GEOM::GEOM_Object_ptr theShape, + const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrors) +{ + //Get the reference shape + Handle(GEOM_Object) aShape = GetObjectImpl(theShape); + + if (aShape.IsNull()) { + return NULL; } - theDescription = CORBA::string_dup(aDump.ToCString()); - return 0; + + // Convert the errors sequence + std::list anErrList; + + ConvertShapeError(theErrors, anErrList); + + TCollection_AsciiString aDescr = + GetOperations()->PrintShapeErrors(aShape, anErrList); + + return CORBA::string_dup(aDescr.ToCString()); } //============================================================================= diff --git a/src/GEOM_I/GEOM_IMeasureOperations_i.hh b/src/GEOM_I/GEOM_IMeasureOperations_i.hh index caa3de251..690ac5390 100644 --- a/src/GEOM_I/GEOM_IMeasureOperations_i.hh +++ b/src/GEOM_I/GEOM_IMeasureOperations_i.hh @@ -84,11 +84,17 @@ class GEOM_I_EXPORT GEOM_IMeasureOperations_i : CORBA::Double& EdgeMin, CORBA::Double& EdgeMax, CORBA::Double& VertMin, CORBA::Double& VertMax); - CORBA::Boolean CheckShape (GEOM::GEOM_Object_ptr theShape, - CORBA::String_out theDescription); + CORBA::Boolean CheckShape + (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors); - CORBA::Boolean CheckShapeWithGeometry (GEOM::GEOM_Object_ptr theShape, - CORBA::String_out theDescription); + CORBA::Boolean CheckShapeWithGeometry + (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_IMeasureOperations::ShapeErrors_out theErrors); + + char* PrintShapeErrors + ( GEOM::GEOM_Object_ptr theShape, + const GEOM::GEOM_IMeasureOperations::ShapeErrors &theErrors); CORBA::Boolean CheckSelfIntersections (GEOM::GEOM_Object_ptr theShape, GEOM::ListOfLong_out theIntersections); diff --git a/src/GEOM_SWIG/GEOM_TestMeasures.py b/src/GEOM_SWIG/GEOM_TestMeasures.py index 817a73082..2aed6d6a5 100644 --- a/src/GEOM_SWIG/GEOM_TestMeasures.py +++ b/src/GEOM_SWIG/GEOM_TestMeasures.py @@ -41,8 +41,9 @@ def TestMeasureOperations (geompy, math): ####### CheckShape ####### - IsValid = geompy.CheckShape(box) + (IsValid, err) = geompy.CheckShape(box, 0, 2) if IsValid == 0: + geompy.PrintShapeError(box, err) raise RuntimeError, "Invalid box created" else: print "\nBox is valid" diff --git a/src/GEOM_SWIG/geomBuilder.py b/src/GEOM_SWIG/geomBuilder.py index 057e6b064..74d835d0a 100644 --- a/src/GEOM_SWIG/geomBuilder.py +++ b/src/GEOM_SWIG/geomBuilder.py @@ -10142,15 +10142,52 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): self._autoPublish(anObj, theName, "normal") return anObj + ## Print shape errors obtained from CheckShape. + # @param theShape Shape that was checked. + # @param theShapeErrors the shape errors obtained by CheckShape. + # @param theReturnStatus If 0 the description of problem is printed. + # If 1 the description of problem is returned. + # @return If theReturnStatus is equal to 1 the description is returned. + # Otherwise doesn't return anything. + # + # @ref tui_measurement_tools_page "Example" + def PrintShapeErrors(self, theShape, theShapeErrors, theReturnStatus = 0): + """ + Print shape errors obtained from CheckShape. + + Parameters: + theShape Shape that was checked. + theShapeErrors the shape errors obtained by CheckShape. + theReturnStatus If 0 the description of problem is printed. + If 1 the description of problem is returned. + + Returns: + If theReturnStatus is equal to 1 the description is returned. + Otherwise doesn't return anything. + """ + # Example: see GEOM_TestMeasures.py + Descr = self.MeasuOp.PrintShapeErrors(theShape, theShapeErrors) + if theReturnStatus == 1: + return Descr + print Descr + pass + ## Check a topology of the given shape. # @param theShape Shape to check validity of. # @param theIsCheckGeom If FALSE, only the shape's topology will be checked, \n # if TRUE, the shape's geometry will be checked also. - # @param theReturnStatus If FALSE and if theShape is invalid, a description \n - # of problem is printed. - # if TRUE and if theShape is invalid, the description - # of problem is also returned. + # @param theReturnStatus If 0 and if theShape is invalid, a description + # of problem is printed. + # If 1 isValid flag and the description of + # problem is returned. + # If 2 isValid flag and the list of error data + # is returned. # @return TRUE, if the shape "seems to be valid". + # If theShape is invalid, prints a description of problem. + # If theReturnStatus is equal to 1 the description is returned + # along with IsValid flag. + # If theReturnStatus is equal to 2 the list of error data is + # returned along with IsValid flag. # # @ref tui_measurement_tools_page "Example" def CheckShape(self,theShape, theIsCheckGeom = 0, theReturnStatus = 0): @@ -10161,28 +10198,37 @@ class geomBuilder(object, GEOM._objref_GEOM_Gen): theShape Shape to check validity of. theIsCheckGeom If FALSE, only the shape's topology will be checked, if TRUE, the shape's geometry will be checked also. - theReturnStatus If FALSE and if theShape is invalid, a description + theReturnStatus If 0 and if theShape is invalid, a description of problem is printed. - if TRUE and if theShape is invalid, the description - of problem is returned. + If 1 IsValid flag and the description of + problem is returned. + If 2 IsValid flag and the list of error data + is returned. Returns: TRUE, if the shape "seems to be valid". If theShape is invalid, prints a description of problem. - This description can also be returned. + If theReturnStatus is equal to 1 the description is returned + along with IsValid flag. + If theReturnStatus is equal to 2 the list of error data is + returned along with IsValid flag. """ # Example: see GEOM_TestMeasures.py if theIsCheckGeom: - (IsValid, Status) = self.MeasuOp.CheckShapeWithGeometry(theShape) + (IsValid, ShapeErrors) = self.MeasuOp.CheckShapeWithGeometry(theShape) RaiseIfFailed("CheckShapeWithGeometry", self.MeasuOp) else: - (IsValid, Status) = self.MeasuOp.CheckShape(theShape) + (IsValid, ShapeErrors) = self.MeasuOp.CheckShape(theShape) RaiseIfFailed("CheckShape", self.MeasuOp) if IsValid == 0: if theReturnStatus == 0: - print Status + Descr = self.MeasuOp.PrintShapeErrors(theShape, ShapeErrors) + print Descr if theReturnStatus == 1: - return (IsValid, Status) + Descr = self.MeasuOp.PrintShapeErrors(theShape, ShapeErrors) + return (IsValid, Descr) + elif theReturnStatus == 2: + return (IsValid, ShapeErrors) return IsValid ## Detect self-intersections in the given shape. diff --git a/src/MeasureGUI/CMakeLists.txt b/src/MeasureGUI/CMakeLists.txt index 20bacd209..8f57e40ad 100755 --- a/src/MeasureGUI/CMakeLists.txt +++ b/src/MeasureGUI/CMakeLists.txt @@ -66,6 +66,7 @@ SET(_uic_files MeasureGUI_1Sel12LineEdit_QTD.ui MeasureGUI_1Sel1TextView1Check_QTD.ui MeasureGUI_1Sel1TextView2ListBox_QTD.ui + MeasureGUI_1Sel1Check1TextView2ListBox_QTD.ui MeasureGUI_1Sel1TextView_QTD.ui MeasureGUI_1Sel3LineEdit_QTD.ui MeasureGUI_1Sel6LineEdit_QTD.ui diff --git a/src/MeasureGUI/MeasureGUI_1Sel1Check1TextView2ListBox_QTD.ui b/src/MeasureGUI/MeasureGUI_1Sel1Check1TextView2ListBox_QTD.ui new file mode 100644 index 000000000..aa6a3fa3d --- /dev/null +++ b/src/MeasureGUI/MeasureGUI_1Sel1Check1TextView2ListBox_QTD.ui @@ -0,0 +1,138 @@ + + MeasureGUI_1Sel1Check1TextView2ListBox_QTD + + + + 0 + 0 + 235 + 274 + + + + + + + + 0 + + + 0 + + + 0 + + + 0 + + + 6 + + + 6 + + + + + + + + + 9 + + + 9 + + + 9 + + + 9 + + + 6 + + + 6 + + + + + + + + + + + + 100 + 0 + + + + + + + + Check also geometry + + + + + + + + 300 + 0 + + + + + + + + TL2 + + + + + + + TL3 + + + + + + + TL1 + + + + + + + + 0 + 0 + + + + + + + + + + + + + + PushButton1 + LineEdit1 + CheckBox1 + TextView1 + + + + diff --git a/src/MeasureGUI/MeasureGUI_CheckCompoundOfBlocksDlg.cxx b/src/MeasureGUI/MeasureGUI_CheckCompoundOfBlocksDlg.cxx index a0900cbc4..26763b814 100644 --- a/src/MeasureGUI/MeasureGUI_CheckCompoundOfBlocksDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_CheckCompoundOfBlocksDlg.cxx @@ -299,25 +299,19 @@ void MeasureGUI_CheckCompoundOfBlocksDlg::processObject() aErrStr = ""; switch ( aErrs[i].error ) { case GEOM::GEOM_IBlocksOperations::NOT_BLOCK : - aErrStr = "Not a Block"; + aErrStr = tr("GEOM_CHECK_BLOCKS_NOT_BLOCK"); break; case GEOM::GEOM_IBlocksOperations::EXTRA_EDGE : - aErrStr = "Extra Edge"; + aErrStr = tr("GEOM_CHECK_BLOCKS_EXTRA_EDGE"); break; case GEOM::GEOM_IBlocksOperations::INVALID_CONNECTION : - aErrStr = "Invalid Connection"; - aErrStr += aConSfx; - aErrStr += QString::number( aConNum ); - aConNum++; + aErrStr = tr("GEOM_CHECK_BLOCKS_INVALID_CONNECTION").arg(aConNum++); break; case GEOM::GEOM_IBlocksOperations::NOT_CONNECTED : - aErrStr = "Not Connected"; + aErrStr = tr("GEOM_CHECK_BLOCKS_NOT_CONNECTED"); break; case GEOM::GEOM_IBlocksOperations::NOT_GLUED : - aErrStr = "Not Glued"; - aErrStr += aGluedSfx; - aErrStr += QString::number( aGluedNum ); - aGluedNum++; + aErrStr = tr("GEOM_CHECK_BLOCKS_NOT_GLUED").arg(aGluedNum++); break; default : aErrStr = ""; diff --git a/src/MeasureGUI/MeasureGUI_CheckShapeDlg.cxx b/src/MeasureGUI/MeasureGUI_CheckShapeDlg.cxx index 48836f74c..42b9e3abd 100644 --- a/src/MeasureGUI/MeasureGUI_CheckShapeDlg.cxx +++ b/src/MeasureGUI/MeasureGUI_CheckShapeDlg.cxx @@ -24,12 +24,24 @@ // File : MeasureGUI_CheckShapeDlg.cxx // Author : Nicolas REJNERI, Open CASCADE S.A.S. // +#include "MeasureGUI.h" #include "MeasureGUI_CheckShapeDlg.h" #include "MeasureGUI_Widgets.h" +#include +#include +#include +#include #include #include #include +#include +#include + +#include +#include +#include +#include #define TEXTEDIT_FONT_FAMILY "Courier" #define TEXTEDIT_FONT_SIZE 11 @@ -42,7 +54,7 @@ // true to construct a modal dialog. //================================================================================= MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg( GeometryGUI* GUI, QWidget* parent ) - : MeasureGUI_Skeleton( GUI, parent ) + : GEOMBase_Skeleton( GUI, parent, false ) { QPixmap image0( SUIT_Session::session()->resourceMgr()->loadPixmap( "GEOM", tr( "ICON_DLG_CHECKSHAPE" ) ) ); @@ -55,8 +67,12 @@ MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg( GeometryGUI* GUI, QWidget* p mainFrame()->GroupConstructors->setTitle( tr( "GEOM_CHECK_SHAPE" ) ); mainFrame()->RadioButton1->setIcon( image0 ); + mainFrame()->RadioButton2->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->setAttribute( Qt::WA_DeleteOnClose ); + mainFrame()->RadioButton3->close(); - myGrp = new MeasureGUI_1Sel1TextView1Check( centralWidget() ); + myGrp = new MeasureGUI_1Sel1Check1TextView2ListBox( centralWidget() ); myGrp->GroupBox1->setTitle( tr( "GEOM_CHECK_INFOS" ) ); myGrp->TextLabel1->setText( tr( "GEOM_OBJECT" ) ); myGrp->TextView1->setReadOnly( true ); @@ -67,10 +83,18 @@ MeasureGUI_CheckShapeDlg::MeasureGUI_CheckShapeDlg( GeometryGUI* GUI, QWidget* p myGrp->PushButton1->setIcon( image1 ); myGrp->LineEdit1->setReadOnly( true ); + myGrp->TextLabel2->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_ERRORS" ) ); + myGrp->TextLabel3->setText( tr( "GEOM_CHECK_BLOCKS_COMPOUND_SUBSHAPES" ) ); + + myGrp->ListBox2->setSelectionMode( QAbstractItemView::ExtendedSelection ); + QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); layout->setMargin( 0 ); layout->setSpacing( 6 ); layout->addWidget( myGrp ); + connect( myGrp->ListBox1, SIGNAL( itemSelectionChanged() ), SLOT( onErrorsListSelectionChanged() ) ); + connect( myGrp->ListBox2, SIGNAL( itemSelectionChanged() ), SLOT( onSubShapesListSelectionChanged() ) ); + /***************************************************************/ myHelpFileName = "using_measurement_tools_page.html#check_anchor"; @@ -94,32 +118,167 @@ MeasureGUI_CheckShapeDlg::~MeasureGUI_CheckShapeDlg() //================================================================================= void MeasureGUI_CheckShapeDlg::Init() { - mySelBtn = myGrp->PushButton1; - mySelEdit = myGrp->LineEdit1; - MeasureGUI_Skeleton::Init(); + // signals and slots connections + connect( buttonOk(), SIGNAL( clicked() ), this, SLOT( ClickOnOk() ) ); + connect( buttonApply(), SIGNAL( clicked() ), this, SLOT( ClickOnApply() ) ); + + connect( myGrp->PushButton1, SIGNAL( clicked() ), this, SLOT( SetEditCurrentArgument() ) ); + + connect( myGeomGUI->getApp()->selectionMgr(), SIGNAL( currentSelectionChanged() ), + this, SLOT( SelectionIntoArgument() ) ); connect( myGrp->CheckBox1, SIGNAL( toggled( bool) ), this, SLOT( SelectionIntoArgument() ) ); + + initName( tr( "GEOM_CHECK_SHAPE_NAME") ); + buttonOk()->setEnabled( false ); + buttonApply()->setEnabled( false ); + activateSelection(); + SelectionIntoArgument(); } //================================================================================= -// function : getParameters +// function : ClickOnOk() // purpose : //================================================================================= -bool MeasureGUI_CheckShapeDlg::getParameters ( bool& theIsValid, QString& theMsg ) +void MeasureGUI_CheckShapeDlg::ClickOnOk() { - if ( myObj->_is_nil() ) + if ( ClickOnApply() ) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool MeasureGUI_CheckShapeDlg::ClickOnApply() +{ + if ( !onAccept() ) return false; - else { + + initName(); + return true; +} + +//================================================================================= +// function : SelectionIntoArgument +// purpose : +//================================================================================= +bool MeasureGUI_CheckShapeDlg::extractPrefix() const +{ + return true; +} + +//================================================================================= +// function : SelectionIntoArgument +// purpose : +//================================================================================= +void MeasureGUI_CheckShapeDlg::SelectionIntoArgument() +{ + erasePreview(); + myObj = GEOM::GEOM_Object::_nil(); + + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if (aSelList.Extent() != 1) { + myGrp->LineEdit1->setText( "" ); + processObject(); + return; + } + + GEOM::GEOM_Object_var aSelectedObject = + GEOMBase::ConvertIOinGEOMObject( aSelList.First() ); + + if ( aSelectedObject->_is_nil() ) { + myGrp->LineEdit1->setText( "" ); + processObject(); + return; + } + + myObj = aSelectedObject; + myGrp->LineEdit1->setText( GEOMBase::GetName( myObj ) ); + processObject(); + DISPLAY_PREVIEW_MACRO; +} + +//================================================================================= +// function : SetEditCurrentArgument +// purpose : +//================================================================================= +void MeasureGUI_CheckShapeDlg::SetEditCurrentArgument() +{ + myGrp->LineEdit1->setFocus(); + SelectionIntoArgument(); +} + +//================================================================================= +// function : ActivateThisDialog() +// purpose : +//================================================================================= +void MeasureGUI_CheckShapeDlg::ActivateThisDialog() +{ + GEOMBase_Skeleton::ActivateThisDialog(); + + LightApp_SelectionMgr* aSel = myGeomGUI->getApp()->selectionMgr(); + if ( aSel ) + connect( aSel, SIGNAL( currentSelectionChanged() ), this, SLOT( SelectionIntoArgument() ) ); + + activateSelection(); + DISPLAY_PREVIEW_MACRO +} + +//================================================================================= +// function : activateSelection +// purpose : activate selection of faces, shells, and solids +//================================================================================= +void MeasureGUI_CheckShapeDlg::activateSelection() +{ + globalSelection( GEOM_ALLSHAPES ); +} + +//================================================================================= +// function : enterEvent() +// purpose : +//================================================================================= +void MeasureGUI_CheckShapeDlg::enterEvent( QEvent* ) +{ + if ( !mainFrame()->GroupConstructors->isEnabled() ) + ActivateThisDialog(); +} + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool MeasureGUI_CheckShapeDlg::isValid( QString& ) +{ + return !myObj->_is_nil(); +} + +//================================================================================= +// function : getErrors +// purpose : +//================================================================================= +bool MeasureGUI_CheckShapeDlg::getErrors + ( bool& theIsValid, + GEOM::GEOM_IMeasureOperations::ShapeErrors& theErrors ) +{ + if ( myObj->_is_nil() ) { + return false; + } else { GEOM::GEOM_IMeasureOperations_var anOper = GEOM::GEOM_IMeasureOperations::_narrow( getOperation() ); try { - char* aMsg; + GEOM::GEOM_IMeasureOperations::ShapeErrors_var aErrs; bool isCheckGeometry = myGrp->CheckBox1->isChecked(); if ( isCheckGeometry ) - theIsValid = anOper->CheckShapeWithGeometry( myObj, aMsg ); + theIsValid = anOper->CheckShapeWithGeometry( myObj, aErrs ); else - theIsValid = anOper->CheckShape( myObj, aMsg ); - theMsg = aMsg; + theIsValid = anOper->CheckShape( myObj, aErrs ); + + if (anOper->IsDone() && aErrs->length() > 0) + theErrors = aErrs; } catch( const SALOME::SALOME_Exception& e ) { SalomeApp_Tools::QtCatchCorbaException( e ); @@ -138,19 +297,343 @@ bool MeasureGUI_CheckShapeDlg::getParameters ( bool& theIsValid, QString& theMsg void MeasureGUI_CheckShapeDlg::processObject() { bool isShapeValid; - QString aMsg; - if ( !getParameters( isShapeValid, aMsg ) ) { + GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs; + + if ( !getErrors( isShapeValid, aErrs ) ) { myGrp->TextView1->setText( "" ); + myGrp->ListBox1->clear(); + myGrp->ListBox2->clear(); + erasePreview(); + return; } if ( isShapeValid ) { - myGrp->TextView1->setText( "This Shape seems to be valid." ); - } - else { - QString aDescr ( "This Shape is not valid.\n" ); - aDescr += aMsg; - myGrp->TextView1->setText( aDescr ); -// myGrp->TextView1->setText("This Shape is not valid."); + myGrp->TextView1->setText(tr("GEOM_CHECK_SHAPE_VALID")); + buttonOk()->setEnabled( false ); + buttonApply()->setEnabled( false ); + } else { + myGrp->TextView1->setText(tr("GEOM_CHECK_SHAPE_NOT_VALID")); + buttonOk()->setEnabled( true ); + buttonApply()->setEnabled( true ); + } + + // Add Error groups + QStringList aErrList; + + for ( int i = 0, n = aErrs.length(); i < n; i++ ) { + QString aErrStr("CHECK_ERROR_"); + + switch ( aErrs[i].error ) { + case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurve: + aErrStr += "INVALID_POINT_ON_CURVE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidPointOnCurveOnSurface: + aErrStr += "INVALID_POINT_ON_CURVE_ON_SURFACE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidPointOnSurface: + aErrStr += "INVALID_POINT_ON_SURFACE"; + break; + case GEOM::GEOM_IMeasureOperations::No3DCurve: + aErrStr += "NO_3D_CURVE"; + break; + case GEOM::GEOM_IMeasureOperations::Multiple3DCurve: + aErrStr += "MULTIPLE_3D_CURVE"; + break; + case GEOM::GEOM_IMeasureOperations::Invalid3DCurve: + aErrStr += "INVALID_3D_CURVE"; + break; + case GEOM::GEOM_IMeasureOperations::NoCurveOnSurface: + aErrStr += "NO_CURVE_ON_SURFACE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidCurveOnSurface: + aErrStr += "INVALID_CURVE_ON_SURFACE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidCurveOnClosedSurface: + aErrStr += "INVALID_CURVE_ON_CLOSED_SURFACE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidSameRangeFlag: + aErrStr += "INVALID_SAME_RANGE_FLAG"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidSameParameterFlag: + aErrStr += "INVALID_SAME_PARAMETER_FLAG"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidDegeneratedFlag: + aErrStr += "INVALID_DEGENERATED_FLAG"; + break; + case GEOM::GEOM_IMeasureOperations::FreeEdge: + aErrStr += "FREE_EDGE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidMultiConnexity: + aErrStr += "INVALID_MULTI_CONNEXITY"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidRange: + aErrStr += "INVALID_RANGE"; + break; + case GEOM::GEOM_IMeasureOperations::EmptyWire: + aErrStr += "EMPTY_WIRE"; + break; + case GEOM::GEOM_IMeasureOperations::RedundantEdge: + aErrStr += "REDUNDANT_EDGE"; + break; + case GEOM::GEOM_IMeasureOperations::SelfIntersectingWire: + aErrStr += "SELF_INTERSECTING_WIRE"; + break; + case GEOM::GEOM_IMeasureOperations::NoSurface: + aErrStr += "NO_SURFACE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidWire: + aErrStr += "INVALID_WIRE"; + break; + case GEOM::GEOM_IMeasureOperations::RedundantWire: + aErrStr += "REDUNDANT_WIRE"; + break; + case GEOM::GEOM_IMeasureOperations::IntersectingWires: + aErrStr += "INTERSECTING_WIRES"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidImbricationOfWires: + aErrStr += "INVALID_IMBRICATION_OF_WIRES"; + break; + case GEOM::GEOM_IMeasureOperations::EmptyShell: + aErrStr += "EMPTY_SHELL"; + break; + case GEOM::GEOM_IMeasureOperations::RedundantFace: + aErrStr += "REDUNDANT_FACE"; + break; + case GEOM::GEOM_IMeasureOperations::UnorientableShape: + aErrStr += "UNORIENTABLE_SHAPE"; + break; + case GEOM::GEOM_IMeasureOperations::NotClosed: + aErrStr += "NOT_CLOSED"; + break; + case GEOM::GEOM_IMeasureOperations::NotConnected: + aErrStr += "NOT_CONNECTED"; + break; + case GEOM::GEOM_IMeasureOperations::SubshapeNotInShape: + aErrStr += "SUBSHAPE_NOT_IN_SHAPE"; + break; + case GEOM::GEOM_IMeasureOperations::BadOrientation: + aErrStr += "BAD_ORIENTATION"; + break; + case GEOM::GEOM_IMeasureOperations::BadOrientationOfSubshape: + aErrStr += "BAD_ORIENTATION_OF_SUBSHAPE"; + break; + case GEOM::GEOM_IMeasureOperations::InvalidToleranceValue: + aErrStr += "INVALID_TOLERANCE_VALUE"; + break; + case GEOM::GEOM_IMeasureOperations::CheckFail: + aErrStr += "CHECK_FAIL"; + break; + default: + aErrStr.clear(); + break; + } + + if (!aErrStr.isEmpty()) { + aErrList.append(tr(aErrStr.toLatin1().constData())); + } } + + myGrp->ListBox1->clear(); + myGrp->ListBox2->clear(); + myGrp->ListBox1->addItems( aErrList ); +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr MeasureGUI_CheckShapeDlg::createOperation() +{ + return getGeomEngine()->GetIMeasureOperations( getStudyId() ); +} + +//================================================================================= +// function : onErrorsListSelectionChanged +// purpose : +//================================================================================= +void MeasureGUI_CheckShapeDlg::onErrorsListSelectionChanged() +{ + erasePreview(); + + int aCurItem = myGrp->ListBox1->currentRow(); + + if ( aCurItem < 0 ) { + return; + } + + bool isShapeValid; + GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs; + + if ( !getErrors( isShapeValid, aErrs ) ) { + myGrp->TextView1->setText( "" ); + myGrp->ListBox1->clear(); + myGrp->ListBox2->clear(); + + return; + } + + myGrp->ListBox2->clear(); + + if (aCurItem < aErrs.length()) { + GEOM::GEOM_IMeasureOperations::ShapeError aErr = aErrs[aCurItem]; + GEOM::ListOfLong aObjLst = aErr.incriminated; + QStringList aSubShapeList; + TopoDS_Shape aSelShape; + + if ( !myObj->_is_nil() && GEOMBase::GetShape( myObj, aSelShape ) ) { + TopTools_IndexedMapOfShape anIndices; + + TopExp::MapShapes( aSelShape, anIndices ); + + for ( int i = 0, n = aObjLst.length(); i < n; i++ ) { + TopoDS_Shape aSubShape = anIndices.FindKey( aObjLst[i] ); + QString aType = GEOMBase::GetShapeTypeString( aSubShape ); + + if ( !aType.isEmpty() ) { + aSubShapeList.append( QString( "%1_%2" ).arg( aType ).arg( aObjLst[i] ) ); + } + } + } + + myGrp->ListBox2->addItems( aSubShapeList ); + } +} + +//================================================================================= +// function : onSubShapesListSelectionChanged +// purpose : +//================================================================================= +void MeasureGUI_CheckShapeDlg::onSubShapesListSelectionChanged() +{ + erasePreview(); + + int aErrCurItem = myGrp->ListBox1->currentRow(); + + if (aErrCurItem < 0) { + return; + } + + QList aIds; + + for (int i = 0, n = myGrp->ListBox2->count(); i < n; i++) { + if (myGrp->ListBox2->item( i )->isSelected()) { + aIds.append(i); + } + } + + if (aIds.count() < 1) { + return; + } + + bool isShapeValid; + GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs; + + if (!getErrors(isShapeValid, aErrs)) { + myGrp->TextView1->setText(""); + myGrp->ListBox1->clear(); + myGrp->ListBox2->clear(); + + return; + } + + GEOM::GEOM_IMeasureOperations::ShapeError aErr = aErrs[aErrCurItem]; + GEOM::ListOfLong aObjLst = aErr.incriminated; + TopoDS_Shape aSelShape; + TopoDS_Shape aSubShape; + TopTools_IndexedMapOfShape anIndices; + + if (!myObj->_is_nil() && GEOMBase::GetShape(myObj, aSelShape)) { + QString aMess; + + if (!isValid(aMess)) { + return; + } + + SALOME_Prs* aPrs = 0; + QList::iterator it; + + TopExp::MapShapes(aSelShape, anIndices); + + for (it = aIds.begin(); it != aIds.end(); ++it) { + SUIT_ResourceMgr* resMgr = SUIT_Session::session()->resourceMgr(); + int w = resMgr->integerValue("Geometry", "measures_line_width", 1); + + aSubShape = anIndices.FindKey(aObjLst[(*it)]); + + try { + getDisplayer()->SetColor( Quantity_NOC_RED ); + getDisplayer()->SetWidth( w ); + getDisplayer()->SetToActivate( false ); + aPrs = !aSubShape.IsNull() ? getDisplayer()->BuildPrs(aSubShape) : 0; + + if (aPrs) { + displayPreview(aPrs, true); + } + } + catch (const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); + } + } + } +} + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool MeasureGUI_CheckShapeDlg::execute( ObjectList& objects ) +{ + bool isShapeValid; + GEOM::GEOM_IMeasureOperations::ShapeErrors aErrs; + + if (!getErrors(isShapeValid, aErrs)) { + return false; + } + + const int aNbErrsSelected = myGrp->ListBox1->selectedItems().size(); + const bool isPublishAllErrors = (aNbErrsSelected < 1); + const bool isPublishAllShapes = + (aNbErrsSelected != 1 || myGrp->ListBox2->selectedItems().empty()); + TColStd_IndexedMapOfInteger aMapIndex; + const int aNbErrs = aErrs.length(); + int i; + + // Collect indices of shapes to be published. + for (i = 0; i < aNbErrs; i++) { + if (isPublishAllErrors || myGrp->ListBox1->item(i)->isSelected()) { + GEOM::ListOfLong aObjLst = aErrs[i].incriminated; + const int aNbShapes = aObjLst.length(); + int j; + + for (j = 0; j < aNbShapes; j++) { + if (isPublishAllShapes || myGrp->ListBox2->item(j)->isSelected()) { + aMapIndex.Add(aObjLst[j]); + } + } + } + } + + // Create objects. + GEOM::ListOfLong_var anArray = new GEOM::ListOfLong; + const int aNbShapes = aMapIndex.Extent(); + + anArray->length(aNbShapes); + + for (i = 1; i <= aNbShapes; i++) { + anArray[i - 1] = aMapIndex.FindKey(i); + } + + if (myShapesOper->_is_nil()) { + myShapesOper = getGeomEngine()->GetIShapesOperations(getStudyId()); + } + + GEOM::ListOfGO_var aList = myShapesOper->MakeSubShapes(myObj, anArray); + const int aNbObj = aList->length(); + + for (i = 0; i < aNbObj; i++) { + objects.push_back(GEOM::GEOM_Object::_duplicate(aList[i])); + } + + return true; } diff --git a/src/MeasureGUI/MeasureGUI_CheckShapeDlg.h b/src/MeasureGUI/MeasureGUI_CheckShapeDlg.h index ade60714d..a2ace0ae2 100644 --- a/src/MeasureGUI/MeasureGUI_CheckShapeDlg.h +++ b/src/MeasureGUI/MeasureGUI_CheckShapeDlg.h @@ -27,15 +27,15 @@ #ifndef MEASUREGUI_CHECKSHAPEDLG_H #define MEASUREGUI_CHECKSHAPEDLG_H -#include "MeasureGUI_Skeleton.h" +#include -class MeasureGUI_1Sel1TextView1Check; +class MeasureGUI_1Sel1Check1TextView2ListBox; //================================================================================= // class : MeasureGUI_CheckShapeDlg // purpose : //================================================================================= -class MeasureGUI_CheckShapeDlg : public MeasureGUI_Skeleton +class MeasureGUI_CheckShapeDlg : public GEOMBase_Skeleton { Q_OBJECT @@ -45,14 +45,32 @@ public: protected: // redefined from GEOMBase_Helper and MeasureGUI_Skeleton - virtual void processObject(); + virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool execute( ObjectList& ); + virtual void processObject(); + virtual void activateSelection(); + virtual bool isValid( QString& ); + virtual bool extractPrefix() const; + +private slots: + void SelectionIntoArgument(); + void ClickOnOk(); + bool ClickOnApply(); + void ActivateThisDialog(); + void SetEditCurrentArgument(); + void onErrorsListSelectionChanged(); + void onSubShapesListSelectionChanged(); private: - void Init(); - bool getParameters( bool&, QString& ); + void Init(); + void enterEvent( QEvent* ); + bool getErrors + ( bool&, GEOM::GEOM_IMeasureOperations::ShapeErrors&); private: - MeasureGUI_1Sel1TextView1Check* myGrp; + GEOM::GEOM_Object_var myObj; + MeasureGUI_1Sel1Check1TextView2ListBox* myGrp; + GEOM::GEOM_IShapesOperations_var myShapesOper; }; #endif // MEASUREGUI_CHECKSHAPEDLG_H diff --git a/src/MeasureGUI/MeasureGUI_Widgets.cxx b/src/MeasureGUI/MeasureGUI_Widgets.cxx index 2cbbeec46..77cdd68f3 100644 --- a/src/MeasureGUI/MeasureGUI_Widgets.cxx +++ b/src/MeasureGUI/MeasureGUI_Widgets.cxx @@ -65,6 +65,21 @@ MeasureGUI_1Sel1TextView2ListBox::~MeasureGUI_1Sel1TextView2ListBox() { } +////////////////////////////////////////// +// MeasureGUI_1Sel1Check1TextView2ListBox +////////////////////////////////////////// + +MeasureGUI_1Sel1Check1TextView2ListBox::MeasureGUI_1Sel1Check1TextView2ListBox( QWidget* parent, + Qt::WindowFlags f ) +: QWidget( parent, f ) +{ + setupUi( this ); +} + +MeasureGUI_1Sel1Check1TextView2ListBox::~MeasureGUI_1Sel1Check1TextView2ListBox() +{ +} + ////////////////////////////////////////// // MeasureGUI_1Sel1TextView ////////////////////////////////////////// diff --git a/src/MeasureGUI/MeasureGUI_Widgets.h b/src/MeasureGUI/MeasureGUI_Widgets.h index 02fe6ea92..1f1f38824 100644 --- a/src/MeasureGUI/MeasureGUI_Widgets.h +++ b/src/MeasureGUI/MeasureGUI_Widgets.h @@ -71,6 +71,22 @@ public: ~MeasureGUI_1Sel1TextView2ListBox(); }; +////////////////////////////////////////// +// MeasureGUI_1Sel1Check1TextView2ListBox +////////////////////////////////////////// + +#include "ui_MeasureGUI_1Sel1Check1TextView2ListBox_QTD.h" + +class MeasureGUI_1Sel1Check1TextView2ListBox : public QWidget, + public Ui::MeasureGUI_1Sel1Check1TextView2ListBox_QTD +{ + Q_OBJECT + +public: + MeasureGUI_1Sel1Check1TextView2ListBox( QWidget* = 0, Qt::WindowFlags = 0 ); + ~MeasureGUI_1Sel1Check1TextView2ListBox(); +}; + ////////////////////////////////////////// // MeasureGUI_1Sel1TextView //////////////////////////////////////////