Salome HOME
Split preview correction: it is provided by AISObject of presentable interface
authornds <nds@opencascade.com>
Thu, 8 Sep 2016 07:14:34 +0000 (10:14 +0300)
committernds <nds@opencascade.com>
Thu, 8 Sep 2016 07:14:34 +0000 (10:14 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.cpp
src/GeomAlgoAPI/GeomAlgoAPI_ShapeTools.h
src/Model/Model_Update.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Point2D.cpp
src/ModelGeomAlgo/ModelGeomAlgo_Point2D.h
src/PartSet/PartSet_WidgetSubShapeSelector.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp
src/SketchPlugin/SketchPlugin_ConstraintSplit.h
src/SketchPlugin/SketchPlugin_Validators.cpp

index 7c0f462e086a033cd980920130a521a79856ba09..bc64bf02efff1db2fb5198822526d9740b2a004c 100644 (file)
@@ -672,8 +672,8 @@ bool GeomAlgoAPI_ShapeTools::isParallel(const std::shared_ptr<GeomAPI_Edge> theE
 
 //==================================================================================================
 void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
-                                        const std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
-                                        std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
+                                          const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+                                          std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
 {
   // General Fuse to split edge by vertices
   BOPAlgo_Builder aBOP;
@@ -685,7 +685,7 @@ void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& th
     Standard_Real aFirst, aLast;
     Handle(Geom_Curve) aCurve = BRep_Tool::Curve(aBaseEdge, aFirst, aLast);
 
-    std::set<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPIt = thePoints.begin();
+    std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPIt = thePoints.begin();
     gp_Pnt aPoint((*aPIt)->x(), (*aPIt)->y(), (*aPIt)->z());
 
     TopAbs_Orientation anOrientation = aBaseEdge.Orientation();
@@ -694,7 +694,7 @@ void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& th
   }
   aBOP.AddArgument(aBaseEdge);
 
-  std::set<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPtIt = thePoints.begin();
+  std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPtIt = thePoints.begin();
   for (; aPtIt != thePoints.end(); ++aPtIt) {
     std::shared_ptr<GeomAPI_Pnt> aPnt = *aPtIt;
     TopoDS_Vertex aV = BRepBuilderAPI_MakeVertex(gp_Pnt(aPnt->x(), aPnt->y(), aPnt->z()));
@@ -714,3 +714,34 @@ void GeomAlgoAPI_ShapeTools::splitShape(const std::shared_ptr<GeomAPI_Shape>& th
     theShapes.insert(anEdge);
   }
 }
+
+//==================================================================================================
+std::shared_ptr<GeomAPI_Shape> GeomAlgoAPI_ShapeTools::findShape(
+                                  const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+                                  const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes)
+{
+  std::shared_ptr<GeomAPI_Shape> aResultShape;
+
+  if (thePoints.size() == 2) {
+    std::list<std::shared_ptr<GeomAPI_Pnt> >::const_iterator aPntIt = thePoints.begin();
+    std::shared_ptr<GeomAPI_Pnt> aFirstPoint = *aPntIt;
+    aPntIt++;
+    std::shared_ptr<GeomAPI_Pnt> aLastPoint = *aPntIt;
+
+    std::set<std::shared_ptr<GeomAPI_Shape> >::const_iterator anIt = theShapes.begin(),
+                                                              aLast = theShapes.end();
+    for (; anIt != aLast; anIt++) {
+      GeomShapePtr aShape = *anIt;
+      std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aShape));
+      if (anEdge.get()) {
+        std::shared_ptr<GeomAPI_Pnt> anEdgeFirstPoint = anEdge->firstPoint();
+        std::shared_ptr<GeomAPI_Pnt> anEdgeLastPoint = anEdge->lastPoint();
+        if (anEdgeFirstPoint->isEqual(aFirstPoint) &&
+            anEdgeLastPoint->isEqual(aLastPoint))
+            aResultShape = aShape;
+      }
+    }
+  }
+
+  return aResultShape;
+}
index f69ad5cd56ef1c0c0657c2eeeb63dc4750ac400b..cadedc031b78b453c9b3d8279a37838817cd5e93 100644 (file)
@@ -104,13 +104,20 @@ public:
   /// \return true if edge is parallel to face.
   GEOMALGOAPI_EXPORT static bool isParallel(const std::shared_ptr<GeomAPI_Edge> theEdge,
                                             const std::shared_ptr<GeomAPI_Face> theFace);
+
   /// \brief Performs the split of the shape by points.
   /// \param[in] theBaseShape shape that should be splitted.
   /// \param[in] thePoints container of points to split
   /// \param[out] theShapes container of shapes after split
   GEOMALGOAPI_EXPORT static void splitShape(const std::shared_ptr<GeomAPI_Shape>& theBaseShape,
-                                            const std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+                                            const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
                                             std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
+
+
+  GEOMALGOAPI_EXPORT static std::shared_ptr<GeomAPI_Shape> findShape(
+                                              const std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+                                              const std::set<std::shared_ptr<GeomAPI_Shape> >& theShapes);
+
 };
 
 #endif
index a156d40021ce39b366690e32358e1403f7cd872b..f4e189731106f380836dced24b126fae86f5a8ec 100755 (executable)
@@ -105,6 +105,14 @@ bool Model_Update::addModified(FeaturePtr theFeature, FeaturePtr theReason) {
     static ModelAPI_ValidatorsFactory* aFactory = ModelAPI_Session::get()->validators();
     aFactory->validate(theFeature); // need to be validated to update the "Apply" state if not previewed
 
+    // to redisplay split's arguments presentation, even result is not computed
+    if (!theFeature->isPreviewNeeded()) {
+      static Events_Loop* aLoop = Events_Loop::loop();
+      static const Events_ID kRedisplayEvent = aLoop->eventByName(EVENT_OBJECT_TO_REDISPLAY);
+      ModelAPI_EventCreator::get()->sendUpdated(theFeature, kRedisplayEvent);
+      aLoop->flush(kRedisplayEvent);
+    }
+
     if (!myIsPreviewBlocked)
       return true;
   }
index 2e81b4f3403ec7be94685c66f3fbdaacdfc2d2e6..976988cdee9ed213e4024388d0594ae805138657 100755 (executable)
@@ -120,7 +120,7 @@ namespace ModelGeomAlgo_Point2D {
                             const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
                             const std::shared_ptr<GeomAPI_Dir>& theDirX,
                             const std::shared_ptr<GeomAPI_Dir>& theDirY,
-                            std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+                            std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
                             std::map<std::shared_ptr<GeomDataAPI_Point2D>,
                                      std::shared_ptr<GeomAPI_Pnt> >& theAttributeToPoint)
   {
@@ -132,7 +132,7 @@ namespace ModelGeomAlgo_Point2D {
       std::shared_ptr<GeomAPI_Pnt> aPoint = aPnt2d->to3D(theOrigin, theDirX, theDirY);
       std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
       if (isPointOnEdge(theBaseShape, aPoint, aProjectedPoint)) {
-        thePoints.insert(aProjectedPoint);
+        thePoints.push_back(aProjectedPoint);
         theAttributeToPoint[anAttribute] = aProjectedPoint;
       }
     }
index 940a869c8716faa150c100e56ad2e18c6ec40b21..7f1e89bdf0c03e6266e41b1db7582667cac04e9a 100755 (executable)
@@ -69,7 +69,7 @@ namespace ModelGeomAlgo_Point2D {
                               const std::shared_ptr<GeomAPI_Pnt>& theOrigin,
                               const std::shared_ptr<GeomAPI_Dir>& theDirX,
                               const std::shared_ptr<GeomAPI_Dir>& theDirY,
-                              std::set<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
+                              std::list<std::shared_ptr<GeomAPI_Pnt> >& thePoints,
                               std::map<std::shared_ptr<GeomDataAPI_Point2D>,
                                        std::shared_ptr<GeomAPI_Pnt> >& theAttributeToPoint);
 
index 35480469d79694337cc27f03b07b59910334d705..50f81218d9c380d5008baac0d6b09bbbd360adce 100755 (executable)
@@ -246,7 +246,7 @@ void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject
     std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
     std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
-    std::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+    std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
     ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(),
                                                 aX->dir(), aY, aPoints, aPointToAttributes);
 
index 395ae31715335f41489bb6144aba5486e2af8416..a7b725c9d41317195f517e0c257cce5c38d19bb6 100755 (executable)
@@ -10,6 +10,8 @@
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
 #include <ModelAPI_AttributeReference.h>
 #include <ModelAPI_AttributeString.h>
 #include <ModelAPI_AttributeRefAttr.h>
@@ -313,6 +315,54 @@ bool SketchPlugin_ConstraintSplit::isMacro() const
   return true;
 }
 
+AISObjectPtr SketchPlugin_ConstraintSplit::getAISObject(AISObjectPtr thePrevious)
+{
+  AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+                                           data()->attribute(SketchPlugin_Constraint::VALUE()));
+  FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
+
+  AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(
+                                        data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
+  AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(
+                                        data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
+
+  if (aBaseObjectAttr->isInitialized() && aBaseFeature.get() &&
+      aFirstPointAttrOfSplit->isInitialized() &&
+      aSecondPointAttrOfSplit->isInitialized()) {
+
+    ResultPtr aResult = getFeatureResult(aBaseFeature);
+    GeomShapePtr aBaseShape = aResult->shape();
+    std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+
+    std::shared_ptr<GeomAPI_Pnt2d> aStartPnt2d = aFirstPointAttrOfSplit->pnt();
+    std::shared_ptr<GeomAPI_Pnt> aStartPoint = sketch()->to3D(aStartPnt2d->x(), aStartPnt2d->y());
+    aPoints.push_back(aStartPoint);
+
+    std::shared_ptr<GeomAPI_Pnt2d> aSecondPnt2d = aSecondPointAttrOfSplit->pnt();
+    std::shared_ptr<GeomAPI_Pnt> aSecondPoint = sketch()->to3D(aSecondPnt2d->x(), aSecondPnt2d->y());
+    aPoints.push_back(aSecondPoint);
+
+    std::set<std::shared_ptr<GeomAPI_Shape> > aSplitShapes;
+
+    GeomAlgoAPI_ShapeTools::splitShape(aBaseShape, aPoints, aSplitShapes);
+    std::shared_ptr<GeomAPI_Shape> aShape = GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes);
+
+    AISObjectPtr anAIS = thePrevious;
+    if (aShape) {
+      if (!anAIS)
+        anAIS = AISObjectPtr(new GeomAPI_AISObject);
+      anAIS->createShape(aShape);
+      anAIS->setWidth(5);
+      std::vector<int> aColor;
+      aColor = Config_PropManager::color("Visualization", "sketch_entity_color",
+                                          SKETCH_ENTITY_COLOR);
+     anAIS->setColor(aColor[0], aColor[1], aColor[2]);
+    }
+    return anAIS;
+  }
+  return AISObjectPtr();
+}
+
 std::shared_ptr<GeomDataAPI_Point2D> SketchPlugin_ConstraintSplit::getPointOfRefAttr(
                                                                   const AttributePtr& theAttribute)
 {
index eab2ae86f0336a1d75005f536fe1d9e0c08f1e1e..dee2b9e041dd213133d16f854d49b708fb99f618 100755 (executable)
@@ -85,6 +85,9 @@ class SketchPlugin_ConstraintSplit : public SketchPlugin_ConstraintBase
   //  return myPointFeaturesMap;
   //};
 
+  /// Returns the AIS preview
+  SKETCHPLUGIN_EXPORT virtual AISObjectPtr getAISObject(AISObjectPtr thePrevious);
+
 private:
   /// Returns geom point attribute of the feature bounds. It processes line or arc.
   /// For circle feature, the result attributes are null
index 9db33a5ed0bd0080c9d7e87d1561e717cfe67355..4f88df34c2ce296078296b9b8fb52a33a4583db3 100755 (executable)
@@ -863,7 +863,7 @@ bool SketchPlugin_SplitValidator::isValid(const AttributePtr& theAttribute,
         aData->attribute(SketchPlugin_Sketch::NORM_ID()));
     std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
     
-    std::set<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+    std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
     std::map<std::shared_ptr<GeomDataAPI_Point2D>, std::shared_ptr<GeomAPI_Pnt> > aPointToAttributes;
     ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
                                                 aX->dir(), aDirY, aPoints, aPointToAttributes);