]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #2120 - Crash when creating an arc passing through the arc connected to both...
authornds <nds@opencascade.com>
Wed, 12 Apr 2017 10:03:42 +0000 (13:03 +0300)
committernds <nds@opencascade.com>
Wed, 12 Apr 2017 10:03:59 +0000 (13:03 +0300)
src/PartSet/PartSet_ExternalObjectsMgr.cpp
src/PartSet/PartSet_ExternalObjectsMgr.h
src/PartSet/PartSet_WidgetPoint2d.cpp
src/PartSet/PartSet_WidgetPoint2d.h
src/PartSet/PartSet_WidgetShapeSelector.cpp

index 2c8ac1d08880d41f2e62c96411ee7aeeb74dd75f..bc0412047a433984eea80cc684ffd4624fc4a983 100755 (executable)
@@ -10,6 +10,9 @@
 #include <XGUI_Workshop.h>
 #include <XGUI_ModuleConnector.h>
 
+#include <ModuleBase_ViewerPrs.h>
+#include <ModuleBase_ISelection.h>
+
 #include <SketchPlugin_Feature.h>
 
 #include <QString>
@@ -75,6 +78,46 @@ ObjectPtr PartSet_ExternalObjectsMgr::externalObject(const ObjectPtr& theSelecte
   return aSelectedObject;
 }
 
+void PartSet_ExternalObjectsMgr::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
+                                                   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 =
+          std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
+  // there is no a sketch feature is selected, but the shape exists,
+  // try to create an exernal object
+  // TODO: unite with the same functionality in PartSet_WidgetShapeSelector
+  if (aSPFeature.get() == NULL) {
+    ObjectPtr anExternalObject = ObjectPtr();
+    GeomShapePtr anExternalShape = GeomShapePtr();
+    if (useExternal()) {
+      if (canCreateExternal()) {
+        GeomShapePtr aShape = theShape;
+        if (!aShape.get()) {
+          ResultPtr aResult = theWorkshop->selection()->getResult(thePrs);
+          if (aResult.get())
+            aShape = aResult->shape();
+        }
+        if (aShape.get() != NULL && !aShape->isNull())
+          anExternalObject =
+            externalObject(theObject, aShape, theSketch, isInValidate);
+      }
+      else { /// use objects of found selection
+        anExternalObject = theObject;
+        anExternalShape = theShape;
+      }
+    }
+    /// the object is null if the selected feature is "external"(not sketch entity feature of the
+    /// current sketch) and it is not created by object manager
+    theObject = anExternalObject;
+    theShape = anExternalShape;
+  }
+}
+
 //********************************************************************
 void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSketch,
                                                 const FeaturePtr& theFeature,
index 4cc3696da8008aa11a2dc74ba36ef840544d4ccb..f403f88a4589b875034f3efd4e3c537a0087a3d3 100755 (executable)
@@ -19,6 +19,7 @@
 #include <string>
 
 class ModuleBase_IWorkshop;
+class ModuleBase_ViewerPrs;
 class XGUI_Workshop;
 
 /**
@@ -70,6 +71,17 @@ class PARTSET_EXPORT PartSet_ExternalObjectsMgr
                       ModuleBase_IWorkshop* theWorkshop,
                       const bool theTemporary);
 
+  /// Return an object and geom shape by the viewer presentation
+  /// \param thePrs a selection
+  /// \param theObject an output object
+  /// \param theShape a shape of the selection
+  virtual void getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs,
+                                ObjectPtr& theObject,
+                                GeomShapePtr& theShape,
+                                ModuleBase_IWorkshop* theWorkshop,
+                                const CompositeFeaturePtr& theSketch,
+                                const bool isInValidate);
+
 protected:
   /// Delete from the document the feature of the object. It deletes all objects, which refers to
   /// the deleted one. The parameter feature is ignored even it refer to the deleted object.
index c81d84b967c594edec5c681a2a1963c599f600d6..ceb12eff04c64c8767666493eedfb52fb7c56e9c 100644 (file)
@@ -8,6 +8,7 @@
 #include <PartSet_Tools.h>
 #include <PartSet_Module.h>
 #include <PartSet_SketcherReentrantMgr.h>
+#include <PartSet_ExternalObjectsMgr.h>
 
 #include <XGUI_Tools.h>
 #include <XGUI_Workshop.h>
@@ -133,6 +134,8 @@ PartSet_WidgetPoint2D::PartSet_WidgetPoint2D(QWidget* theParent,
   setLayout(aLayout);
 
   myWidgetValidator = new ModuleBase_WidgetValidator(this, myWorkshop);
+  myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
+                                         theData->getProperty("can_create_external"), true);
 }
 
 bool PartSet_WidgetPoint2D::isValidSelectionCustom(const ModuleBase_ViewerPrsPtr& theValue)
@@ -212,6 +215,7 @@ bool PartSet_WidgetPoint2D::isValidSelectionForAttribute_(
 
   // restores the current values of the widget attribute
   myWidgetValidator->restoreAttributeValue(aRefAttr, aValid);
+  myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
 
   ModuleBase_WidgetValidated::blockFeatureAttribute(aRefAttr, myFeature, false, isFlushesActived,
                                 isAttributeSetInitializedBlocked, isAttributeSendUpdatedBlocked);
@@ -227,11 +231,11 @@ bool PartSet_WidgetPoint2D::setSelectionCustom(const ModuleBase_ViewerPrsPtr& th
     double aX, aY;
     const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
     if (getPoint2d(aView, aTDShape, aX, aY)) {
-      fillRefAttribute(aX, aY);
+      fillRefAttribute(aX, aY, theValue);
       isDone = true;
     }
     else if (aTDShape.ShapeType() == TopAbs_EDGE) {
-      fillRefAttribute(theValue->object());
+      fillRefAttribute(theValue);
       isDone = true;
     }
   }
@@ -271,6 +275,7 @@ bool PartSet_WidgetPoint2D::resetCustom()
 
 PartSet_WidgetPoint2D::~PartSet_WidgetPoint2D()
 {
+  delete myExternalObjectMgr;
 }
 
 bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValues,
@@ -290,7 +295,7 @@ bool PartSet_WidgetPoint2D::setSelection(QList<ModuleBase_ViewerPrsPtr>& theValu
       const TopoDS_Shape& aTDShape = aShape->impl<TopoDS_Shape>();
       if (getPoint2d(aView, aTDShape, aX, aY)) {
         isDone = setPoint(aX, aY);
-        setConstraintToPoint(aX, aY);
+        setConstraintToPoint(aX, aY, aValue);
       }
     }
   }
@@ -458,11 +463,12 @@ bool PartSet_WidgetPoint2D::getPoint2d(const Handle(V3d_View)& theView,
   return false;
 }
 
-bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY)
+bool PartSet_WidgetPoint2D::setConstraintToPoint(double theClickedX, double theClickedY,
+                                  const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
 {
   AttributeRefAttrPtr aRefAttr = attributeRefAttr();
   if (aRefAttr.get())
-    fillRefAttribute(theClickedX, theClickedY);
+    fillRefAttribute(theClickedX, theClickedY, theValue);
   else {
     FeaturePtr aFeature = feature();
     std::string anAttribute = attributeID();
@@ -647,7 +653,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo
         bool isAuxiliaryFeature = false;
         if (getPoint2d(aView, aShape, aX, aY)) {
           setPoint(aX, aY);
-          setConstraintToPoint(aX, aY);
+          setConstraintToPoint(aX, aY, aFirstValue);
         }
         else if (aShape.ShapeType() == TopAbs_EDGE) {
           // point is taken from mouse event and set in attribute. It should be done before setting
@@ -869,7 +875,8 @@ AttributeRefAttrPtr PartSet_WidgetPoint2D::attributeRefAttr() const
   return std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttributeRef);
 }
 
-void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY)
+void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClickedY,
+                              const std::shared_ptr<ModuleBase_ViewerPrs>& theValue)
 {
   AttributeRefAttrPtr aRefAttr = attributeRefAttr();
   if (!aRefAttr.get())
@@ -885,9 +892,19 @@ void PartSet_WidgetPoint2D::fillRefAttribute(double theClickedX, double theClick
                                                             aFeature, aClickedPoint);
     if (aClickedFeaturePoint.get())
       aRefAttr->setAttr(aClickedFeaturePoint);
+    else {
+      ObjectPtr anObject = getGeomSelection(theValue);
+      if (anObject.get())
+        aRefAttr->setObject(anObject);
+    }
   }
 }
 
+void PartSet_WidgetPoint2D::fillRefAttribute(const ModuleBase_ViewerPrsPtr& theValue)
+{
+  fillRefAttribute(getGeomSelection(theValue));
+}
+
 void PartSet_WidgetPoint2D::fillRefAttribute(const ObjectPtr& theObject)
 {
   AttributeRefAttrPtr aRefAttr = attributeRefAttr();
@@ -972,3 +989,15 @@ std::shared_ptr<GeomDataAPI_Point2D> PartSet_WidgetPoint2D::findFirstEqualPointI
   }
   return aFPoint;
 }
+
+ObjectPtr PartSet_WidgetPoint2D::getGeomSelection(const ModuleBase_ViewerPrsPtr& theValue)
+{
+  ObjectPtr anObject;
+  GeomShapePtr aShape;
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  anObject = aSelection->getResult(theValue);
+  aShape = aSelection->getShape(theValue);
+  myExternalObjectMgr->getGeomSelection(theValue, anObject, aShape, myWorkshop, sketch(), true);
+
+  return anObject;
+}
index 45841941a594763e780f0641c437ba1e56d4f567..06b8e4a3771b6180909f003f7a8902e15fe9ef9f 100755 (executable)
@@ -25,6 +25,7 @@ class ModuleBase_IWorkshop;
 class ModuleBase_ParamSpinBox;
 class ModuleBase_IViewWindow;
 class ModuleBase_LabelValue;
+class PartSet_ExternalObjectsMgr;
 class GeomAPI_Pnt2d;
 class ModuleBase_IWorkshop;
 
@@ -191,7 +192,8 @@ protected:
    /// Creates constrains of the clicked point
    /// \param theClickedX the horizontal coordnate of the point
    /// \param theClickedY the vertical coordnate of the point
-   bool setConstraintToPoint(double theClickedX, double theClickedY);
+   bool setConstraintToPoint(double theClickedX, double theClickedY,
+                             const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
 
    /// Create a coincidence constraint between the attribute and the parameter object
    /// \theObject a result object
@@ -249,9 +251,13 @@ protected:
   /// Finds first equal point attribute in sketch and set it to reference attribute
   /// \param theClickedX the horizontal coordnate of the point
   /// \param theClickedY the vertical coordnate of the point
-  void fillRefAttribute(double theClickedX, double theClickedY);
+  void fillRefAttribute(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+  void fillRefAttribute(double theClickedX, double theClickedY,
+                        const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
   void fillRefAttribute(const ObjectPtr& theObject);
 
+  ObjectPtr getGeomSelection(const std::shared_ptr<ModuleBase_ViewerPrs>& theValue);
+
 protected:
   ModuleBase_IWorkshop* myWorkshop; ///< workshop
 
@@ -261,6 +267,7 @@ private:
   //ModuleBase_ParamSpinBox* myYSpin;  ///< the spin box for the Y coordinate
   ModuleBase_LabelValue* myXSpin; ///< the label for the X coordinate
   ModuleBase_LabelValue* myYSpin; ///< the label for the Y coordinate
+  PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
 
   /// value used as selection in mouse release method
   std::shared_ptr<ModuleBase_ViewerPrs> myPreSelected;
index 472b122e829813972c40327f8bc6bb3ccef2099b..14444e9da8d6f93873fd1fe2aab4ff1b7cf28561 100755 (executable)
@@ -74,6 +74,9 @@ void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr
 {
   ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
 
+  myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
+                                        myWorkshop, sketch(), myIsInValidate);
+  /*
   FeaturePtr aSelectedFeature = ModelAPI_Feature::feature(theObject);
   std::shared_ptr<SketchPlugin_Feature> aSPFeature =
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aSelectedFeature);
@@ -104,7 +107,7 @@ void PartSet_WidgetShapeSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr
     /// current sketch) and it is not created by object manager
     theObject = anExternalObject;
     theShape = anExternalShape;
-  }
+  }*/
 }
 
 //********************************************************************