From: vsv Date: Fri, 31 Oct 2014 16:24:04 +0000 (+0300) Subject: Issue #201: Reuse already created external edges X-Git-Tag: V_0.5~43 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=87f32fb90e038b3b84047c5c4fe518617265fc46;p=modules%2Fshaper.git Issue #201: Reuse already created external edges --- diff --git a/src/GeomAPI/GeomAPI_Edge.cpp b/src/GeomAPI/GeomAPI_Edge.cpp index a4b42b207..5c61a94a1 100644 --- a/src/GeomAPI/GeomAPI_Edge.cpp +++ b/src/GeomAPI/GeomAPI_Edge.cpp @@ -9,10 +9,12 @@ #include #include +#include #include #include #include #include +#include #include GeomAPI_Edge::GeomAPI_Edge() @@ -94,3 +96,37 @@ boost::shared_ptr GeomAPI_Edge::circle() } return boost::shared_ptr(); // not circle } + + +bool GeomAPI_Edge::isEqual(boost::shared_ptr theEdge) +{ + const TopoDS_Shape& aMyShape = const_cast(this)->impl(); + const TopoDS_Shape& aInShape = theEdge->impl(); + + double aMyStart, aMyEnd; + Handle(Geom_Curve) aMyCurve = BRep_Tool::Curve(TopoDS::Edge(aMyShape), aMyStart, aMyEnd); + double aInStart, aInEnd; + Handle(Geom_Curve) aInCurve = BRep_Tool::Curve(TopoDS::Edge(aInShape), aInStart, aInEnd); + + // Check that curves a the same type + GeomAdaptor_Curve aMyAdaptor(aMyCurve); + GeomAdaptor_Curve aInAdaptor(aInCurve); + if (aMyAdaptor.GetType() != aInAdaptor.GetType()) + return false; + + // Check that end point parameters are the same + if ((aMyStart != aInStart) || (aMyEnd != aInEnd)) + return false; + + // Check that end points are equal + gp_Pnt aMyPnt1 = aMyAdaptor.Value(aMyStart); + gp_Pnt aMyPnt2 = aMyAdaptor.Value(aMyEnd); + gp_Pnt aInPnt1 = aInAdaptor.Value(aInStart); + gp_Pnt aInPnt2 = aInAdaptor.Value(aInEnd); + + if ((!aMyPnt1.IsEqual(aInPnt1, Precision::Confusion())) || + (!aMyPnt2.IsEqual(aInPnt2, Precision::Confusion()))) + return false; + + return true; +} \ No newline at end of file diff --git a/src/GeomAPI/GeomAPI_Edge.h b/src/GeomAPI/GeomAPI_Edge.h index 6814bb687..ea4be9ef6 100644 --- a/src/GeomAPI/GeomAPI_Edge.h +++ b/src/GeomAPI/GeomAPI_Edge.h @@ -41,6 +41,9 @@ public: /// Returns a circle if edge is based on the cirsle curve boost::shared_ptr circle(); + + /// Returns true if the current edge is geometrically equal to the given edge + bool isEqual(boost::shared_ptr theEdge); }; #endif diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 668cb4653..dfd39512d 100644 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -16,6 +17,7 @@ #include #include #include +#include #include #include @@ -43,6 +45,7 @@ #include #include #include +#include #ifdef _DEBUG #include @@ -362,6 +365,14 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const ModuleBase_ViewerPrs& the if (aShape.ShapeType() != TopAbs_EDGE) return ResultPtr(); + // Check that we already have such external edge + boost::shared_ptr aInEdge = boost::shared_ptr(new GeomAPI_Edge()); + aInEdge->setImpl(new TopoDS_Shape(aShape)); + ResultPtr aResult = findExternalEdge(theSketch, aInEdge); + if (aResult) + return aResult; + + // If not found then we have to create new Standard_Real aStart, aEnd; Handle(V3d_View) aNullView; FeaturePtr aMyFeature; @@ -435,3 +446,30 @@ bool PartSet_Tools::isContainPresentation(const QList& the } return false; } + +ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr theEdge) +{ + for (int i = 0; i < theSketch->numberOfSubs(); i++) { + FeaturePtr aFeature = theSketch->subFeature(i); + boost::shared_ptr aSketchFea = + boost::dynamic_pointer_cast(aFeature); + if (aSketchFea) { + if (aSketchFea->isExternal()) { + std::list aResults = aSketchFea->results(); + std::list::const_iterator aIt; + for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) { + ResultConstructionPtr aRes = + boost::dynamic_pointer_cast(*aIt); + if (aRes) { + boost::shared_ptr aShape = aRes->shape(); + if (aShape) { + if (theEdge->isEqual(aShape)) + return aRes; + } + } + } + } + } + } + return ResultPtr(); +} \ No newline at end of file diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index c847a1ad1..1e5b4b085 100644 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -14,7 +14,6 @@ #include #include -#include #include @@ -24,6 +23,7 @@ class GeomDataAPI_Point2D; class GeomAPI_Pln; class GeomAPI_Pnt2d; class GeomAPI_Pnt; +class GeomAPI_Edge; /*! \class PartSet_Tools @@ -141,6 +141,11 @@ class PARTSET_EXPORT PartSet_Tools static bool isContainPresentation(const QList& theSelected, const ModuleBase_ViewerPrs& thePrs); + /// Returns Result object if the given skietch contains external edge equal to the given + /// \param theSketch - the sketch feature + /// \param theEdge - the edge + /// \return result object with external edge if it is found + static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr theEdge); }; #endif diff --git a/src/SketchPlugin/SketchPlugin_Feature.h b/src/SketchPlugin/SketchPlugin_Feature.h index 8c022ed2b..2f4c3aaf1 100644 --- a/src/SketchPlugin/SketchPlugin_Feature.h +++ b/src/SketchPlugin/SketchPlugin_Feature.h @@ -55,6 +55,14 @@ class SketchPlugin_Feature : public ModelAPI_Feature /// Returns true is sketch element is under the rigid constraint SKETCHPLUGIN_EXPORT virtual bool isFixed() {return false;} + bool isExternal() const + { + AttributeSelectionPtr aAttr = data()->selection(EXTERNAL_ID()); + if (aAttr) + return aAttr->context(); + return false; + } + /// Returns the sketch of this feature SketchPlugin_Sketch* sketch(); protected: