]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #1393 Angle constraint : incorrect angle displayed. solution: arc's passed...
authornds <nds@opencascade.com>
Fri, 8 Apr 2016 11:10:37 +0000 (14:10 +0300)
committernds <nds@opencascade.com>
Fri, 8 Apr 2016 11:10:37 +0000 (14:10 +0300)
src/GeomAlgoAPI/GeomAlgoAPI_EdgeBuilder.cpp
src/ModuleBase/ModuleBase_WidgetValidated.cpp
src/ModuleBase/ModuleBase_WidgetValidator.cpp
src/ModuleBase/ModuleBase_WidgetValidator.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h
src/SketchPlugin/SketchPlugin_Arc.cpp

index 9089c195acb506840861956f8605354930fdaf2e..97e62158a5adfb6f0875bf681de1a1d86af06f57 100644 (file)
@@ -147,10 +147,7 @@ std::shared_ptr<GeomAPI_Edge> GeomAlgoAPI_EdgeBuilder::lineCircleArc(
   const gp_Pnt& anEnd = theEndPoint->impl<gp_Pnt>();
 
   BRepBuilderAPI_MakeEdge anEdgeBuilder;
-  if (aStart.IsEqual(anEnd, Precision::Confusion()))
-    anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle);
-  else
-    anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
+  anEdgeBuilder = BRepBuilderAPI_MakeEdge(aCircle, aStart, anEnd);
 
   anEdgeBuilder.Build();
 
index c2ad49c1c5b49f00d30f269a5d51922464d9d5d2..7e85bce2e5fcdb2eb7e80761627ee2b89510ce6e 100644 (file)
@@ -48,7 +48,7 @@ ObjectPtr ModuleBase_WidgetValidated::findPresentedObject(const AISObjectPtr& th
 void ModuleBase_WidgetValidated::clearValidatedCash()
 {
 #ifdef DEBUG_VALID_STATE
-  qDebug("clearValidatedState");
+  qDebug("clearValidatedCash");
 #endif
   myValidPrs.clear();
   myInvalidPrs.clear();
index 330b4c468caac1b30ee4fd8e5e1fcffc59227032..191a277ee8f41f0ff91273ed12200cc89fcb07fb 100755 (executable)
@@ -20,17 +20,14 @@ ModuleBase_WidgetValidator::~ModuleBase_WidgetValidator()
 //********************************************************************
 bool ModuleBase_WidgetValidator::isValidSelection(const ModuleBase_ViewerPrsPtr& theValue)
 {
-  return myModelWidget->isValidSelectionCustom(theValue);
-}
+  bool aValid = false;
+  if (getValidState(theValue, aValid))
+    return aValid;
 
-bool ModuleBase_WidgetValidator::isFilterActivated() const
-{
-  bool isActivated = false;
+  aValid = myModelWidget->isValidSelectionCustom(theValue);
 
-  Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
-  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
-
-  return aViewer->hasSelectionFilter(aSelFilter);
+  storeValidState(theValue, aValid);
+  return aValid;
 }
 
 bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
@@ -44,8 +41,63 @@ bool ModuleBase_WidgetValidator::activateFilters(const bool toActivate)
     aViewer->addSelectionFilter(aSelFilter);
   else {
     aViewer->removeSelectionFilter(aSelFilter);
-    //clearValidatedCash();
+    clearValidatedCash();
   }
 
   return aHasSelectionFilter;
 }
+
+bool ModuleBase_WidgetValidator::isFilterActivated() const
+{
+  bool isActivated = false;
+
+  Handle(SelectMgr_Filter) aSelFilter = myWorkshop->validatorFilter();
+  ModuleBase_IViewer* aViewer = myWorkshop->viewer();
+
+  return aViewer->hasSelectionFilter(aSelFilter);
+}
+
+void ModuleBase_WidgetValidator::clearValidatedCash()
+{
+  myValidPrs.clear();
+  myInvalidPrs.clear();
+}
+
+bool ModuleBase_WidgetValidator::getValidState(const ModuleBase_ViewerPrsPtr& theValue, bool& theValid)
+{
+  bool aValidPrs = myValidPrs.contains(theValue);
+  bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+  if (aValidPrs)
+    theValid = true;
+  else if (anInvalidPrs)
+    theValid = false;
+
+  return aValidPrs || anInvalidPrs;
+}
+
+//********************************************************************
+void ModuleBase_WidgetValidator::storeValidState(const ModuleBase_ViewerPrsPtr& theValue, const bool theValid)
+{
+  bool aValidPrs = myInvalidPrs.contains(theValue);
+  bool anInvalidPrs = myInvalidPrs.contains(theValue);
+
+  if (theValid) {
+    if (!aValidPrs)
+      myValidPrs.append(theValue);
+    // the commented code will be useful when the valid state of the presentation
+    // will be changable between activate/deactivate. Currently it does not happen.
+    //if (anInvalidPrs)
+    //  myInvalidPrs.removeOne(theValue);
+  }
+  else { // !theValid
+    if (!anInvalidPrs)
+      myInvalidPrs.append(theValue);
+    //if (!aValidPrs)
+    //  myValidPrs.removeOne(theValue);
+  }
+#ifdef DEBUG_VALID_STATE
+  qDebug(QString("storeValidState: myValidPrs.size() = %1, myInvalidPrs.size() = %2").arg(myValidPrs.count())
+                 .arg(myInvalidPrs.count()).toStdString().c_str());
+#endif
+}
index 942e9bc931153aa0744e1b8f0b4b4e29c03e9ea1..ead80e794c0cce62503e7242e6ee24ad2b121ed7 100755 (executable)
@@ -10,6 +10,7 @@
 
 #include <ModuleBase.h>
 
+#include <QList>
 #include <memory>
 
 class ModuleBase_ModelWidget;
@@ -48,10 +49,26 @@ private:
   /// \return boolean value
   bool isFilterActivated() const;
 
+  //! Clear all validated cash in the widget
+  void clearValidatedCash();
+
+  /// Gets the validity state of the presentation in an internal map. Returns true if the valid state of value is stored
+  /// \param theValue a viewer presentation
+  /// \param theValid a valid state
+  bool getValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, bool& theValid);
+
+  /// Store the validity state of the presentation in an internal map
+  /// \param theValue a viewer presentation
+  /// \param theValid a valid state
+  void storeValidState(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue, const bool theValid);
+
 protected:
   /// Reference to workshop
   ModuleBase_ModelWidget* myModelWidget; ///< the current widget to be validated
   ModuleBase_IWorkshop* myWorkshop; ///< the active workshop
+
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myValidPrs; /// cash of valid selection presentations
+  QList<std::shared_ptr<ModuleBase_ViewerPrs>> myInvalidPrs; /// cash of invalid selection presentations
 };
 
 #endif /* ModuleBase_WidgetValidator_H_ */
index a2c0245033bddbf26d787e7d2d61bba0607907e8..f259ca6afae5da9a9c325053890d4960c92c67ff 100644 (file)
@@ -7,6 +7,7 @@
 #include "PartSet_WidgetPoint2d.h"
 #include <PartSet_Tools.h>
 #include <PartSet_Module.h>
+#include <PartSet_SketcherReetntrantMgr.h>
 
 #include <XGUI_Tools.h>
 #include <XGUI_Workshop.h>
@@ -33,6 +34,9 @@
 #include <GeomDataAPI_Point2D.h>
 #include <GeomAPI_Pnt2d.h>
 
+#include <GeomAPI_ShapeExplorer.h>
+#include <GeomAPI_Vertex.h>
+
 #include <SketchPlugin_Feature.h>
 #include <SketchPlugin_ConstraintCoincidence.h>
 #include <SketchPlugin_Line.h>
@@ -124,15 +128,51 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
 bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
 {
   bool aValid = true;
-  /*if (getValidState(theValue, aValid)) {
-    return aValid;
-  }
-  aValid = isValidSelectionCustom(theValue);
-  if (aValid)
-    aValid = isValidSelectionForAttribute(theValue, attribute());
 
-  storeValidState(theValue, aValid);
-  */return aValid;
+  PartSet_Module* aModule = dynamic_cast<PartSet_Module*>(myWorkshop->module());
+  if (aModule->sketchReentranceMgr()->isInternalEditActive()) 
+    return true; /// when internal edit is started a new feature is created. I has not results, AIS
+
+  // workaround for feature, where there is no results
+  //if (myFeature->getKind() == "SketchRectangle")
+  //  return true;
+
+  /// the selection is not possible if the current feature has no presentation for the current
+  /// attribute not in AIS not in results. If so, no object in current feature where make
+  /// coincidence, so selection is not necessary
+  std::shared_ptr<ModelAPI_Data> aData = myFeature->data();
+  std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+      aData->attribute(attributeID()));
+  std::shared_ptr<GeomAPI_Pnt2d> aPoint = aPointAttr->pnt();
+
+  bool aFoundPoint = false;
+  GeomShapePtr anAISShape;
+  GeomPresentablePtr aPrs = std::dynamic_pointer_cast<GeomAPI_IPresentable>(myFeature);
+  if (aPrs.get()) {
+    AISObjectPtr anAIS;
+    anAIS = aPrs->getAISObject(anAIS);
+    if (anAIS.get()) {
+      anAISShape = anAIS->getShape();
+    }
+  }
+  const std::list<std::shared_ptr<ModelAPI_Result> >& aResults = myFeature->results();
+  if (!anAISShape.get() && aResults.empty())
+    return true;
+
+  /// analysis of AIS
+  if (anAISShape.get())
+    aFoundPoint = shapeContainsPoint(anAISShape, aPoint, mySketch);
+
+  /// analysis of results
+  std::list<std::shared_ptr<ModelAPI_Result> >::const_iterator aRIter = aResults.cbegin();
+  for (; aRIter != aResults.cend() && !aFoundPoint; aRIter++) {
+    ResultPtr aResult = *aRIter;
+    if (aResult.get() && aResult->shape().get()) {
+      GeomShapePtr aShape = aResult->shape();
+      aFoundPoint = shapeContainsPoint(aShape, aPoint, mySketch);
+    }
+  }
+  return aFoundPoint;
 }
 
 bool PartSet_WidgetPoint2D::resetCustom()
@@ -450,14 +490,22 @@ void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMous
 
   ModuleBase_ISelection* aSelection = myWorkshop->selection();
   Handle(V3d_View) aView = theWnd->v3dView();
-  // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
-  NCollection_List<TopoDS_Shape> aShapes;
-  std::list<ObjectPtr> aObjects;
-  aSelection->selectedShapes(aShapes, aObjects);
+
+  QList<ModuleBase_ViewerPrsPtr> aList = aSelection->getSelected(ModuleBase_ISelection::Viewer);
+  ModuleBase_ViewerPrsPtr aFirstValue = aList.size() > 0 ? aList.first() : ModuleBase_ViewerPrsPtr();
+  //NCollection_List<TopoDS_Shape> aShapes;
+  //std::list<ObjectPtr> aObjects;
+  //aSelection->selectedShapes(aShapes, aObjects);
   // if we have selection and use it
-  if (aShapes.Extent() > 0 && useSelectedShapes()) {
-    TopoDS_Shape aShape = aShapes.First();
-    ObjectPtr aObject = aObjects.front();
+  //if (/*aShapes.Extent() > 0 && useSelectedShapes() &&*/ isValidSelectionCustom() {
+  if (aFirstValue.get() && isValidSelectionCustom(aFirstValue)) {
+    //TopoDS_Shape aShape = aShapes.First();
+    //ObjectPtr aObject = aObjects.front();
+
+    GeomShapePtr aGeomShape = aFirstValue->shape();
+    TopoDS_Shape aShape = aGeomShape->impl<TopoDS_Shape>(); /// to find axis shape
+    ObjectPtr aObject = aFirstValue->object(); /// to find owner
+
     FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(aObject);
     bool anExternal = false;
     std::shared_ptr<SketchPlugin_Feature> aSPFeature;
@@ -714,3 +762,20 @@ bool PartSet_WidgetPoint2D::isOrphanPoint(const FeaturePtr& theFeature,
   }
   return anOrphanPoint;
 }
+
+bool PartSet_WidgetPoint2D::shapeContainsPoint(const GeomShapePtr& theShape,
+                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
+                                               const CompositeFeaturePtr& theSketch)
+{
+  std::shared_ptr<GeomAPI_Pnt> aPoint = PartSet_Tools::point3D(thePoint, theSketch);
+
+  bool aContainPoint = false;
+  GeomAPI_ShapeExplorer anExp(theShape, GeomAPI_Shape::VERTEX);
+  for(; anExp.more() && !aContainPoint; anExp.next()) {
+    std::shared_ptr<GeomAPI_Shape> aVertexInCompSolid = anExp.current();
+    std::shared_ptr<GeomAPI_Vertex> aVertex(new GeomAPI_Vertex(aVertexInCompSolid));
+    if (aVertex.get())
+      aContainPoint = aPoint->isEqual(aVertex->point());
+  }
+  return aContainPoint;
+}
index 449b890f3686df3db718150784a9c8b01c9ad1d2..b04dfc776f7cf185e7f11d7c259052c40196fed7 100755 (executable)
@@ -182,6 +182,14 @@ protected:
    static bool isOrphanPoint(const FeaturePtr& theFeature, const CompositeFeaturePtr& theSketch,
                              double theX, double theY);
 
+   /// Explode the given shape by vertices and found closed to the point vertes
+   /// \param theShape a shape to be exploded
+   /// \param thePoint a point
+   /// \return boolean value
+   static bool shapeContainsPoint(const std::shared_ptr<GeomAPI_Shape>& theShape,
+                                  const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
+                                  const CompositeFeaturePtr& theSketch);
+
 protected:
   ModuleBase_IWorkshop* myWorkshop; ///< workshop
 
index f6d4ec763d7de07ff1e6204c5e3898d457c1a808..365fcb7afc2cfadaa9b3eb56c6a385548672b866 100644 (file)
@@ -219,8 +219,13 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
       // compute a circle point in 3D view
       std::shared_ptr<GeomDataAPI_Point2D> aCenterAttr = std::dynamic_pointer_cast<
           GeomDataAPI_Point2D>(data()->attribute(CENTER_ID()));
+
+      std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
       if (aCenterAttr->isInitialized()) {
         std::shared_ptr<GeomAPI_Pnt> aCenter(aSketch->to3D(aCenterAttr->x(), aCenterAttr->y()));
+        // make a visible point
+        std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
+        aShapes.push_back(aCenterPointShape);
 
         std::shared_ptr<GeomDataAPI_Point2D> aStartAttr = std::dynamic_pointer_cast<
             GeomDataAPI_Point2D>(data()->attribute(SketchPlugin_Arc::START_ID()));
@@ -242,28 +247,22 @@ AISObjectPtr SketchPlugin_Arc::getAISObject(AISObjectPtr thePrevious)
                 aTypeAttr->value() == ARC_TYPE_THREE_POINTS() && aEndAttr->isInitialized())
               aEndPoint = aSketch->to3D(aEndAttr->x(), aEndAttr->y());
 
-            std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
-            // make a visible point
-            std::shared_ptr<GeomAPI_Shape> aCenterPointShape = GeomAlgoAPI_PointBuilder::point(aCenter);
-            aShapes.push_back(aCenterPointShape);
-
             std::shared_ptr<GeomAPI_Shape> aCircleShape = GeomAlgoAPI_EdgeBuilder::lineCircleArc(
                                                             aCenter, aStartPoint, aEndPoint, aNormal);
             if (aCircleShape)
               aShapes.push_back(aCircleShape);
-
-            if (!aShapes.empty()) {
-              std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
-              AISObjectPtr anAIS = thePrevious;
-              if (!anAIS)
-                anAIS = AISObjectPtr(new GeomAPI_AISObject);
-              anAIS->createShape(aCompound);
-              anAIS->setWidth(3);
-              return anAIS;
-            }
           }
         }
       }
+      if (!aShapes.empty()) {
+        std::shared_ptr<GeomAPI_Shape> aCompound = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+        AISObjectPtr anAIS = thePrevious;
+        if (!anAIS)
+          anAIS = AISObjectPtr(new GeomAPI_AISObject);
+        anAIS->createShape(aCompound);
+        anAIS->setWidth(3);
+        return anAIS;
+      }
     }
   }
   return AISObjectPtr();