]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Process non-sketch Points for Distance constraint
authorvsv <vitaly.smetannikov@opencascade.com>
Tue, 16 Dec 2014 13:05:46 +0000 (16:05 +0300)
committervsv <vitaly.smetannikov@opencascade.com>
Tue, 16 Dec 2014 13:05:46 +0000 (16:05 +0300)
src/GeomAPI/CMakeLists.txt
src/GeomAPI/GeomAPI_Vertex.cpp [new file with mode: 0644]
src/GeomAPI/GeomAPI_Vertex.h [new file with mode: 0644]
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetShapeSelector.cpp

index eec0e4d2c7529624f826adaf78ed1a25c0dd21d2..2df13f8cc8165fc8942ce7b6121aa0e2f3ef939e 100644 (file)
@@ -27,7 +27,8 @@ SET(PROJECT_HEADERS
     GeomAPI_IPresentable.h
     GeomAPI_Curve.h 
     GeomAPI_DataMapOfShapeShape.h
-       GeomAPI_ICustomPrs.h
+    GeomAPI_ICustomPrs.h
+    GeomAPI_Vertex.h
 )
 
 SET(PROJECT_SOURCES
@@ -50,6 +51,7 @@ SET(PROJECT_SOURCES
     GeomAPI_AISObject.cpp
     GeomAPI_Curve.cpp
     GeomAPI_DataMapOfShapeShape.cpp
+    GeomAPI_Vertex.cpp
 )
 
 SET(PROJECT_LIBRARIES
diff --git a/src/GeomAPI/GeomAPI_Vertex.cpp b/src/GeomAPI/GeomAPI_Vertex.cpp
new file mode 100644 (file)
index 0000000..6c3d05e
--- /dev/null
@@ -0,0 +1,50 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAPI_Vertex.cpp
+// Created:     24 Jul 2014
+// Author:      Artem ZHIDKOV
+
+#include<GeomAPI_Vertex.h>
+#include<GeomAPI_Pnt.h>
+
+#include <TopoDS_Shape.hxx>
+#include <TopoDS_Edge.hxx>
+#include <TopoDS.hxx>
+#include <TopoDS_Vertex.hxx>
+#include <BRep_Tool.hxx>
+#include <gp_Pnt.hxx>
+#include <Precision.hxx>
+
+GeomAPI_Vertex::GeomAPI_Vertex()
+  : GeomAPI_Shape()
+{
+}
+
+GeomAPI_Vertex::GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape)
+{
+  if (!theShape->isNull() && theShape->isVertex()) {
+    setImpl(new TopoDS_Shape(theShape->impl<TopoDS_Shape>()));
+  }
+}
+
+std::shared_ptr<GeomAPI_Pnt> GeomAPI_Vertex::point()
+{
+  const TopoDS_Shape& aShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
+  TopoDS_Vertex aVertex = TopoDS::Vertex(aShape);
+  gp_Pnt aPoint = BRep_Tool::Pnt(aVertex);
+  return std::shared_ptr<GeomAPI_Pnt>(new GeomAPI_Pnt(aPoint.X(), aPoint.Y(), aPoint.Z()));
+}
+
+bool GeomAPI_Vertex::isEqual(std::shared_ptr<GeomAPI_Shape> theVert)
+{
+  const TopoDS_Shape& aMyShape = const_cast<GeomAPI_Vertex*>(this)->impl<TopoDS_Shape>();
+  const TopoDS_Shape& aInShape = theVert->impl<TopoDS_Shape>();
+
+  TopoDS_Vertex aVertex1 = TopoDS::Vertex(aMyShape);
+  gp_Pnt aPoint1 = BRep_Tool::Pnt(aVertex1);
+
+  TopoDS_Vertex aVertex2 = TopoDS::Vertex(aInShape);
+  gp_Pnt aPoint2 = BRep_Tool::Pnt(aVertex2);
+
+  return aPoint1.IsEqual(aPoint2, Precision::Confusion());
+}
diff --git a/src/GeomAPI/GeomAPI_Vertex.h b/src/GeomAPI/GeomAPI_Vertex.h
new file mode 100644 (file)
index 0000000..fab2840
--- /dev/null
@@ -0,0 +1,36 @@
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File:        GeomAPI_Vertex.hxx
+// Created:     16 Dec 2014
+// Author:      Vitaly Smetannikov
+
+#ifndef GeomAPI_Vertex_H_
+#define GeomAPI_Vertex_H_
+
+#include <GeomAPI_Shape.h>
+
+class GeomAPI_Pnt;
+
+/**\class GeomAPI_Vertex
+* \ingroup DataModel
+ * \brief Interface to the vertex object
+ */
+
+class GEOMAPI_EXPORT GeomAPI_Vertex : public GeomAPI_Shape
+{
+public:
+   /// Creation of empty (null) shape
+   GeomAPI_Vertex();
+
+   /// Creation of edge by the edge-shape
+   GeomAPI_Vertex(const std::shared_ptr<GeomAPI_Shape>& theShape);
+
+  /// Returns the first vertex coordinates of the edge 
+  std::shared_ptr<GeomAPI_Pnt> point();
+
+  /// Returns true if the current edge is geometrically equal to the given edge
+  bool isEqual(std::shared_ptr<GeomAPI_Shape> theVert);
+};
+
+#endif
+
index 41182b67466ec120220231ecb90a898b894fb989..78df67edb61f3a0f9a98e7400a2e967329eb67e8 100644 (file)
@@ -20,6 +20,7 @@
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_Pnt.h>
 #include <GeomAPI_Edge.h>
+#include <GeomAPI_Vertex.h>
 
 #include <GeomAPI_Dir.h>
 #include <GeomAPI_XYZ.h>
@@ -35,6 +36,7 @@
 #include <SketchPlugin_Circle.h>
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
 
 #include <ModuleBase_ViewerPrs.h>
 
@@ -402,56 +404,87 @@ ResultPtr PartSet_Tools::createFixedObjectByEdge(const TopoDS_Shape& theShape,
                                                  const ObjectPtr& theObject, 
                                                  CompositeFeaturePtr theSketch)
 {
-  if (theShape.ShapeType() != TopAbs_EDGE)
-    return ResultPtr();
-
-  // Check that we already have such external edge
-  std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
-  aInEdge->setImpl(new TopoDS_Shape(theShape));
-  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;
-
-  Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd);
-  GeomAdaptor_Curve aAdaptor(aCurve);
-  if (aAdaptor.GetType() == GeomAbs_Line) {
-    // Create line
-    aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID());
-  } else if (aAdaptor.GetType() == GeomAbs_Circle) {
-    if (aAdaptor.IsClosed()) {
-      // Create circle
-      aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
-    } else {
-      // Create arc
-      aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
+  if (theShape.ShapeType() == TopAbs_EDGE) {
+    // Check that we already have such external edge
+    std::shared_ptr<GeomAPI_Edge> aInEdge = std::shared_ptr<GeomAPI_Edge>(new GeomAPI_Edge());
+    aInEdge->setImpl(new TopoDS_Shape(theShape));
+    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;
+
+    Handle(Geom_Curve) aCurve = BRep_Tool::Curve(TopoDS::Edge(theShape), aStart, aEnd);
+    GeomAdaptor_Curve aAdaptor(aCurve);
+    if (aAdaptor.GetType() == GeomAbs_Line) {
+      // Create line
+      aMyFeature = theSketch->addFeature(SketchPlugin_Line::ID());
+    } else if (aAdaptor.GetType() == GeomAbs_Circle) {
+      if (aAdaptor.IsClosed()) {
+        // Create circle
+        aMyFeature = theSketch->addFeature(SketchPlugin_Circle::ID());
+      } else {
+        // Create arc
+        aMyFeature = theSketch->addFeature(SketchPlugin_Arc::ID());
+      }
     }
-  }
-  if (aMyFeature) {
-    DataPtr aData = aMyFeature->data();
-    AttributeSelectionPtr anAttr = 
-      std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
-      (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+    if (aMyFeature) {
+      DataPtr aData = aMyFeature->data();
+      AttributeSelectionPtr anAttr = 
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+        (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
 
-    ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
-    if (anAttr && aRes) {
-      std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
-      anEdge->setImpl(new TopoDS_Shape(theShape));
+      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+      if (anAttr && aRes) {
+        std::shared_ptr<GeomAPI_Shape> anEdge(new GeomAPI_Shape);
+        anEdge->setImpl(new TopoDS_Shape(theShape));
 
-      anAttr->setValue(aRes, anEdge);
+        anAttr->setValue(aRes, anEdge);
 
-      aMyFeature->execute();
+        aMyFeature->execute();
 
-      // fix this edge
-      FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
-      aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
-        setObject(aMyFeature->lastResult());
+        // fix this edge
+        FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
+        aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
+          setObject(aMyFeature->lastResult());
 
-      return aMyFeature->lastResult();
+        return aMyFeature->lastResult();
+      }
+    }
+  }
+  if (theShape.ShapeType() == TopAbs_VERTEX) {
+    std::shared_ptr<GeomAPI_Vertex> aInVert = std::shared_ptr<GeomAPI_Vertex>(new GeomAPI_Vertex());
+    aInVert->setImpl(new TopoDS_Shape(theShape));
+    ResultPtr aResult = findExternalVertex(theSketch, aInVert);
+    if (aResult)
+      return aResult;
+
+    FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID());
+
+    if (aMyFeature) {
+      DataPtr aData = aMyFeature->data();
+      AttributeSelectionPtr anAttr = 
+        std::dynamic_pointer_cast<ModelAPI_AttributeSelection>
+        (aData->attribute(SketchPlugin_Feature::EXTERNAL_ID()));
+
+      ResultPtr aRes = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
+      if (anAttr && aRes) {
+        std::shared_ptr<GeomAPI_Shape> aVert(new GeomAPI_Shape);
+        aVert->setImpl(new TopoDS_Shape(theShape));
+
+        anAttr->setValue(aRes, aVert);
+        aMyFeature->execute();
+
+        // fix this edge
+        FeaturePtr aFix = theSketch->addFeature(SketchPlugin_ConstraintRigid::ID());
+        aFix->data()->refattr(SketchPlugin_Constraint::ENTITY_A())->
+          setObject(aMyFeature->lastResult());
+
+        return aMyFeature->lastResult();
+      }
     }
   }
   return ResultPtr();
@@ -494,6 +527,35 @@ ResultPtr PartSet_Tools::findExternalEdge(CompositeFeaturePtr theSketch, std::sh
   return ResultPtr();
 }
 
+
+ResultPtr PartSet_Tools::findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert)
+{
+  for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+    FeaturePtr aFeature = theSketch->subFeature(i);
+    std::shared_ptr<SketchPlugin_Feature> aSketchFea = 
+      std::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 = 
+            std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aIt);
+          if (aRes) {
+            std::shared_ptr<GeomAPI_Shape> aShape = aRes->shape();
+            if (aShape) {
+              if (theVert->isEqual(aShape))
+                return aRes;
+            }
+          }
+        }
+      }
+    }
+  }
+  return ResultPtr();
+}
+
+
 bool PartSet_Tools::hasVertexShape(const ModuleBase_ViewerPrs& thePrs, FeaturePtr theSketch,
                                    Handle_V3d_View theView, double& theX, double& theY)
 {
index ec1afea13b22676a35d00deb9663952e7ff69751..e3579c9f56b5958559ce8d88e132381a1d696284 100644 (file)
@@ -30,6 +30,7 @@ class GeomAPI_Pln;
 class GeomAPI_Pnt2d;
 class GeomAPI_Pnt;
 class GeomAPI_Edge;
+class GeomAPI_Vertex;
 
 /*!
  \class PartSet_Tools
@@ -160,6 +161,12 @@ class PARTSET_EXPORT PartSet_Tools
   /// \return result object with external edge if it is found
   static ResultPtr findExternalEdge(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Edge> theEdge);
 
+  /// Returns Result object if the given sketch contains external vertex equal to the given
+  /// \param theSketch - the sketch feature
+  /// \param theVert - the vertex
+  /// \return result object with external vertex if it is found
+  static ResultPtr findExternalVertex(CompositeFeaturePtr theSketch, std::shared_ptr<GeomAPI_Vertex> theVert);
+
   /// Returns whether the selected presentation has a shape with the vertex type
   /// \param thePrs a selected presentation
   /// \param theSketch the sketch feature
index fe34cc85911daf828a8dd1d363ce3bac859eb043..04f026112ce43b54ca6d18f01898b82081209fe0 100644 (file)
@@ -19,22 +19,35 @@ bool PartSet_WidgetShapeSelector::storeValue() const
   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(mySelectedObject);
   if (aSelectedFeature == myFeature)  // In order to avoid selection of the same object
     return false;
+  std::shared_ptr<SketchPlugin_Feature> aSPFeature = 
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+  if ((!aSPFeature) && (!myShape->isNull())) {
+    // Processing of external (non-sketch) object
+    ObjectPtr aObj = PartSet_Tools::createFixedObjectByEdge(myShape->impl<TopoDS_Shape>(),
+                                                            mySelectedObject, mySketch);
+    if (aObj) {
+      PartSet_WidgetShapeSelector* that = (PartSet_WidgetShapeSelector*) this;
+      that->mySelectedObject = aObj;
+    } else 
+      return false;
+  } else {
+    // Processing of sketch object
+    DataPtr aData = myFeature->data();
+    if (myUseSubShapes && myShape) {
+      AttributePtr aAttr = aData->attribute(attributeID());
+      AttributeRefAttrPtr aRefAttr = 
+        std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
+      if (aRefAttr) {
+        TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
+        AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
+        if (mySelectedObject)
+          aRefAttr->setObject(mySelectedObject);
+        if (aPntAttr)
+          aRefAttr->setAttr(aPntAttr);
 
-  DataPtr aData = myFeature->data();
-  if (myUseSubShapes && myShape) {
-    AttributePtr aAttr = aData->attribute(attributeID());
-    AttributeRefAttrPtr aRefAttr = 
-      std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(aAttr);
-    if (aRefAttr) {
-      TopoDS_Shape aShape = myShape->impl<TopoDS_Shape>();
-      AttributePtr aPntAttr = PartSet_Tools::findAttributeBy2dPoint(mySelectedObject, aShape, mySketch);
-      if (mySelectedObject)
-        aRefAttr->setObject(mySelectedObject);
-      if (aPntAttr)
-        aRefAttr->setAttr(aPntAttr);
-
-      updateObject(myFeature);
-      return true;
+        updateObject(myFeature);
+        return true;
+      }
     }
   }
   return ModuleBase_WidgetShapeSelector::storeValue();
@@ -53,7 +66,8 @@ bool PartSet_WidgetConstraintShapeSelector::storeValue() const
       if (aObj) {
         PartSet_WidgetConstraintShapeSelector* that = (PartSet_WidgetConstraintShapeSelector*) this;
         that->mySelectedObject = aObj;
-      }
+      } else 
+        return false;
     }
   }
   return ModuleBase_WidgetShapeSelector::storeValue();