diff --git a/doc/salome/gui/GEOM/images/limit_tolerance_dlg.png b/doc/salome/gui/GEOM/images/limit_tolerance_dlg.png new file mode 100644 index 000000000..98adfc454 Binary files /dev/null and b/doc/salome/gui/GEOM/images/limit_tolerance_dlg.png differ diff --git a/doc/salome/gui/GEOM/input/limit_tolerance_operation.doc b/doc/salome/gui/GEOM/input/limit_tolerance_operation.doc new file mode 100644 index 000000000..7f692656d --- /dev/null +++ b/doc/salome/gui/GEOM/input/limit_tolerance_operation.doc @@ -0,0 +1,23 @@ +/*! + +\page limit_tolerance_operation_page Limit Tolerance + +\n To produce a Limit Tolerance operation in the Main + Menu select Repair - > Limit Tolerance. + +\n It is possible on all kind of shapes. + +\n The \b Result will be a \b GEOM_Object. + +\n TUI Command: geompy.LimitTolerance(Shape, Tolerance), + where \em Shape is a shape with presumably incorrect tolerance, \em + Tolerance is a desired value of tolerance. + +\image html limit_tolerance_dlg.png + +\n Arguments: Name + 1 shape + 1 value (new tolerance). + +Our TUI Scripts provide you with useful examples of the use of +\ref tui_limit_tolerance "Repairing Operations". + +*/ diff --git a/doc/salome/gui/GEOM/input/repairing_operations.doc b/doc/salome/gui/GEOM/input/repairing_operations.doc index 542f5c25e..592c1b653 100644 --- a/doc/salome/gui/GEOM/input/repairing_operations.doc +++ b/doc/salome/gui/GEOM/input/repairing_operations.doc @@ -17,6 +17,8 @@ holes with free boundaries on a selected face.
  • \subpage sewing_operation_page "Sewing" - sews faces or shells.
  • \subpage glue_faces_operation_page "Glue faces" - unites coincident faces within the given tolerance.
  • +
  • \subpage limit_tolerance_operation_page "Limit Tolerance" - tries +to set new tolerance value for the given shape.
  • \subpage add_point_on_edge_operation_page "Add point on edge" - splits an edge in two.
  • \subpage change_orientation_operation_page "Change orientation" - diff --git a/doc/salome/gui/GEOM/input/tui_repairing_operations.doc b/doc/salome/gui/GEOM/input/tui_repairing_operations.doc index 98dccc6f0..ff562631f 100644 --- a/doc/salome/gui/GEOM/input/tui_repairing_operations.doc +++ b/doc/salome/gui/GEOM/input/tui_repairing_operations.doc @@ -289,6 +289,31 @@ gg.createAndDisplayGO(id_glue) gg.setDisplayMode(id_glue,1) \endcode +\anchor tui_limit_tolerance +

    Limit Tolerance

    + +\code +import geompy +gg = salome.ImportComponentGUI("GEOM") + +# import initial topology +bad_shape = geompy.ImportBREP("my_bad_shape.brep") + +# limit tolerance +tolerance = 1e-07 +good_shape = geompy.LimitTolerance(bad_shape, tolerance) + +# add objects in the study +id_bad_shape = geompy.addToStudy(bad_shape, "My Bad Shape") +id_good_shape = geompy.addToStudy(good_shape, "My Good Shape") + +# display the results +gg.createAndDisplayGO(id_bad_shape) +gg.setDisplayMode(id_bad_shape, 1) +gg.createAndDisplayGO(id_good_shape) +gg.setDisplayMode(id_good_shape, 1) +\endcode + \anchor tui_add_point_on_edge

    Add Point on Edge

    diff --git a/doc/salome/gui/GEOM/input/tui_test_others.doc b/doc/salome/gui/GEOM/input/tui_test_others.doc index 443326fea..e2c6d43b4 100644 --- a/doc/salome/gui/GEOM/input/tui_test_others.doc +++ b/doc/salome/gui/GEOM/input/tui_test_others.doc @@ -99,12 +99,21 @@ \anchor swig_GetPoint \until blocksComp (-50, -50, -50) +\anchor swig_GetVertexNearPoint +\until near (40, 40, 40) + +\anchor swig_GetEdge +\until by two points + \anchor swig_GetEdgeNearPoint \until edge near point \anchor swig_GetBlockByParts \until "b0 image" +\anchor swig_GetShapesNearPoint +\until "faces near point" + \anchor swig_GetShapesOnPlane \until Face on Plane diff --git a/idl/GEOM_Gen.idl b/idl/GEOM_Gen.idl index 164969e51..309d9bbe8 100644 --- a/idl/GEOM_Gen.idl +++ b/idl/GEOM_Gen.idl @@ -1905,6 +1905,15 @@ module GEOM in double theZ, in double theEpsilon); + /*! + * Find a vertex of the given shape, which has minimal distance to the given point. + * \param theShape Any shape. + * \param thePoint Point, close to the desired vertex. + * \return New GEOM_Object, containing the found vertex. + */ + GEOM_Object GetVertexNearPoint (in GEOM_Object theShape, + in GEOM_Object thePoint); + /*! * Get an edge, found in the given shape by two given vertices. * \param theShape Block or a compound of blocks. @@ -1973,6 +1982,22 @@ module GEOM GEOM_Object GetFaceByNormale (in GEOM_Object theBlock, in GEOM_Object theVector); + /*! + * Find all subshapes of type \a theShapeType of the given shape, + * which have minimal distance to the given point. + * \param theShape Any shape. + * \param thePoint Point, close to the desired shape. + * \param theShapeType Defines what kind of subshapes is searched. + * \param theTolerance The tolerance for distances comparison. All shapes + * with distances to the given point in interval + * [minimal_distance, minimal_distance + theTolerance] will be gathered. + * \return New GEOM_Object, containing a group of all found shapes. + */ + GEOM_Object GetShapesNearPoint (in GEOM_Object theShape, + in GEOM_Object thePoint, + in long theShapeType, + in double theTolerance); + /*! * Extract blocks from blocks compounds */ @@ -2726,6 +2751,14 @@ module GEOM GEOM_Object ChangeOrientation (in GEOM_Object theObject); GEOM_Object ChangeOrientationCopy (in GEOM_Object theObject); + /*! + * Try to limit tolerance of the given object by value \a theTolerance. + * \param theObject Shape to be processed. + * \param theTolerance Required tolerance value. + * \return New GEOM_Object, containing processed shape. + */ + GEOM_Object LimitTolerance (in GEOM_Object theObject, in double theTolerance); + }; /*! diff --git a/resources/Makefile.am b/resources/Makefile.am index 3ba2946e0..f8bc0a9dc 100644 --- a/resources/Makefile.am +++ b/resources/Makefile.am @@ -93,6 +93,7 @@ filletface.png \ filling.png \ fuse.png \ geometry.png \ +limit_tolerance.png \ line.png \ line2points.png \ line2faces.png \ diff --git a/resources/limit_tolerance.png b/resources/limit_tolerance.png new file mode 100644 index 000000000..35f20804e Binary files /dev/null and b/resources/limit_tolerance.png differ diff --git a/src/GEOMGUI/GEOM_images.ts b/src/GEOMGUI/GEOM_images.ts index 3dab5a404..e41de1d95 100644 --- a/src/GEOMGUI/GEOM_images.ts +++ b/src/GEOMGUI/GEOM_images.ts @@ -269,6 +269,10 @@ ICON_DLG_GLUE_FACES2 glue2.png + + ICON_DLG_LIMIT_TOLERANCE + limit_tolerance.png + ICON_DLG_INERTIA axisinertia.png @@ -849,6 +853,10 @@ ICO_GLUE_FACES glue.png + + ICO_LIMIT_TOLERANCE + limit_tolerance.png + ICO_GROUP_CREATE group_new.png diff --git a/src/GEOMGUI/GEOM_msg_en.ts b/src/GEOMGUI/GEOM_msg_en.ts index aac0da797..9a47a49af 100644 --- a/src/GEOMGUI/GEOM_msg_en.ts +++ b/src/GEOMGUI/GEOM_msg_en.ts @@ -771,6 +771,10 @@ Please, select face, shell or solid and try again GEOM_GLUE_TITLE Glue faces + + GEOM_LIMIT_TOLERANCE_TITLE + Limit tolerance + GEOM_HEIGHT Height : @@ -2055,6 +2059,10 @@ Please, select face, shell or solid and try again GLUE_NEW_OBJ_NAME Glue + + LIMIT_TOLERANCE_NEW_OBJ_NAME + Limit_tolerance + MEN_ALL_SEL_ONLY Select All @@ -2307,6 +2315,10 @@ Please, select face, shell or solid and try again MEN_ISOS Isos + + MEN_LIMIT_TOLERANCE + Limit tolerance + MEN_LINE Line @@ -2955,6 +2967,10 @@ Please, select face, shell or solid and try again STB_LINE Create a line + + STB_LIMIT_TOLERANCE + Limit tolerance + STB_LOCAL_CS Create a local coordinate system @@ -3479,6 +3495,10 @@ Please, select face, shell or solid and try again TOP_LINE Create a line + + TOP_LIMIT_TOLERANCE + Limit tolerance + TOP_LOCAL_CS Create a local coordinate system diff --git a/src/GEOMGUI/GeometryGUI.cxx b/src/GEOMGUI/GeometryGUI.cxx index 1edeb1ada..44d9898fd 100644 --- a/src/GEOMGUI/GeometryGUI.cxx +++ b/src/GEOMGUI/GeometryGUI.cxx @@ -19,11 +19,10 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// GEOM GEOMGUI : GUI for Geometry component +// File : GeometryGUI.cxx +// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// GEOM GEOMGUI : GUI for Geometry component -// File : GeometryGUI.cxx -// Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// #include // E.A. must be included before Python.h to fix compilation on windows #include "Python.h" #include "GeometryGUI.h" @@ -476,6 +475,7 @@ void GeometryGUI::OnGUIEvent( int id ) case GEOMOp::OpFreeFaces: // MENU MEASURE - FREE FACES case GEOMOp::OpOrientation: // MENU REPAIR - CHANGE ORIENTATION case GEOMOp::OpGlueFaces: // MENU REPAIR - GLUE FACES + case GEOMOp::OpLimitTolerance: // MENU REPAIR - LIMIT TOLERANCE case GEOMOp::OpRemoveExtraEdges: // MENU REPAIR - REMOVE EXTRA EDGES libName = "RepairGUI"; break; @@ -580,7 +580,7 @@ void GeometryGUI::createGeomAction( const int id, const QString& label, const QS createAction( id, tr( QString( "TOP_%1" ).arg( label ).toLatin1().constData() ), icon, - tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ), + tr( QString( "MEN_%1" ).arg( label ).toLatin1().constData() ), tr( QString( "STB_%1" ).arg( label ).toLatin1().constData() ), accel, application()->desktop(), @@ -706,6 +706,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpSewing, "SEWING" ); createGeomAction( GEOMOp::OpGlueFaces, "GLUE_FACES" ); + createGeomAction( GEOMOp::OpLimitTolerance, "LIMIT_TOLERANCE" ); createGeomAction( GEOMOp::OpSuppressFaces, "SUPPRESS_FACES" ); createGeomAction( GEOMOp::OpSuppressHoles, "SUPPERSS_HOLES" ); createGeomAction( GEOMOp::OpShapeProcess, "SHAPE_PROCESS" ); @@ -765,7 +766,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createGeomAction( GEOMOp::OpShowChildren, "POP_SHOW_CHILDREN" ); createGeomAction( GEOMOp::OpHideChildren, "POP_HIDE_CHILDREN" ); createGeomAction( GEOMOp::OpPointMarker, "POP_POINT_MARKER" ); - + createGeomAction( GEOMOp::OpPipeTShape, "PIPETSHAPE" ); // createGeomAction( GEOMOp::OpPipeTShapeGroups, "PIPETSHAPEGROUPS" ); //@@ insert new functions before this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@ do not remove this line @@// @@ -891,6 +892,7 @@ void GeometryGUI::initialize( CAM_Application* app ) createMenu( GEOMOp::OpSuppressHoles, repairId, -1 ); createMenu( GEOMOp::OpSewing, repairId, -1 ); createMenu( GEOMOp::OpGlueFaces, repairId, -1 ); + createMenu( GEOMOp::OpLimitTolerance, repairId, -1 ); createMenu( GEOMOp::OpAddPointOnEdge, repairId, -1 ); //createMenu( GEOMOp::OpFreeBoundaries, repairId, -1 ); //createMenu( GEOMOp::OpFreeFaces, repairId, -1 ); @@ -1210,7 +1212,7 @@ bool GeometryGUI::activateModule( SUIT_Study* study ) SALOME_ListIO selected; sm->selectedObjects( selected ); sm->clearSelected(); - + // disable OCC selectors getApp()->selectionMgr()->setEnabled( false, OCCViewer_Viewer::Type() ); QListIterator itOCCSel( myOCCSelectors ); @@ -1473,7 +1475,7 @@ void GeometryGUI::createPreferences() setPreferenceProperty( genGroup, "columns", 2 ); int dispmode = addPreference( tr( "PREF_DISPLAY_MODE" ), genGroup, - LightApp_Preferences::Selector, + LightApp_Preferences::Selector, "Geometry", "display_mode" ); addPreference( tr( "PREF_SHADING_COLOR" ), genGroup, @@ -1499,36 +1501,36 @@ void GeometryGUI::createPreferences() int defl = addPreference( tr( "PREF_DEFLECTION" ), genGroup, LightApp_Preferences::DblSpin, "Geometry", "deflection_coeff" ); - + // Quantities with individual precision settings int precGroup = addPreference( tr( "GEOM_PREF_GROUP_PRECISION" ), tabId ); setPreferenceProperty( precGroup, "columns", 2 ); - + const int nbQuantities = 8; int prec[nbQuantities], ii = 0; prec[ii++] = addPreference( tr( "GEOM_PREF_length_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "length_precision" ); + LightApp_Preferences::IntSpin, "Geometry", "length_precision" ); prec[ii++] = addPreference( tr( "GEOM_PREF_angle_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "angle_precision" ); + LightApp_Preferences::IntSpin, "Geometry", "angle_precision" ); prec[ii++] = addPreference( tr( "GEOM_PREF_len_tol_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" ); + LightApp_Preferences::IntSpin, "Geometry", "len_tol_precision" ); prec[ii++] = addPreference( tr( "GEOM_PREF_ang_tol_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" ); + LightApp_Preferences::IntSpin, "Geometry", "ang_tol_precision" ); prec[ii++] = addPreference( tr( "GEOM_PREF_weight_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "weight_precision" ); + LightApp_Preferences::IntSpin, "Geometry", "weight_precision" ); prec[ii++] = addPreference( tr( "GEOM_PREF_density_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "density_precision" ); + LightApp_Preferences::IntSpin, "Geometry", "density_precision" ); prec[ii++] = addPreference( tr( "GEOM_PREF_parametric_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" ); + LightApp_Preferences::IntSpin, "Geometry", "parametric_precision" ); prec[ii ] = addPreference( tr( "GEOM_PREF_param_tol_precision" ), precGroup, - LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" ); - + LightApp_Preferences::IntSpin, "Geometry", "param_tol_precision" ); + // Set property for precision value for spinboxes for ( ii = 0; ii < nbQuantities; ii++ ){ setPreferenceProperty( prec[ii], "min", -14 ); setPreferenceProperty( prec[ii], "max", 14 ); setPreferenceProperty( prec[ii], "precision", 2 ); - } + } int VertexGroup = addPreference( tr( "PREF_GROUP_VERTEX" ), tabId ); setPreferenceProperty( VertexGroup, "columns", 2 ); diff --git a/src/GEOMGUI/GeometryGUI_Operations.h b/src/GEOMGUI/GeometryGUI_Operations.h index 311dbbe76..c027220c9 100644 --- a/src/GEOMGUI/GeometryGUI_Operations.h +++ b/src/GEOMGUI/GeometryGUI_Operations.h @@ -16,10 +16,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - // File : GeometryGUI_Operations.h // Author : Vadim SANDLER, Open CASCADE S.A.S. (vadim.sandler@opencascade.com) -// + #ifndef GEOMETRYGUI_OPERATIONS_H #define GEOMETRYGUI_OPERATIONS_H @@ -131,6 +130,7 @@ namespace GEOMOp { OpOrientation = 4009, // MENU REPAIR - CHANGE ORIENTATION OpGlueFaces = 4010, // MENU REPAIR - GLUE FACES OpRemoveExtraEdges = 4011, // MENU REPAIR - REMOVE EXTRA EDGES + OpLimitTolerance = 4012, // MENU REPAIR - LIMIT TOLERANCE // MeasureGUI ----------------//-------------------------------- OpProperties = 5000, // MENU MEASURES - PROPERTIES OpCenterMass = 5001, // MENU MEASURES - CENTRE OF MASS @@ -160,6 +160,6 @@ namespace GEOMOp { // OpPipeTShapeGroups = 10002, // MENU NEW ENTITY - ADVANCED - PIPE TSHAPE GROUPS //@@ insert new functions before this line @@ do not remove this line @@// }; -} +} #endif // GEOMETRYGUI_OPERATIONS_H diff --git a/src/GEOMImpl/GEOMImpl_HealingDriver.cxx b/src/GEOMImpl/GEOMImpl_HealingDriver.cxx index 5670d099b..d59b07203 100644 --- a/src/GEOMImpl/GEOMImpl_HealingDriver.cxx +++ b/src/GEOMImpl/GEOMImpl_HealingDriver.cxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #include @@ -45,6 +44,12 @@ #include #include +#include +#include +#include +#include +#include + #include #include @@ -126,6 +131,9 @@ Standard_Integer GEOMImpl_HealingDriver::Execute(TFunction_Logbook& log) const case CHANGE_ORIENTATION: ChangeOrientation(&HI, anOriginalShape, aShape); break; + case LIMIT_TOLERANCE: + LimitTolerance(&HI, anOriginalShape, aShape); + break; default: return 0; } @@ -465,6 +473,36 @@ Standard_Boolean GEOMImpl_HealingDriver::ChangeOrientation (GEOMImpl_IHealing* t return aResult; } +//======================================================================= +//function : LimitTolerance +//purpose : +//======================================================================= +void GEOMImpl_HealingDriver::LimitTolerance (GEOMImpl_IHealing* theHI, + const TopoDS_Shape& theOriginalShape, + TopoDS_Shape& theOutShape) const +{ + Standard_Real aTol = theHI->GetTolerance(); + if (aTol < Precision::Confusion()) + aTol = Precision::Confusion(); + + // 1. Make a copy to prevent the original shape changes. + TopoDS_Shape aShapeCopy; + TColStd_IndexedDataMapOfTransientTransient aMapTShapes; + TNaming_CopyShape::CopyTool(theOriginalShape, aMapTShapes, aShapeCopy); + + // 2. Limit tolerance. + ShapeFix_ShapeTolerance aSFT; + aSFT.LimitTolerance(aShapeCopy, aTol, aTol, TopAbs_SHAPE); + + // 3. Fix obtained shape. + Handle(ShapeFix_Shape) aSfs = new ShapeFix_Shape (aShapeCopy); + aSfs->Perform(); + theOutShape = aSfs->Shape(); + + BRepCheck_Analyzer ana (theOutShape, Standard_True); + if (!ana.IsValid()) + StdFail_NotDone::Raise("Non valid shape result"); +} //======================================================================= //function : GEOMImpl_HealingDriver_Type_ diff --git a/src/GEOMImpl/GEOMImpl_HealingDriver.hxx b/src/GEOMImpl/GEOMImpl_HealingDriver.hxx index 344cf770c..4e4b44b49 100644 --- a/src/GEOMImpl/GEOMImpl_HealingDriver.hxx +++ b/src/GEOMImpl/GEOMImpl_HealingDriver.hxx @@ -19,10 +19,9 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // - // File : GEOMImpl_HealingDriver.hxx // Module : GEOMImpl -// + #ifndef _GEOMImpl_HealingDriver_HeaderFile #define _GEOMImpl_HealingDriver_HeaderFile @@ -156,7 +155,7 @@ Standard_EXPORT ~GEOMImpl_HealingDriver() {}; // Standard_EXPORT friend Handle_Standard_Type& GEOMImpl_HealingDriver_Type_(); Standard_EXPORT const Handle(Standard_Type)& DynamicType() const { return STANDARD_TYPE(GEOMImpl_HealingDriver) ; } -Standard_EXPORT Standard_Boolean IsKind(const Handle(Standard_Type)& AType) const { return (STANDARD_TYPE(GEOMImpl_HealingDriver) == AType || TFunction_Driver::IsKind(AType)); } +Standard_EXPORT Standard_Boolean IsKind(const Handle(Standard_Type)& AType) const { return (STANDARD_TYPE(GEOMImpl_HealingDriver) == AType || TFunction_Driver::IsKind(AType)); } private: Standard_Boolean ShapeProcess ( GEOMImpl_IHealing*, const TopoDS_Shape&, TopoDS_Shape& ) const; @@ -167,7 +166,7 @@ Standard_Boolean RemoveHoles ( GEOMImpl_IHealing*, const TopoDS_Shape&, TopoDS Standard_Boolean Sew ( GEOMImpl_IHealing*, const TopoDS_Shape&, TopoDS_Shape& ) const; Standard_Boolean AddPointOnEdge( GEOMImpl_IHealing*, const TopoDS_Shape&, TopoDS_Shape& ) const; Standard_Boolean ChangeOrientation( GEOMImpl_IHealing*, const TopoDS_Shape&, TopoDS_Shape& ) const; - +void LimitTolerance( GEOMImpl_IHealing*, const TopoDS_Shape&, TopoDS_Shape& ) const; }; diff --git a/src/GEOMImpl/GEOMImpl_IBlocksOperations.cxx b/src/GEOMImpl/GEOMImpl_IBlocksOperations.cxx index 3aeca3008..b4c4ebd77 100644 --- a/src/GEOMImpl/GEOMImpl_IBlocksOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IBlocksOperations.cxx @@ -569,6 +569,81 @@ Handle(GEOM_Object) GEOMImpl_IBlocksOperations::GetPoint return aResult; } +//============================================================================= +/*! + * GetVertexNearPoint + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IBlocksOperations::GetVertexNearPoint + (Handle(GEOM_Object) theShape, + Handle(GEOM_Object) thePoint) +{ + SetErrorCode(KO); + + // New Point object + Handle(GEOM_Object) aResult; + + // Arguments + if (theShape.IsNull() || thePoint.IsNull()) return NULL; + + TopoDS_Shape aBlockOrComp = theShape->GetValue(); + TopoDS_Shape aPoint = thePoint->GetValue(); + if (aBlockOrComp.IsNull() || aPoint.IsNull()) { + SetErrorCode("Given shape is null"); + return NULL; + } + + if (aPoint.ShapeType() != TopAbs_VERTEX) { + SetErrorCode("Element for vertex identification is not a vertex"); + return NULL; + } + + TopoDS_Vertex aVert = TopoDS::Vertex(aPoint); + gp_Pnt aP = BRep_Tool::Pnt(aVert); + + // Compute the Vertex value + TopoDS_Shape V; + bool isFound = false; + Standard_Real aDist = RealLast(); + TopTools_MapOfShape mapShape; + + TopExp_Explorer exp (aBlockOrComp, TopAbs_VERTEX); + for (; exp.More(); exp.Next()) { + if (mapShape.Add(exp.Current())) { + TopoDS_Vertex aVi = TopoDS::Vertex(exp.Current()); + gp_Pnt aPi = BRep_Tool::Pnt(aVi); + Standard_Real aDisti = aPi.Distance(aP); + if (aDisti < aDist) { + V = aVi; + aDist = aDisti; + isFound = true; + } + } + } + + if (!isFound) { + SetErrorCode("Vertex has not been found"); + return NULL; + } + + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(aBlockOrComp, anIndices); + Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger(1,1); + anArray->SetValue(1, anIndices.FindIndex(V)); + aResult = GetEngine()->AddSubShape(theShape, anArray); + + // The GetPoint() doesn't change object so no new function is required. + Handle(GEOM_Function) aFunction = theShape->GetLastFunction(); + + // Make a Python command + GEOM::TPythonDump(aFunction, /*append=*/true) + << aResult << " = geompy.GetVertexNearPoint(" + << theShape << ", " << thePoint << ")"; + + SetErrorCode(OK); + return aResult; +} + //============================================================================= /*! * GetEdge @@ -1458,6 +1533,136 @@ Handle(GEOM_Object) GEOMImpl_IBlocksOperations::GetFaceByNormale return aResult; } +//============================================================================= +/*! + * GetShapesNearPoint + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IBlocksOperations::GetShapesNearPoint + (Handle(GEOM_Object) theShape, + Handle(GEOM_Object) thePoint, + const Standard_Integer theShapeType, + const Standard_Real theTolerance) +{ + SetErrorCode(KO); + + // New object + Handle(GEOM_Object) aResult; + + // Arguments + if (theShape.IsNull() || thePoint.IsNull()) return NULL; + + TopoDS_Shape aBlockOrComp = theShape->GetValue(); + if (aBlockOrComp.IsNull()) { + SetErrorCode("Block or compound is null"); + return NULL; + } + + TopoDS_Shape anArg = thePoint->GetValue(); + if (anArg.IsNull()) { + SetErrorCode("Null shape is given as argument"); + return NULL; + } + if (anArg.ShapeType() != TopAbs_VERTEX) { + SetErrorCode("Element for face identification is not a vertex"); + return NULL; + } + + if (theShapeType < TopAbs_SOLID || TopAbs_VERTEX < theShapeType) { + SetErrorCode("Invalid type of result is requested"); + return NULL; + } + + if (theTolerance < Precision::Confusion()) { + theTolerance == Precision::Confusion(); + } + + // Compute the result + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif + TopoDS_Vertex aVert = TopoDS::Vertex(anArg); + + TopTools_MapOfShape mapShape; + Standard_Integer nbEdges = 0; + TopExp_Explorer exp (aBlockOrComp, TopAbs_ShapeEnum(theShapeType)); + for (; exp.More(); exp.Next()) { + if (mapShape.Add(exp.Current())) { + nbEdges++; + } + } + + if (nbEdges == 0) { + SetErrorCode("Given shape contains no subshapes of requested type"); + return NULL; + } + + // Calculate distances and find min + mapShape.Clear(); + Standard_Integer ind = 1; + Standard_Real aMinDist = RealLast(); + TopTools_Array1OfShape anEdges (1, nbEdges); + TColStd_Array1OfReal aDistances (1, nbEdges); + for (exp.Init(aBlockOrComp, TopAbs_ShapeEnum(theShapeType)); exp.More(); exp.Next()) { + if (mapShape.Add(exp.Current())) { + TopoDS_Shape anEdge = exp.Current(); + anEdges(ind) = anEdge; + + BRepExtrema_DistShapeShape aDistTool (aVert, anEdges(ind)); + if (!aDistTool.IsDone()) { + SetErrorCode("Can not find a distance from the given point to one of subshapes"); + return NULL; + } + aDistances(ind) = aDistTool.Value(); + if (aDistances(ind) < aMinDist) { + aMinDist = aDistances(ind); + } + ind++; + } + } + + if (aMinDist < RealLast()) { + // Collect subshapes with distance < (aMinDist + theTolerance) + int nbSubShapes = 0; + TopTools_Array1OfShape aNearShapes (1, nbEdges); + for (ind = 1; ind <= nbEdges; ind++) { + if (aDistances(ind) < aMinDist + theTolerance) { + nbSubShapes++; + aNearShapes(nbSubShapes) = anEdges(ind); + } + } + + // Add subshape + TopTools_IndexedMapOfShape anIndices; + TopExp::MapShapes(aBlockOrComp, anIndices); + Handle(TColStd_HArray1OfInteger) anArray = new TColStd_HArray1OfInteger (1, nbSubShapes); + for (ind = 1; ind <= nbSubShapes; ind++) { + anArray->SetValue(ind, anIndices.FindIndex(aNearShapes(ind))); + } + aResult = GetEngine()->AddSubShape(theShape, anArray); + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + if (aResult.IsNull()) + return NULL; + + Handle(GEOM_Function) aFunction = aResult->GetLastFunction(); + + //Make a Python command + GEOM::TPythonDump(aFunction) + << aResult << " = geompy.GetShapesNearPoint(" << theShape << ", " << thePoint + << ", " << TopAbs_ShapeEnum(theShapeType) << ", " << theTolerance << ")"; + + SetErrorCode(OK); + return aResult; +} + //============================================================================= /*! * IsCompoundOfBlocks diff --git a/src/GEOMImpl/GEOMImpl_IBlocksOperations.hxx b/src/GEOMImpl/GEOMImpl_IBlocksOperations.hxx index c5ce21151..43caa5883 100644 --- a/src/GEOMImpl/GEOMImpl_IBlocksOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IBlocksOperations.hxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifndef _GEOMImpl_IBlocksOperations_HXX_ #define _GEOMImpl_IBlocksOperations_HXX_ @@ -41,68 +40,76 @@ class GEOMImpl_IBlocksOperations : public GEOM_IOperations { // Creation of blocks and block faces Standard_EXPORT Handle(GEOM_Object) MakeQuad (Handle(GEOM_Object) theEdge1, - Handle(GEOM_Object) theEdge2, - Handle(GEOM_Object) theEdge3, - Handle(GEOM_Object) theEdge4); + Handle(GEOM_Object) theEdge2, + Handle(GEOM_Object) theEdge3, + Handle(GEOM_Object) theEdge4); Standard_EXPORT Handle(GEOM_Object) MakeQuad2Edges (Handle(GEOM_Object) theEdge1, - Handle(GEOM_Object) theEdge2); + Handle(GEOM_Object) theEdge2); Standard_EXPORT Handle(GEOM_Object) MakeQuad4Vertices (Handle(GEOM_Object) thePoint1, - Handle(GEOM_Object) thePoint2, - Handle(GEOM_Object) thePoint3, - Handle(GEOM_Object) thePoint4); + Handle(GEOM_Object) thePoint2, + Handle(GEOM_Object) thePoint3, + Handle(GEOM_Object) thePoint4); Standard_EXPORT Handle(GEOM_Object) MakeHexa (Handle(GEOM_Object) theFace1, - Handle(GEOM_Object) theFace2, - Handle(GEOM_Object) theFace3, - Handle(GEOM_Object) theFace4, - Handle(GEOM_Object) theFace5, - Handle(GEOM_Object) theFace6); + Handle(GEOM_Object) theFace2, + Handle(GEOM_Object) theFace3, + Handle(GEOM_Object) theFace4, + Handle(GEOM_Object) theFace5, + Handle(GEOM_Object) theFace6); Standard_EXPORT Handle(GEOM_Object) MakeHexa2Faces (Handle(GEOM_Object) theFace1, - Handle(GEOM_Object) theFace2); + Handle(GEOM_Object) theFace2); Standard_EXPORT Handle(GEOM_Object) MakeBlockCompound (Handle(GEOM_Object) theCompound); // Extract elements of blocks and blocks compounds Standard_EXPORT Handle(GEOM_Object) GetPoint (Handle(GEOM_Object) theShape, - const Standard_Real theX, - const Standard_Real theY, - const Standard_Real theZ, - const Standard_Real theEpsilon); + const Standard_Real theX, + const Standard_Real theY, + const Standard_Real theZ, + const Standard_Real theEpsilon); + + Standard_EXPORT Handle(GEOM_Object) GetVertexNearPoint (Handle(GEOM_Object) theShape, + Handle(GEOM_Object) thePoint); Standard_EXPORT Handle(GEOM_Object) GetEdge (Handle(GEOM_Object) theShape, - Handle(GEOM_Object) thePoint1, - Handle(GEOM_Object) thePoint2); + Handle(GEOM_Object) thePoint1, + Handle(GEOM_Object) thePoint2); Standard_EXPORT Handle(GEOM_Object) GetEdgeNearPoint (Handle(GEOM_Object) theBlock, - Handle(GEOM_Object) thePoint); + Handle(GEOM_Object) thePoint); Standard_EXPORT Handle(GEOM_Object) GetFaceByPoints (Handle(GEOM_Object) theShape, - Handle(GEOM_Object) thePoint1, - Handle(GEOM_Object) thePoint2, - Handle(GEOM_Object) thePoint3, - Handle(GEOM_Object) thePoint4); + Handle(GEOM_Object) thePoint1, + Handle(GEOM_Object) thePoint2, + Handle(GEOM_Object) thePoint3, + Handle(GEOM_Object) thePoint4); Standard_EXPORT Handle(GEOM_Object) GetFaceByEdges (Handle(GEOM_Object) theShape, - Handle(GEOM_Object) theEdge1, - Handle(GEOM_Object) theEdge2); + Handle(GEOM_Object) theEdge1, + Handle(GEOM_Object) theEdge2); Standard_EXPORT Handle(GEOM_Object) GetOppositeFace (Handle(GEOM_Object) theBlock, - Handle(GEOM_Object) theFace); + Handle(GEOM_Object) theFace); Standard_EXPORT Handle(GEOM_Object) GetFaceNearPoint (Handle(GEOM_Object) theBlock, - Handle(GEOM_Object) thePoint); + Handle(GEOM_Object) thePoint); Standard_EXPORT Handle(GEOM_Object) GetFaceByNormale (Handle(GEOM_Object) theBlock, - Handle(GEOM_Object) theVector); + Handle(GEOM_Object) theVector); + + Standard_EXPORT Handle(GEOM_Object) GetShapesNearPoint (Handle(GEOM_Object) theShape, + Handle(GEOM_Object) thePoint, + const Standard_Integer theShapeType, + const Standard_Real theTolerance); // Check blocks compounds Standard_EXPORT Standard_Boolean IsCompoundOfBlocks (Handle(GEOM_Object) theCompound, - const Standard_Integer theMinNbFaces, - const Standard_Integer theMaxNbFaces, - Standard_Integer& theNbBlocks); + const Standard_Integer theMinNbFaces, + const Standard_Integer theMaxNbFaces, + Standard_Integer& theNbBlocks); enum BCErrorType { NOT_BLOCK, @@ -118,13 +125,13 @@ class GEOMImpl_IBlocksOperations : public GEOM_IOperations { }; Standard_EXPORT Standard_Boolean CheckCompoundOfBlocksOld (Handle(GEOM_Object) theCompound, - std::list& theErrors); + std::list& theErrors); Standard_EXPORT Standard_Boolean CheckCompoundOfBlocks (Handle(GEOM_Object) theCompound, - std::list& theErrors); + std::list& theErrors); Standard_EXPORT TCollection_AsciiString PrintBCErrors (Handle(GEOM_Object) theCompound, - const std::list& theErrors); + const std::list& theErrors); Standard_EXPORT Handle(GEOM_Object) RemoveExtraEdges (Handle(GEOM_Object) theShape, const Standard_Integer theOptimumNbFaces = 6); @@ -132,9 +139,9 @@ class GEOMImpl_IBlocksOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) CheckAndImprove (Handle(GEOM_Object) theCompound); Standard_EXPORT static void AddBlocksFrom (const TopoDS_Shape& theShape, - TopTools_ListOfShape& BLO, - TopTools_ListOfShape& NOT, - TopTools_ListOfShape& EXT); + TopTools_ListOfShape& BLO, + TopTools_ListOfShape& NOT, + TopTools_ListOfShape& EXT); // Extract blocks from blocks compounds Standard_EXPORT Handle(TColStd_HSequenceOfTransient) ExplodeCompoundOfBlocks @@ -143,7 +150,7 @@ class GEOMImpl_IBlocksOperations : public GEOM_IOperations { const Standard_Integer theMaxNbFaces); Standard_EXPORT Handle(GEOM_Object) GetBlockNearPoint (Handle(GEOM_Object) theCompound, - Handle(GEOM_Object) thePoint); + Handle(GEOM_Object) thePoint); Standard_EXPORT Handle(GEOM_Object) GetBlockByParts (Handle(GEOM_Object) theCompound, @@ -155,17 +162,17 @@ class GEOMImpl_IBlocksOperations : public GEOM_IOperations { // Operations on blocks with gluing of result Standard_EXPORT Handle(GEOM_Object) MakeMultiTransformation1D (Handle(GEOM_Object) theBlock, - const Standard_Integer theDirFace1, - const Standard_Integer theDirFace2, - const Standard_Integer theNbTimes); + const Standard_Integer theDirFace1, + const Standard_Integer theDirFace2, + const Standard_Integer theNbTimes); Standard_EXPORT Handle(GEOM_Object) MakeMultiTransformation2D (Handle(GEOM_Object) theBlock, - const Standard_Integer theDirFace1U, - const Standard_Integer theDirFace2U, - const Standard_Integer theNbTimesU, - const Standard_Integer theDirFace1V, - const Standard_Integer theDirFace2V, - const Standard_Integer theNbTimesV); + const Standard_Integer theDirFace1U, + const Standard_Integer theDirFace2U, + const Standard_Integer theNbTimesU, + const Standard_Integer theDirFace1V, + const Standard_Integer theDirFace2V, + const Standard_Integer theNbTimesV); // Build groups for Propagation of 1D hypotheses Standard_EXPORT Handle(TColStd_HSequenceOfTransient) Propagate (Handle(GEOM_Object) theShape); diff --git a/src/GEOMImpl/GEOMImpl_IHealing.hxx b/src/GEOMImpl/GEOMImpl_IHealing.hxx index 07252ac76..5a9d26455 100755 --- a/src/GEOMImpl/GEOMImpl_IHealing.hxx +++ b/src/GEOMImpl/GEOMImpl_IHealing.hxx @@ -19,9 +19,8 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// NOTE: This is an intreface to a function for the Healing creation. -//NOTE: This is an intreface to a function for the Healing creation. -// #include "GEOM_Function.hxx" #include @@ -76,7 +75,7 @@ public: void SetIndex( Standard_Integer val ) { _func->SetInteger(ARG_SUBSHAPE_INDEX, val); } Standard_Integer GetIndex() { return _func->GetInteger(ARG_SUBSHAPE_INDEX); } - + private: - Handle(GEOM_Function) _func; + Handle(GEOM_Function) _func; }; diff --git a/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx b/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx index d78c82d4e..e19acd19a 100644 --- a/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx +++ b/src/GEOMImpl/GEOMImpl_IHealingOperations.cxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifdef WNT #pragma warning( disable:4786 ) @@ -864,7 +863,6 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientation (Handle(GEOM_ return theObject; } - //============================================================================= /*! * ChangeOrientationCopy @@ -921,3 +919,62 @@ Handle(GEOM_Object) GEOMImpl_IHealingOperations::ChangeOrientationCopy (Handle(G SetErrorCode(OK); return aNewObject; } + +//============================================================================= +/*! + * LimitTolerance + */ +//============================================================================= +Handle(GEOM_Object) GEOMImpl_IHealingOperations::LimitTolerance (Handle(GEOM_Object) theObject, + double theTolerance) +{ + // Set error code, check parameters + SetErrorCode(KO); + + if (theObject.IsNull()) + return NULL; + + Handle(GEOM_Function) aFunction, aLastFunction = theObject->GetLastFunction(); + if (aLastFunction.IsNull()) + return NULL; // There is no function which creates an object to be processed + + // Add a new object + Handle(GEOM_Object) aNewObject = GetEngine()->AddObject(GetDocID(), theObject->GetType()); + + // Add the function + aFunction = aNewObject->AddFunction(GEOMImpl_HealingDriver::GetID(), LIMIT_TOLERANCE); + + if (aFunction.IsNull()) + return NULL; + + // Check if the function is set correctly + if (aFunction->GetDriverGUID() != GEOMImpl_HealingDriver::GetID()) return NULL; + + // Prepare "data container" class IHealing + GEOMImpl_IHealing HI (aFunction); + HI.SetOriginal(aLastFunction); + HI.SetTolerance(theTolerance); + + // Compute + try { +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) > 0x060100 + OCC_CATCH_SIGNALS; +#endif + if (!GetSolver()->ComputeFunction(aFunction)) { + SetErrorCode("Healing driver failed"); + return NULL; + } + } + catch (Standard_Failure) { + Handle(Standard_Failure) aFail = Standard_Failure::Caught(); + SetErrorCode(aFail->GetMessageString()); + return NULL; + } + + // Make a Python command + GEOM::TPythonDump(aFunction) << aNewObject << " = geompy.LimitTolerance(" + << theObject << ", " << theTolerance << ")"; + + SetErrorCode(OK); + return aNewObject; +} diff --git a/src/GEOMImpl/GEOMImpl_IHealingOperations.hxx b/src/GEOMImpl/GEOMImpl_IHealingOperations.hxx index aafa9687d..064194fdd 100644 --- a/src/GEOMImpl/GEOMImpl_IHealingOperations.hxx +++ b/src/GEOMImpl/GEOMImpl_IHealingOperations.hxx @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #ifndef _GEOMImpl_IHealingOperations_HXX_ #define _GEOMImpl_IHealingOperations_HXX_ @@ -39,9 +38,9 @@ class GEOMImpl_IHealingOperations : public GEOM_IOperations { // Apply Shape Processing to the selected Object Standard_EXPORT Handle(GEOM_Object) ShapeProcess( Handle(GEOM_Object) theObject, - const Handle(TColStd_HArray1OfExtendedString)& theOperations, - const Handle(TColStd_HArray1OfExtendedString)& theParams, - const Handle(TColStd_HArray1OfExtendedString)& theValues ); + const Handle(TColStd_HArray1OfExtendedString)& theOperations, + const Handle(TColStd_HArray1OfExtendedString)& theParams, + const Handle(TColStd_HArray1OfExtendedString)& theValues ); // Retrieve default Shape Process parameters (from resource file) Standard_EXPORT void GetShapeProcessParameters( std::list& theOperations, @@ -49,12 +48,13 @@ class GEOMImpl_IHealingOperations : public GEOM_IOperations { std::list& theValues ); // Retrieve default Shape Process parameters for given operator - Standard_EXPORT bool GetOperatorParameters( const std::string theOperation, + Standard_EXPORT bool GetOperatorParameters( const std::string theOperation, std::list& theParams, std::list& theValues ); // returns all parameters that are valid for the given operation (Shape Process operator) - Standard_EXPORT static bool GetParameters( const std::string theOperation, std::list& theParams ); + Standard_EXPORT static bool GetParameters( const std::string theOperation, + std::list& theParams ); Standard_EXPORT Handle(GEOM_Object) SuppressFaces( Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theFaces); @@ -68,25 +68,28 @@ class GEOMImpl_IHealingOperations : public GEOM_IOperations { Standard_EXPORT Handle(GEOM_Object) FillHoles( Handle(GEOM_Object) theObject, const Handle(TColStd_HArray1OfInteger)& theWires); - + Standard_EXPORT Handle(GEOM_Object) Sew( Handle(GEOM_Object) theObject, double theTolerance ); Standard_EXPORT Handle(GEOM_Object) DivideEdge( Handle(GEOM_Object) theObject, - int theIndex, - double theValue, - bool isByParameter ); + int theIndex, + double theValue, + bool isByParameter ); // this function does not use Function-Driver mechanism, it just computes the free // boundary edges and returns them in the sequence. It is called just for information reasons // and it's not intended for history/undo/redo/etc.. - Standard_EXPORT bool GetFreeBoundary ( Handle(GEOM_Object) theObject, - Handle(TColStd_HSequenceOfTransient)& theOutClosedWires, + Standard_EXPORT bool GetFreeBoundary ( Handle(GEOM_Object) theObject, + Handle(TColStd_HSequenceOfTransient)& theOutClosedWires, Handle(TColStd_HSequenceOfTransient)& theOutOpenWires ); Standard_EXPORT Handle(GEOM_Object) ChangeOrientation( Handle(GEOM_Object) theObject); Standard_EXPORT Handle(GEOM_Object) ChangeOrientationCopy( Handle(GEOM_Object) theObject); + Standard_EXPORT Handle(GEOM_Object) LimitTolerance( Handle(GEOM_Object) theObject, + double theTolerance ); + }; #endif diff --git a/src/GEOMImpl/GEOMImpl_Types.hxx b/src/GEOMImpl/GEOMImpl_Types.hxx index b1d626427..d1dcbe274 100755 --- a/src/GEOMImpl/GEOMImpl_Types.hxx +++ b/src/GEOMImpl/GEOMImpl_Types.hxx @@ -269,6 +269,7 @@ #define SEWING 6 #define DIVIDE_EDGE 7 #define CHANGE_ORIENTATION 8 +#define LIMIT_TOLERANCE 9 #define BASIC_FILLING 1 diff --git a/src/GEOM_I/GEOM_IBlocksOperations_i.cc b/src/GEOM_I/GEOM_IBlocksOperations_i.cc index d5435c5d1..f765856d0 100644 --- a/src/GEOM_I/GEOM_IBlocksOperations_i.cc +++ b/src/GEOM_I/GEOM_IBlocksOperations_i.cc @@ -269,6 +269,34 @@ GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetPoint (GEOM::GEOM_Object_ptr return GetObject(anObject); } +//============================================================================= +/*! + * GetVertexNearPoint + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetVertexNearPoint + (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_Object_ptr thePoint) +{ + GEOM::GEOM_Object_var aGEOMObject; + + // Set a not done flag + GetOperations()->SetNotDone(); + + // Get the reference Objects + Handle(GEOM_Object) aShape = GetObjectImpl(theShape); + Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint); + if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn(); + + // Create the Point + Handle(GEOM_Object) anObject = + GetOperations()->GetVertexNearPoint(aShape, aPoint); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + //============================================================================= /*! * GetEdge @@ -481,6 +509,37 @@ GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetFaceByNormale (GEOM::GEOM_Obj return GetObject(anObject); } +//============================================================================= +/*! + * GetShapesNearPoint + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_IBlocksOperations_i::GetShapesNearPoint + (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Long theShapeType, + CORBA::Double theTolerance) +{ + GEOM::GEOM_Object_var aGEOMObject; + + // Set a not done flag + GetOperations()->SetNotDone(); + + // Get the reference Objects + Handle(GEOM_Object) aShape = GetObjectImpl(theShape); + Handle(GEOM_Object) aPoint = GetObjectImpl(thePoint); + + if (aShape.IsNull() || aPoint.IsNull()) return aGEOMObject._retn(); + + // Create the Shape + Handle(GEOM_Object) anObject = + GetOperations()->GetShapesNearPoint(aShape, aPoint, theShapeType, theTolerance); + if (!GetOperations()->IsDone() || anObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(anObject); +} + //============================================================================= /*! * ExplodeCompoundOfBlocks diff --git a/src/GEOM_I/GEOM_IBlocksOperations_i.hh b/src/GEOM_I/GEOM_IBlocksOperations_i.hh index 68904892c..8fa1e1de7 100644 --- a/src/GEOM_I/GEOM_IBlocksOperations_i.hh +++ b/src/GEOM_I/GEOM_IBlocksOperations_i.hh @@ -75,6 +75,9 @@ class GEOM_I_EXPORT GEOM_IBlocksOperations_i : CORBA::Double theZ, CORBA::Double theEpsilon); + GEOM::GEOM_Object_ptr GetVertexNearPoint (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_Object_ptr thePoint); + GEOM::GEOM_Object_ptr GetEdge (GEOM::GEOM_Object_ptr theShape, GEOM::GEOM_Object_ptr thePoint1, GEOM::GEOM_Object_ptr thePoint2); @@ -101,10 +104,15 @@ class GEOM_I_EXPORT GEOM_IBlocksOperations_i : GEOM::GEOM_Object_ptr GetFaceByNormale (GEOM::GEOM_Object_ptr theBlock, GEOM::GEOM_Object_ptr theVector); + GEOM::GEOM_Object_ptr GetShapesNearPoint (GEOM::GEOM_Object_ptr theShape, + GEOM::GEOM_Object_ptr thePoint, + CORBA::Long theShapeType, + CORBA::Double theTolerance); + // Check blocks compound CORBA::Boolean IsCompoundOfBlocks (GEOM::GEOM_Object_ptr theCompound, - CORBA::Long theMinNbFaces, - CORBA::Long theMaxNbFaces, + CORBA::Long theMinNbFaces, + CORBA::Long theMaxNbFaces, CORBA::Long& theNbBlocks); CORBA::Boolean CheckCompoundOfBlocks (GEOM::GEOM_Object_ptr theCompound, diff --git a/src/GEOM_I/GEOM_IHealingOperations_i.cc b/src/GEOM_I/GEOM_IHealingOperations_i.cc index 81dac09c3..39df78fe1 100644 --- a/src/GEOM_I/GEOM_IHealingOperations_i.cc +++ b/src/GEOM_I/GEOM_IHealingOperations_i.cc @@ -18,7 +18,6 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// #include @@ -493,3 +492,30 @@ GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::ChangeOrientationCopy (GEOM::GE return GetObject(aNewObject); } + +//============================================================================= +/*! + * LimitTolerance + */ +//============================================================================= +GEOM::GEOM_Object_ptr GEOM_IHealingOperations_i::LimitTolerance (GEOM::GEOM_Object_ptr theObject, + CORBA::Double theTolerance) +{ + GEOM::GEOM_Object_var aGEOMObject; + + // Set a not done flag + GetOperations()->SetNotDone(); + + // Get the object itself + Handle(GEOM_Object) anObject = GetObjectImpl(theObject); + if (anObject.IsNull()) + return aGEOMObject._retn(); + + // Perform + Handle(GEOM_Object) aNewObject = + GetOperations()->LimitTolerance(anObject, theTolerance); + if (!GetOperations()->IsDone() || aNewObject.IsNull()) + return aGEOMObject._retn(); + + return GetObject(aNewObject); +} diff --git a/src/GEOM_I/GEOM_IHealingOperations_i.hh b/src/GEOM_I/GEOM_IHealingOperations_i.hh index be42fbd55..01b3f48fc 100644 --- a/src/GEOM_I/GEOM_IHealingOperations_i.hh +++ b/src/GEOM_I/GEOM_IHealingOperations_i.hh @@ -18,7 +18,7 @@ // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com -// + #ifndef _GEOM_IHealingOperations_i_HeaderFile #define _GEOM_IHealingOperations_i_HeaderFile @@ -36,42 +36,65 @@ #include #include -class GEOM_I_EXPORT GEOM_IHealingOperations_i : +class GEOM_I_EXPORT GEOM_IHealingOperations_i : public virtual POA_GEOM::GEOM_IHealingOperations, public virtual GEOM_IOperations_i { public: - GEOM_IHealingOperations_i(PortableServer::POA_ptr thePOA, GEOM::GEOM_Gen_ptr theEngine, ::GEOMImpl_IHealingOperations* theImpl); + GEOM_IHealingOperations_i(PortableServer::POA_ptr thePOA, + GEOM::GEOM_Gen_ptr theEngine, + ::GEOMImpl_IHealingOperations* theImpl); ~GEOM_IHealingOperations_i(); - - GEOM::GEOM_Object_ptr ProcessShape(GEOM::GEOM_Object_ptr theObject, const GEOM::string_array& theOperations, const GEOM::string_array& theParams, const GEOM::string_array& theValues); - void GetShapeProcessParameters(GEOM::string_array_out theOperations, GEOM::string_array_out theParams, GEOM::string_array_out theValues); + GEOM::GEOM_Object_ptr ProcessShape(GEOM::GEOM_Object_ptr theObject, + const GEOM::string_array& theOperations, + const GEOM::string_array& theParams, + const GEOM::string_array& theValues); - void GetOperatorParameters (const char* theOperator, GEOM::string_array_out theParams, GEOM::string_array_out theValues); + void GetShapeProcessParameters(GEOM::string_array_out theOperations, + GEOM::string_array_out theParams, + GEOM::string_array_out theValues); - GEOM::GEOM_Object_ptr SuppressFaces(GEOM::GEOM_Object_ptr theObject, const GEOM::short_array& theFaces); + void GetOperatorParameters (const char* theOperator, + GEOM::string_array_out theParams, + GEOM::string_array_out theValues); - GEOM::GEOM_Object_ptr CloseContour (GEOM::GEOM_Object_ptr theObject, const GEOM::short_array& theWires, CORBA::Boolean isCommonVertex); + GEOM::GEOM_Object_ptr SuppressFaces(GEOM::GEOM_Object_ptr theObject, + const GEOM::short_array& theFaces); - GEOM::GEOM_Object_ptr RemoveIntWires (GEOM::GEOM_Object_ptr theObject, const GEOM::short_array& theWires); - - GEOM::GEOM_Object_ptr FillHoles (GEOM::GEOM_Object_ptr theObject, const GEOM::short_array& theWires); + GEOM::GEOM_Object_ptr CloseContour (GEOM::GEOM_Object_ptr theObject, + const GEOM::short_array& theWires, + CORBA::Boolean isCommonVertex); - GEOM::GEOM_Object_ptr Sew (GEOM::GEOM_Object_ptr theObject, CORBA::Double theTolerance); + GEOM::GEOM_Object_ptr RemoveIntWires (GEOM::GEOM_Object_ptr theObject, + const GEOM::short_array& theWires); - GEOM::GEOM_Object_ptr DivideEdge (GEOM::GEOM_Object_ptr theObject, CORBA::Short theIndex, CORBA::Double theValue, CORBA::Boolean isByParameter); + GEOM::GEOM_Object_ptr FillHoles (GEOM::GEOM_Object_ptr theObject, + const GEOM::short_array& theWires); + + GEOM::GEOM_Object_ptr Sew (GEOM::GEOM_Object_ptr theObject, + CORBA::Double theTolerance); + + GEOM::GEOM_Object_ptr DivideEdge (GEOM::GEOM_Object_ptr theObject, + CORBA::Short theIndex, + CORBA::Double theValue, + CORBA::Boolean isByParameter); + + CORBA::Boolean GetFreeBoundary(GEOM::GEOM_Object_ptr theObject, + GEOM::ListOfGO_out theClosedWires, + GEOM::ListOfGO_out theOpenWires ); - CORBA::Boolean GetFreeBoundary(GEOM::GEOM_Object_ptr theObject, GEOM::ListOfGO_out theClosedWires, GEOM::ListOfGO_out theOpenWires ); - GEOM::GEOM_Object_ptr ChangeOrientation (GEOM::GEOM_Object_ptr theObject); GEOM::GEOM_Object_ptr ChangeOrientationCopy (GEOM::GEOM_Object_ptr theObject); + GEOM::GEOM_Object_ptr LimitTolerance (GEOM::GEOM_Object_ptr theObject, + CORBA::Double theTolerance); + ::GEOMImpl_IHealingOperations* GetOperations() { return (::GEOMImpl_IHealingOperations*)GetImpl(); } private: - Handle(TColStd_HArray1OfExtendedString) Convert( const GEOM::string_array& ); - Handle(TColStd_HArray1OfInteger) Convert( const GEOM::short_array& ); + Handle(TColStd_HArray1OfExtendedString) Convert( const GEOM::string_array& ); + Handle(TColStd_HArray1OfInteger) Convert( const GEOM::short_array& ); }; diff --git a/src/GEOM_SWIG/GEOM_TestOthers.py b/src/GEOM_SWIG/GEOM_TestOthers.py index ca37dd30b..a1607cd43 100644 --- a/src/GEOM_SWIG/GEOM_TestOthers.py +++ b/src/GEOM_SWIG/GEOM_TestOthers.py @@ -500,6 +500,17 @@ def TestOtherOperations (geompy, math): geompy.addToStudyInFather(blocksComp, pb0_top_1, "point from blocksComp (-50, 50, 50)") geompy.addToStudyInFather(blocksComp, pb0_bot_1, "point from blocksComp (-50, -50, -50)") + # GetVertexNearPoint(theShape, thePoint) + pb0_top_2_near = geompy.MakeVertex(40, 40, 40) + pb0_top_2 = geompy.GetVertexNearPoint(blocksComp, pb0_top_2_near) + + geompy.addToStudyInFather(blocksComp, pb0_top_2, "point from blocksComp near (40, 40, 40)") + + # GetEdge(theShape, thePoint1, thePoint2) + edge_top_y50 = geompy.GetEdge(blocksComp, pb0_top_1, pb0_top_2) + + geompy.addToStudyInFather(blocksComp, edge_top_y50, "edge from blocksComp by two points") + # GetEdgeNearPoint(theShape, thePoint) pmidle = geompy.MakeVertex(50, 0, 50) edge1 = geompy.GetEdgeNearPoint(blocksComp, pmidle) @@ -511,6 +522,11 @@ def TestOtherOperations (geompy, math): geompy.addToStudyInFather(blocksComp, b0_image, "b0 image") + # GetShapesNearPoint(theShape, thePoint, theShapeType, theTolerance) + b0_faces_plus = geompy.GetShapesNearPoint(blocksComp, pb0_top_2_near, geompy.ShapeType["FACE"], 0.01) + + geompy.addToStudyInFather(blocksComp, b0_faces_plus, "faces near point (40, 40, 40)") + # GetShapesOnPlane faces_on_pln = geompy.GetShapesOnPlane(blocksComp, geompy.ShapeType["FACE"], v_0pp, geompy.GEOM.ST_ONIN) diff --git a/src/GEOM_SWIG/geompyDC.py b/src/GEOM_SWIG/geompyDC.py index 67657dce1..0f570563f 100644 --- a/src/GEOM_SWIG/geompyDC.py +++ b/src/GEOM_SWIG/geompyDC.py @@ -448,7 +448,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing the created point. # # @ref tui_creation_point "Example" - def MakeVertex(self,theX, theY, theZ): + def MakeVertex(self, theX, theY, theZ): # Example: see GEOM_TestAll.py theX,theY,theZ,Parameters = ParseParameters(theX, theY, theZ) anObj = self.BasicOp.MakePointXYZ(theX, theY, theZ) @@ -2266,11 +2266,22 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing processed shape. # # @ref swig_todo "Example" - def ChangeOrientationShellCopy(self,theObject): + def ChangeOrientationShellCopy(self, theObject): anObj = self.HealOp.ChangeOrientationCopy(theObject) RaiseIfFailed("ChangeOrientationCopy", self.HealOp) return anObj + ## Try to limit tolerance of the given object by value \a theTolerance. + # @param theObject Shape to be processed. + # @param theTolerance Required tolerance value. + # @return New GEOM_Object, containing processed shape. + # + # @ref tui_limit_tolerance "Example" + def LimitTolerance(self, theObject, theTolerance = 1e-07): + anObj = self.HealOp.LimitTolerance(theObject, theTolerance) + RaiseIfFailed("LimitTolerance", self.HealOp) + return anObj + ## Get a list of wires (wrapped in GEOM_Object-s), # that constitute a free boundary of the given shape. # @param theObject Shape to get free boundary of. @@ -2280,7 +2291,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): # theOpenWires: Open wires on the free boundary of the given shape. # # @ref tui_measurement_tools_page "Example" - def GetFreeBoundary(self,theObject): + def GetFreeBoundary(self, theObject): # Example: see GEOM_TestHealing.py anObj = self.HealOp.GetFreeBoundary(theObject) RaiseIfFailed("GetFreeBoundary", self.HealOp) @@ -3620,19 +3631,31 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing the found vertex. # # @ref swig_GetPoint "Example" - def GetPoint(self,theShape, theX, theY, theZ, theEpsilon): + def GetPoint(self, theShape, theX, theY, theZ, theEpsilon): # Example: see GEOM_TestOthers.py anObj = self.BlocksOp.GetPoint(theShape, theX, theY, theZ, theEpsilon) RaiseIfFailed("GetPoint", self.BlocksOp) return anObj + ## Find a vertex of the given shape, which has minimal distance to the given point. + # @param theShape Any shape. + # @param thePoint Point, close to the desired vertex. + # @return New GEOM_Object, containing the found vertex. + # + # @ref swig_GetVertexNearPoint "Example" + def GetVertexNearPoint(self, theShape, thePoint): + # Example: see GEOM_TestOthers.py + anObj = self.BlocksOp.GetVertexNearPoint(theShape, thePoint) + RaiseIfFailed("GetVertexNearPoint", self.BlocksOp) + return anObj + ## Get an edge, found in the given shape by two given vertices. # @param theShape Block or a compound of blocks. # @param thePoint1,thePoint2 Points, close to the ends of the desired edge. # @return New GEOM_Object, containing the found edge. # - # @ref swig_todo "Example" - def GetEdge(self,theShape, thePoint1, thePoint2): + # @ref swig_GetEdge "Example" + def GetEdge(self, theShape, thePoint1, thePoint2): # Example: see GEOM_Spanner.py anObj = self.BlocksOp.GetEdge(theShape, thePoint1, thePoint2) RaiseIfFailed("GetEdge", self.BlocksOp) @@ -3644,7 +3667,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing the found edge. # # @ref swig_GetEdgeNearPoint "Example" - def GetEdgeNearPoint(self,theShape, thePoint): + def GetEdgeNearPoint(self, theShape, thePoint): # Example: see GEOM_TestOthers.py anObj = self.BlocksOp.GetEdgeNearPoint(theShape, thePoint) RaiseIfFailed("GetEdgeNearPoint", self.BlocksOp) @@ -3692,7 +3715,7 @@ class geompyDC(GEOM._objref_GEOM_Gen): # @return New GEOM_Object, containing the found face. # # @ref swig_GetFaceNearPoint "Example" - def GetFaceNearPoint(self,theShape, thePoint): + def GetFaceNearPoint(self, theShape, thePoint): # Example: see GEOM_Spanner.py anObj = self.BlocksOp.GetFaceNearPoint(theShape, thePoint) RaiseIfFailed("GetFaceNearPoint", self.BlocksOp) @@ -3710,6 +3733,23 @@ class geompyDC(GEOM._objref_GEOM_Gen): RaiseIfFailed("GetFaceByNormale", self.BlocksOp) return anObj + ## Find all subshapes of type \a theShapeType of the given shape, + # which have minimal distance to the given point. + # @param theShape Any shape. + # @param thePoint Point, close to the desired shape. + # @param theShapeType Defines what kind of subshapes is searched. + # @param theTolerance The tolerance for distances comparison. All shapes + # with distances to the given point in interval + # [minimal_distance, minimal_distance + theTolerance] will be gathered. + # @return New GEOM_Object, containing a group of all found shapes. + # + # @ref swig_GetShapesNearPoint "Example" + def GetShapesNearPoint(self, theShape, thePoint, theShapeType, theTolerance = 1e-07): + # Example: see GEOM_TestOthers.py + anObj = self.BlocksOp.GetShapesNearPoint(theShape, thePoint, theShapeType, theTolerance) + RaiseIfFailed("GetShapesNearPoint", self.BlocksOp) + return anObj + # end of l3_blocks_op ## @} diff --git a/src/RepairGUI/Makefile.am b/src/RepairGUI/Makefile.am index c59c15056..7f8a4fcbe 100644 --- a/src/RepairGUI/Makefile.am +++ b/src/RepairGUI/Makefile.am @@ -38,6 +38,7 @@ salomeinclude_HEADERS = \ RepairGUI_FreeFacesDlg.h \ RepairGUI_ChangeOrientationDlg.h \ RepairGUI_GlueDlg.h \ + RepairGUI_LimitToleranceDlg.h \ RepairGUI_RemoveExtraEdgesDlg.h # Libraries targets @@ -56,6 +57,7 @@ dist_libRepairGUI_la_SOURCES = \ RepairGUI_FreeFacesDlg.h \ RepairGUI_ChangeOrientationDlg.h \ RepairGUI_GlueDlg.h \ + RepairGUI_LimitToleranceDlg.h \ RepairGUI_RemoveExtraEdgesDlg.h \ \ RepairGUI.cxx \ @@ -70,6 +72,7 @@ dist_libRepairGUI_la_SOURCES = \ RepairGUI_FreeFacesDlg.cxx \ RepairGUI_ChangeOrientationDlg.cxx \ RepairGUI_GlueDlg.cxx \ + RepairGUI_LimitToleranceDlg.cxx \ RepairGUI_RemoveExtraEdgesDlg.cxx MOC_FILES = \ @@ -84,6 +87,7 @@ MOC_FILES = \ RepairGUI_FreeFacesDlg_moc.cxx \ RepairGUI_ChangeOrientationDlg_moc.cxx \ RepairGUI_GlueDlg_moc.cxx \ + RepairGUI_LimitToleranceDlg_moc.cxx \ RepairGUI_RemoveExtraEdgesDlg_moc.cxx nodist_libRepairGUI_la_SOURCES = \ diff --git a/src/RepairGUI/RepairGUI.cxx b/src/RepairGUI/RepairGUI.cxx index 652cdb63a..ebfc75fb4 100644 --- a/src/RepairGUI/RepairGUI.cxx +++ b/src/RepairGUI/RepairGUI.cxx @@ -19,11 +19,10 @@ // // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // +// GEOM GEOMGUI : GUI for Geometry component +// File : RepairGUI.cxx +// Author : Damien COQUERET, Open CASCADE S.A.S. -// GEOM GEOMGUI : GUI for Geometry component -// File : RepairGUI.cxx -// Author : Damien COQUERET, Open CASCADE S.A.S. -// #include "RepairGUI.h" #include @@ -43,8 +42,9 @@ #include "RepairGUI_FreeBoundDlg.h" // Method FREE BOUNDARIES #include "RepairGUI_FreeFacesDlg.h" // Method FREE FACES #include "RepairGUI_GlueDlg.h" // Method GLUE FACES +#include "RepairGUI_LimitToleranceDlg.h" // Method LIMIT TOLERANCE #include "RepairGUI_ChangeOrientationDlg.h" // Method CHANGE ORIENTATION -#include "RepairGUI_RemoveExtraEdgesDlg.h" // Method REMOVE EXTRA EDGES +#include "RepairGUI_RemoveExtraEdgesDlg.h" // Method REMOVE EXTRA EDGES //======================================================================= // function : RepairGUI() @@ -66,7 +66,7 @@ RepairGUI::~RepairGUI() //======================================================================= // function : OnGUIEvent() -// purpose : +// purpose : //======================================================================= bool RepairGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) { @@ -77,18 +77,19 @@ bool RepairGUI::OnGUIEvent( int theCommandID, SUIT_Desktop* parent ) QDialog* aDlg = NULL; switch ( theCommandID ) { - case GEOMOp::OpSewing: aDlg = new RepairGUI_SewingDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpGlueFaces: aDlg = new RepairGUI_GlueDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpSuppressFaces: aDlg = new RepairGUI_SuppressFacesDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpSuppressHoles: aDlg = new RepairGUI_RemoveHolesDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpShapeProcess: aDlg = new RepairGUI_ShapeProcessDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpCloseContour: aDlg = new RepairGUI_CloseContourDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpRemoveIntWires: aDlg = new RepairGUI_RemoveIntWiresDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpAddPointOnEdge: aDlg = new RepairGUI_DivideEdgeDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpFreeBoundaries: aDlg = new RepairGUI_FreeBoundDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpFreeFaces: aDlg = new RepairGUI_FreeFacesDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpOrientation: aDlg = new RepairGUI_ChangeOrientationDlg ( getGeometryGUI(), parent ); break; - case GEOMOp::OpRemoveExtraEdges: aDlg = new RepairGUI_RemoveExtraEdgesDlg ( getGeometryGUI(), parent ); break; + case GEOMOp::OpSewing: aDlg = new RepairGUI_SewingDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpGlueFaces: aDlg = new RepairGUI_GlueDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpLimitTolerance: aDlg = new RepairGUI_LimitToleranceDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpSuppressFaces: aDlg = new RepairGUI_SuppressFacesDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpSuppressHoles: aDlg = new RepairGUI_RemoveHolesDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpShapeProcess: aDlg = new RepairGUI_ShapeProcessDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpCloseContour: aDlg = new RepairGUI_CloseContourDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpRemoveIntWires: aDlg = new RepairGUI_RemoveIntWiresDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpAddPointOnEdge: aDlg = new RepairGUI_DivideEdgeDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpFreeBoundaries: aDlg = new RepairGUI_FreeBoundDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpFreeFaces: aDlg = new RepairGUI_FreeFacesDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpOrientation: aDlg = new RepairGUI_ChangeOrientationDlg (getGeometryGUI(), parent); break; + case GEOMOp::OpRemoveExtraEdges: aDlg = new RepairGUI_RemoveExtraEdgesDlg (getGeometryGUI(), parent); break; default: app->putInfo( tr( "GEOM_PRP_COMMAND" ).arg( theCommandID ) ); break; diff --git a/src/RepairGUI/RepairGUI_LimitToleranceDlg.cxx b/src/RepairGUI/RepairGUI_LimitToleranceDlg.cxx new file mode 100644 index 000000000..19cfe7a02 --- /dev/null +++ b/src/RepairGUI/RepairGUI_LimitToleranceDlg.cxx @@ -0,0 +1,441 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// GEOM RepairGUI : GUI for Geometry component +// File : RepairGUI_LimitToleranceDlg.cxx + +#include "RepairGUI_LimitToleranceDlg.h" + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include + +#define DEFAULT_TOLERANCE_VALUE 1e-07 + +//================================================================================= +// class : RepairGUI_LimitToleranceDlg() +// purpose : Constructs a RepairGUI_LimitToleranceDlg which is a child of 'parent', with the +// name 'name' and widget flags set to 'f'. +// The dialog will by default be modeless, unless you set 'modal' to +// TRUE to construct a modal dialog. +//================================================================================= +RepairGUI_LimitToleranceDlg::RepairGUI_LimitToleranceDlg(GeometryGUI* theGeometryGUI, + QWidget* parent, bool modal) + : GEOMBase_Skeleton(theGeometryGUI, parent, modal) +{ + QPixmap image0 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_DLG_LIMIT_TOLERANCE"))); + QPixmap image1 (SUIT_Session::session()->resourceMgr()->loadPixmap("GEOM", tr("ICON_SELECT"))); + + setWindowTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE")); + + /***************************************************************/ + mainFrame()->GroupConstructors->setTitle(tr("GEOM_LIMIT_TOLERANCE_TITLE")); + mainFrame()->RadioButton1->setIcon(image0); + mainFrame()->RadioButton2->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton3->setAttribute(Qt::WA_DeleteOnClose); + mainFrame()->RadioButton2->close(); + mainFrame()->RadioButton3->close(); + + GroupPoints = new DlgRef_1SelExt(centralWidget()); + GroupPoints->GroupBox1->setTitle(tr("GEOM_ARGUMENTS")); + GroupPoints->TextLabel1->setText(tr("GEOM_SELECTED_SHAPE")); + GroupPoints->PushButton1->setIcon(image1); + GroupPoints->LineEdit1->setReadOnly(true); + + QLabel* aTolLab = new QLabel(tr("GEOM_TOLERANCE"), GroupPoints->Box); + myTolEdt = new SalomeApp_DoubleSpinBox(GroupPoints->Box); + initSpinBox(myTolEdt, 0., 100., DEFAULT_TOLERANCE_VALUE, "len_tol_precision"); + myTolEdt->setValue(DEFAULT_TOLERANCE_VALUE); + + QGridLayout* boxLayout = new QGridLayout(GroupPoints->Box); + boxLayout->setMargin(0); boxLayout->setSpacing(6); + boxLayout->addWidget(aTolLab, 0, 0); + boxLayout->addWidget(myTolEdt, 0, 2); + + QVBoxLayout* layout = new QVBoxLayout(centralWidget()); + layout->setMargin(0); layout->setSpacing(6); + layout->addWidget(GroupPoints); + + setHelpFileName("limit_tolerance_operation_page.html"); + + Init(); +} + + +//================================================================================= +// function : ~RepairGUI_LimitToleranceDlg() +// purpose : Destroys the object and frees any allocated resources +//================================================================================= +RepairGUI_LimitToleranceDlg::~RepairGUI_LimitToleranceDlg() +{ +} + + +//================================================================================= +// function : Init() +// purpose : +//================================================================================= +void RepairGUI_LimitToleranceDlg::Init() +{ + /* init variables */ + myEditCurrentArgument = GroupPoints->LineEdit1; + + myObject = GEOM::GEOM_Object::_nil(); + + //myGeomGUI->SetState(0); + //globalSelection(GEOM_COMPOUND); + + mainFrame()->GroupBoxPublish->show(); + + /* signals and slots connections */ + connect(buttonOk(), SIGNAL(clicked()), this, SLOT(ClickOnOk())); + connect(buttonApply(), SIGNAL(clicked()), this, SLOT(ClickOnApply())); + + connect(GroupPoints->PushButton1, SIGNAL(clicked()), this, SLOT(SetEditCurrentArgument())); + connect(GroupPoints->LineEdit1, SIGNAL(returnPressed()), this, SLOT(LineEditReturnPressed())); + + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + initName(tr("LIMIT_TOLERANCE_NEW_OBJ_NAME")); + + ConstructorsClicked(0); + + activateSelection(); + updateButtonState(); +} + + +//================================================================================= +// function : ConstructorsClicked() +// purpose : Radio button management +//================================================================================= +void RepairGUI_LimitToleranceDlg::ConstructorsClicked(int constructorId) +{ + disconnect(myGeomGUI->getApp()->selectionMgr(), 0, this, 0); + + GroupPoints->show(); + GroupPoints->LineEdit1->setText(""); + myEditCurrentArgument = GroupPoints->LineEdit1; + myEditCurrentArgument->setFocus(); + + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + qApp->processEvents(); + updateGeometry(); + resize(minimumSizeHint()); + + updateButtonState(); + activateSelection(); + SelectionIntoArgument(); +} + + +//================================================================================= +// function : ClickOnOk() +// purpose : Same than click on apply but close this dialog. +//================================================================================= +void RepairGUI_LimitToleranceDlg::ClickOnOk() +{ + if (ClickOnApply()) + ClickOnCancel(); +} + +//================================================================================= +// function : ClickOnApply() +// purpose : +//================================================================================= +bool RepairGUI_LimitToleranceDlg::ClickOnApply() +{ + if (!onAcceptLocal()) + return false; + + initName(); + + ConstructorsClicked(0); + + return true; +} + +//================================================================================= +// function : SelectionIntoArgument() +// purpose : Called when selection +//================================================================================= +void RepairGUI_LimitToleranceDlg::SelectionIntoArgument() +{ + myEditCurrentArgument->setText(""); + myObject = GEOM::GEOM_Object::_nil(); + + LightApp_SelectionMgr* aSelMgr = myGeomGUI->getApp()->selectionMgr(); + SALOME_ListIO aSelList; + aSelMgr->selectedObjects(aSelList); + + if (aSelList.Extent() == 1) { + Handle(SALOME_InteractiveObject) anIO = aSelList.First(); + Standard_Boolean aRes; + myObject = GEOMBase::ConvertIOinGEOMObject(anIO, aRes); + if (aRes) + myEditCurrentArgument->setText(GEOMBase::GetName(myObject)); + } + updateButtonState(); +} + +//================================================================================= +// function : SetEditCurrentArgument() +// purpose : +//================================================================================= +void RepairGUI_LimitToleranceDlg::SetEditCurrentArgument() +{ + const QObject* send = sender(); + if (send == GroupPoints->PushButton1) { + myEditCurrentArgument->setFocus(); + SelectionIntoArgument(); + } +} + +//================================================================================= +// function : LineEditReturnPressed() +// purpose : +//================================================================================= +void RepairGUI_LimitToleranceDlg::LineEditReturnPressed() +{ + const QObject* send = sender(); + if (send == GroupPoints->LineEdit1) { + myEditCurrentArgument = GroupPoints->LineEdit1; + GEOMBase_Skeleton::LineEditReturnPressed(); + } +} + +//================================================================================= +// function : ActivateThisDialog() +// purpose : +//================================================================================= +void RepairGUI_LimitToleranceDlg::ActivateThisDialog() +{ + GEOMBase_Skeleton::ActivateThisDialog(); + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + activateSelection(); +} + +//================================================================================= +// function : enterEvent() +// purpose : Mouse enter onto the dialog to activate it +//================================================================================= +void RepairGUI_LimitToleranceDlg::enterEvent(QEvent*) +{ + if (!mainFrame()->GroupConstructors->isEnabled()) + ActivateThisDialog(); +} + +//================================================================================= +// function : createOperation +// purpose : +//================================================================================= +GEOM::GEOM_IOperations_ptr RepairGUI_LimitToleranceDlg::createOperation() +{ + return getGeomEngine()->GetIHealingOperations(getStudyId()); +} + +//================================================================================= +// function : isValid +// purpose : +//================================================================================= +bool RepairGUI_LimitToleranceDlg::isValid(QString& msg) +{ + double v = myTolEdt->value(); + bool ok = myTolEdt->isValid(msg, true); + return !myObject->_is_nil() && (v > 0.) && ok; +} + +//================================================================================= +// function : execute +// purpose : +//================================================================================= +bool RepairGUI_LimitToleranceDlg::execute(ObjectList& objects) +{ + bool aResult = false; + objects.clear(); + + GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation()); + GEOM::GEOM_Object_var anObj = anOper->LimitTolerance(myObject, myTolEdt->value()); + aResult = !anObj->_is_nil(); + if (aResult) { + QStringList aParameters; + aParameters << myTolEdt->text(); + anObj->SetParameters(aParameters.join(":").toLatin1().constData()); + objects.push_back(anObj._retn()); + } + + return aResult; +} + +//================================================================ +// Function : onAccept +// Purpose : This method should be called from dialog's slots onOk() and onApply() +// It perfroms user input validation, then it +// performs a proper operation and manages transactions, etc. +//================================================================ +bool RepairGUI_LimitToleranceDlg::onAcceptLocal() +{ + if (!getStudy() || !(getStudy()->studyDS())) + return false; + + _PTR(Study) aStudy = getStudy()->studyDS(); + + bool aLocked = aStudy->GetProperties()->IsLocked(); + if (aLocked) { + MESSAGE("GEOMBase_Helper::onAccept - ActiveStudy is locked"); + SUIT_MessageBox::warning(this, tr("WRN_WARNING"), tr("WRN_STUDY_LOCKED"), tr("BUT_OK")); + return false; + } + + QString msg; + if (!isValid(msg)) { + showError(msg); + return false; + } + + try { + if (openCommand()) { + SUIT_OverrideCursor wc; + + myGeomGUI->getApp()->putInfo(""); + ObjectList objects; + + if (!execute(objects)) { + wc.suspend(); + abortCommand(); + showError(); + } + else { + const int nbObjs = objects.size(); + for (ObjectList::iterator it = objects.begin(); it != objects.end(); ++it) { + QString aName = getNewObjectName(); + if (nbObjs > 1) { + if (aName.isEmpty()) + aName = getPrefix(*it); + aName = GEOMBase::GetDefaultName(aName); + } + else { + // PAL6521: use a prefix, if some dialog box doesn't reimplement getNewObjectName() + if (aName.isEmpty()) + aName = GEOMBase::GetDefaultName(getPrefix(*it)); + } + addInStudy(*it, aName.toLatin1().data()); + display(*it, false); + } + + if (nbObjs) { + commitCommand(); + updateObjBrowser(); + myGeomGUI->getApp()->putInfo(QObject::tr("GEOM_PRP_DONE")); + } + else { + abortCommand(); + } + + // JFA 28.12.2004 BEGIN // To enable warnings + GEOM::GEOM_IHealingOperations_var anOper = GEOM::GEOM_IHealingOperations::_narrow(getOperation()); + if (!CORBA::is_nil(anOper) && !anOper->IsDone()) { + wc.suspend(); + QString msgw = QObject::tr(anOper->GetErrorCode()); + SUIT_MessageBox::warning(this, tr("WRN_WARNING"), msgw, tr("BUT_OK")); + } + // JFA 28.12.2004 END + } + } + } + catch(const SALOME::SALOME_Exception& e) { + SalomeApp_Tools::QtCatchCorbaException(e); + abortCommand(); + } + + updateViewer(); + activateSelection(); + updateButtonState(); + + return true; +} + +//================================================================================= +// function : activateSelection +// purpose : Activate selection +//================================================================================= +void RepairGUI_LimitToleranceDlg::activateSelection() +{ + disconnect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + + globalSelection(GEOM_ALLSHAPES); + if (myObject->_is_nil()) + SelectionIntoArgument(); + + connect(myGeomGUI->getApp()->selectionMgr(), SIGNAL(currentSelectionChanged()), + this, SLOT(SelectionIntoArgument())); + updateViewer(); +} + +//================================================================================= +// function : updateButtonState +// purpose : Update button state +//================================================================================= +void RepairGUI_LimitToleranceDlg::updateButtonState() +{ + bool hasMainObj = !myObject->_is_nil(); + buttonOk()->setEnabled(hasMainObj); + buttonApply()->setEnabled(hasMainObj); +} + +//================================================================================= +// function : restoreSubShapes +// purpose : +//================================================================================= +void RepairGUI_LimitToleranceDlg::restoreSubShapes(SALOMEDS::Study_ptr theStudy, + SALOMEDS::SObject_ptr theSObject) +{ + if (mainFrame()->CheckBoxRestoreSS->isChecked()) { + // empty list of arguments means that all arguments should be restored + getGeomEngine()->RestoreSubShapesSO(theStudy, theSObject, GEOM::ListOfGO(), + GEOM::FSM_GetInPlace, /*theInheritFirstArg=*/true, + mainFrame()->CheckBoxAddPrefix->isChecked()); + } +} diff --git a/src/RepairGUI/RepairGUI_LimitToleranceDlg.h b/src/RepairGUI/RepairGUI_LimitToleranceDlg.h new file mode 100644 index 000000000..bba1dbfff --- /dev/null +++ b/src/RepairGUI/RepairGUI_LimitToleranceDlg.h @@ -0,0 +1,83 @@ +// Copyright (C) 2007-2010 CEA/DEN, EDF R&D, OPEN CASCADE +// +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License. +// +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. +// +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// +// GEOM GEOMGUI : GUI for Geometry component +// File : RepairGUI_LimitToleranceDlg.h + +#ifndef REPAIRGUI_LIMITTOLERANCEDLG_H +#define REPAIRGUI_LIMITTOLERANCEDLG_H + +#include + +class DlgRef_1SelExt; +class SalomeApp_DoubleSpinBox; +class QPushButton; +class QCheckBox; + +//================================================================================= +// class : RepairGUI_LimitToleranceDlg +// purpose : +//================================================================================= +class RepairGUI_LimitToleranceDlg : public GEOMBase_Skeleton +{ + Q_OBJECT + +public: + RepairGUI_LimitToleranceDlg (GeometryGUI*, QWidget* = 0, bool = false); + ~RepairGUI_LimitToleranceDlg(); + +protected: + // redefined from GEOMBase_Helper + virtual GEOM::GEOM_IOperations_ptr createOperation(); + virtual bool isValid (QString&); + virtual bool execute (ObjectList&); + virtual void restoreSubShapes (SALOMEDS::Study_ptr, SALOMEDS::SObject_ptr); + +private: + void Init(); + void enterEvent (QEvent*); + void initSelection(); + + bool onAcceptLocal(); + + void activateSelection(); + void updateButtonState(); + +private: + GEOM::GEOM_Object_var myObject; + + DlgRef_1SelExt* GroupPoints; + SalomeApp_DoubleSpinBox* myTolEdt; + +private slots: + void ClickOnOk(); + bool ClickOnApply(); + + void ActivateThisDialog(); + + void LineEditReturnPressed(); + void SelectionIntoArgument(); + void SetEditCurrentArgument(); + + void ConstructorsClicked( int ); +}; + +#endif // REPAIRGUI_LIMITTOLERANCEDLG_H