Salome HOME
Issue #2325 impossible to select center of cylinder in sketch
authornds <nds@opencascade.com>
Thu, 7 Dec 2017 08:57:59 +0000 (11:57 +0300)
committernds <nds@opencascade.com>
Thu, 7 Dec 2017 08:57:59 +0000 (11:57 +0300)
src/PartSet/PartSet_ExternalObjectsMgr.cpp
src/PartSet/PartSet_ExternalObjectsMgr.h
src/PartSet/PartSet_Tools.cpp
src/PartSet/PartSet_Tools.h
src/PartSet/PartSet_WidgetMultiSelector.cpp
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetShapeSelector.cpp

index 793940ccab1e13b733d4cef8ba3c6ab6a40a1d2d..d2df7c96db9bc2c761e8249b0bb72736a6c45a6c 100755 (executable)
@@ -19,6 +19,8 @@
 //
 
 #include "PartSet_ExternalObjectsMgr.h"
+
+#include "PartSet_CenterPrs.h"
 #include "PartSet_Tools.h"
 
 #include <XGUI_Workshop.h>
@@ -83,12 +85,40 @@ ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelecte
   return aSelectedObject;
 }
 
+ObjectPtr PartSet_ExternalObjectsMgr::externalCenterObject(const ModuleBase_ViewerPrsPtr& thePrs,
+                                                           const CompositeFeaturePtr& theSketch,
+                                                           const bool theTemporary)
+{
+  if (!thePrs.get() || thePrs->interactive().IsNull())
+    return ObjectPtr();
+
+  Handle(PartSet_CenterPrs) aAIS = Handle(PartSet_CenterPrs)::DownCast(thePrs->interactive());
+  if (aAIS.IsNull())
+    return ObjectPtr();
+
+  gp_Pnt aPntComp = aAIS->Component()->Pnt();
+  GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z()));
+  TopoDS_Shape aShape = aVertPtr->impl<TopoDS_Shape>();
+
+  ResultPtr aSelectedObject =
+    PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), theSketch);
+  if (!aSelectedObject.get())
+  {
+    FeaturePtr aCreatedFeature;
+    aSelectedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(),
+      aAIS->centerType(), theSketch, theTemporary, aCreatedFeature);
+    if (aCreatedFeature.get() && theTemporary)
+        myExternalObjectValidated = aCreatedFeature;
+  }
+  return aSelectedObject;
+}
+
 void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
-                                                   ObjectPtr& theObject,
-                                                   GeomShapePtr& theShape,
-                                                   ModuleBase_IWorkshop* theWorkshop,
-                                                   const CompositeFeaturePtr& theSketch,
-                                                   const bool isInValidate)
+                                                  ObjectPtr& theObject,
+                                                  GeomShapePtr& theShape,
+                                                  ModuleBase_IWorkshop* theWorkshop,
+                                                  const CompositeFeaturePtr& theSketch,
+                                                  const bool isInValidate)
 {
   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
   std::shared_ptr<SketchPlugin_Feature> aSPFeature =
@@ -110,6 +140,9 @@ void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr&
         if (aShape.get() != NULL && !aShape->isNull())
           anExternalObject =
             externalObject(theObject, aShape, theSketch, isInValidate);
+        if (!anExternalObject.get()) {
+          anExternalObject = externalCenterObject(thePrs, theSketch, isInValidate);
+        }
       }
       else { /// use objects of found selection
         anExternalObject = theObject;
index d506047e75ac185ba235c8a63a61b11a3757ec9c..59d0141584376fcebb1bc2e3132782859e4473ef 100755 (executable)
@@ -74,6 +74,15 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr
   ObjectPtr externalObject(const ObjectPtr& theSelectedObject, const GeomShapePtr& theShape,
                            const CompositeFeaturePtr& theSketch, const bool theTemporary = false);
 
+  /// Finds or create and external object by selected circle center (PartSet_CenterPrs)
+  /// \param thePrs a selection
+  /// \param theSketch a current sketch
+  /// \param theTemporary the created external object is temporary, execute is not performed for it
+  /// \return the object
+  ObjectPtr externalCenterObject(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
+                                 const CompositeFeaturePtr& theSketch,
+                                 const bool theTemporary);
+
   // Removes the external presentation from the model
   /// \param theSketch a current sketch
   /// \param theFeature a current feature
index dac76b8e98286ecada62e6c7adf612516a757e53..2d32f553e341349d33808337ca0eb7f4c8e763fc 100755 (executable)
@@ -686,13 +686,15 @@ ResultPtr PartSet_Tools::createFixedByExternalCenter(
     const std::shared_ptr<GeomAPI_Edge>& theEdge,
     ModelAPI_AttributeSelection::CenterType theType,
     const CompositeFeaturePtr& theSketch,
-    bool theTemporary)
+    bool theTemporary,
+    FeaturePtr& theCreatedFeature)
 {
   ResultPtr aResult = std::dynamic_pointer_cast<ModelAPI_Result>(theObject);
   if (!aResult.get())
     return ResultPtr();
 
   FeaturePtr aProjectionFeature = theSketch->addFeature(SketchPlugin_Projection::ID());
+  theCreatedFeature = aProjectionFeature;
   AttributeSelectionPtr anExternalAttr = std::dynamic_pointer_cast<ModelAPI_AttributeSelection>(
                  aProjectionFeature->attribute(SketchPlugin_Projection::EXTERNAL_FEATURE_ID()));
   anExternalAttr->setValueCenter(aResult, theEdge, theType, theTemporary);
index 1a8beb6703ecde71c7df961411e7d564707e934b..1f5bf51b12ae1b4c36a5e8d4a91a80660e42fea1 100755 (executable)
@@ -283,7 +283,8 @@ public:
                                                const std::shared_ptr<GeomAPI_Edge>& theEdge,
                                                ModelAPI_AttributeSelection::CenterType theType,
                                                const CompositeFeaturePtr& theSketch,
-                                               bool theTemporary = false);
+                                               bool theTemporary,
+                                               FeaturePtr& theCreatedFeature);
 
 };
 
index a858357346f58fb1e5697f9c00d35d23e677e00a..b552e9376f82709b4d0b9ab4f72fb4b76f8e410b 100755 (executable)
@@ -34,6 +34,7 @@
 
 #include <Config_WidgetAPI.h>
 
+#include <PartSet_CenterPrs.h>
 #include <PartSet_Tools.h>
 #include <PartSet_ExternalObjectsMgr.h>
 #include <SketchPlugin_Feature.h>
@@ -61,7 +62,12 @@ PartSet_WidgetMultiSelector::~PartSet_WidgetMultiSelector()
 //********************************************************************
 bool PartSet_WidgetMultiSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
 {
-  bool aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
+  bool aValid = false;
+  if (thePrs.get() && thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs)))
+    aValid = true; // we should not check acceptSubShape for such presentation
+  else
+    aValid = ModuleBase_WidgetMultiSelector::isValidSelectionCustom(thePrs);
+
   if (aValid) {
     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
     aValid = myExternalObjectMgr->isValidObject(anObject);
index 37d9fb01599b1bef5cfcb10f85d3e9520247a064..0514fe7bb0a4af70000e3ac26bc60be6a44d3893 100644 (file)
@@ -726,8 +726,11 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
       ResultPtr aFixedObject =
           PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), mySketch);
       if (!aFixedObject.get())
+      {
+        FeaturePtr aCreatedFeature;
         aFixedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(),
-                                                                  aAIS->centerType(), mySketch);
+          aAIS->centerType(), mySketch, false, aCreatedFeature);
+      }
       if (aFixedObject.get())
         setConstraintToObject(aFixedObject);
       // fignal updated should be flushed in order to visualize possible created
index ead2a719aab71e133fe8ea75ac919d9eeca000c6..056ca9dd6ea1d770a31e21b44961c7723b305cb4 100755 (executable)
@@ -19,6 +19,8 @@
 //
 
 #include "PartSet_WidgetShapeSelector.h"
+
+#include "PartSet_CenterPrs.h"
 #include "PartSet_Module.h"
 #include "PartSet_SketcherMgr.h"
 
@@ -74,7 +76,12 @@ bool PartSet_WidgetShapeSelector::activateSelectionAndFilters(bool toActivate)
 //********************************************************************
 bool PartSet_WidgetShapeSelector::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
 {
-  bool aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
+  bool aValid = false;
+  if (thePrs.get() && thePrs->interactive()->IsKind(STANDARD_TYPE(PartSet_CenterPrs)))
+    aValid = true; // we should not check acceptSubShape for such presentation
+  else
+    aValid = ModuleBase_WidgetShapeSelector::isValidSelectionCustom(thePrs);
+
   if (aValid) {
     ObjectPtr anObject = myWorkshop->selection()->getResult(thePrs);
     aValid = myExternalObjectMgr->isValidObject(anObject);