]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #201: Reuse already created external edges
authorvsv <vitaly.smetannikov@opencascade.com>
Fri, 31 Oct 2014 16:24:04 +0000 (19:24 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Fri, 31 Oct 2014 16:24:04 +0000 (19:24 +0300)
src/GeomAPI/GeomAPI_Edge.cpp
src/GeomAPI/GeomAPI_Edge.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/SketchPlugin/SketchPlugin_Feature.h

index a4b42b207dd60d9445b4de1189fb01110a71fab3..5c61a94a1360d4588b652f5c5ac26c84115ba8a8 100644 (file)
@@ -9,10 +9,12 @@
 
 #include <TopoDS_Shape.hxx>
 #include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
 #include <BRep_Tool.hxx>
 #include <Geom_Curve.hxx>
 #include <Geom_Line.hxx>
 #include <Geom_Circle.hxx>
+#include <GeomAdaptor_Curve.hxx>
 #include <gp_Ax1.hxx>
 
 GeomAPI_Edge::GeomAPI_Edge()
@@ -94,3 +96,37 @@ boost::shared_ptr<GeomAPI_Circ> GeomAPI_Edge::circle()
   }
   return boost::shared_ptr<GeomAPI_Circ>(); // not circle
 }
+
+
+bool GeomAPI_Edge::isEqual(boost::shared_ptr<GeomAPI_Shape> theEdge)
+{
+  const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Edge*>(this)->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aInShape = theEdge->impl<TopoDS_Shape>();
+  
+  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
index 6814bb68777cce3c2f8000735a97b3989d45933d..ea4be9ef62f0aebc8ba02769f4dc99b5321d7c85 100644 (file)
@@ -41,6 +41,9 @@ public:
 
   /// Returns a circle if edge is based on the cirsle curve
   boost::shared_ptr<GeomAPI_Circ> circle();
+
+  /// Returns true if the current edge is geometrically equal to the given edge
+  bool isEqual(boost::shared_ptr<GeomAPI_Shape> theEdge);
 };
 
 #endif
index 668cb4653b28ced6903969b4fda8b250d0279b7f..dfd39512dfd04867ed34e3b81b158e5a0a81b25a 100644 (file)
@@ -9,6 +9,7 @@
 #include <ModelAPI_AttributeRefList.h>
 #include <ModelAPI_Document.h>
 #include <ModelAPI_Session.h>
+#include <ModelAPI_ResultConstruction.h>
 
 #include <GeomDataAPI_Point.h>
 #include <GeomDataAPI_Dir.h>
@@ -16,6 +17,7 @@
 #include <GeomAPI_Pln.h>
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Pnt.h>
+#include <GeomAPI_Edge.h>
 
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_XYZ.h>
@@ -43,6 +45,7 @@
 #include <GeomAPI_ProjectPointOnCurve.hxx>
 #include <BRep_Tool.hxx>
 #include <TopoDS.hxx>
+#include <TopoDS_Edge.hxx>
 
 #ifdef _DEBUG
 #include <QDebug>
@@ -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<GeomAPI_Edge> aInEdge = boost::shared_ptr<GeomAPI_Edge>(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<ModuleBase_ViewerPrs>& the
   }
   return false;
 }
+
+ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, boost::shared_ptr<GeomAPI_Edge> theEdge)
+{
+  for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+    FeaturePtr aFeature = theSketch->subFeature(i);
+    boost::shared_ptr<SketchPlugin_Feature> aSketchFea = 
+      boost::dynamic_pointer_cast<SketchPlugin_Feature>(aFeature);
+    if (aSketchFea) {
+      if (aSketchFea->isExternal()) {
+        std::list<ResultPtr> aResults = aSketchFea->results();
+        std::list<ResultPtr>::const_iterator aIt;
+        for (aIt = aResults.cbegin(); aIt != aResults.cend(); ++aIt) {
+          ResultConstructionPtr aRes = 
+            boost::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
+          if (aRes) {
+            boost::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
+            if (aShape) {
+              if (theEdge->isEqual(aShape))
+                return aRes;
+            }
+          }
+        }
+      }
+    }
+  }
+  return ResultPtr();
+}
\ No newline at end of file
index c847a1ad11f205dab6de36a0e1c5ae64f6afdef5..1e5b4b0851eeaf3af63c2a0e7f759762f521f16d 100644 (file)
@@ -14,7 +14,6 @@
 #include <QList>
 
 #include <ModelAPI_CompositeFeature.h>
-#include <TopoDS_Edge.hxx>
 
 #include <boost/shared_ptr.hpp>
 
@@ -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<ModuleBase_ViewerPrs>& 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<GeomAPI_Edge> theEdge);
 };
 
 #endif
index 8c022ed2bc441993c8076809bc1c28ce2463c86d..2f4c3aaf17fd94aba30aaf0180fa38cfe00a25f2 100644 (file)
@@ -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: