]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Issue #18429: Provide selection of external objects for angle constraint.
authorvsv <vsv@opencascade.com>
Mon, 16 Dec 2019 16:09:21 +0000 (19:09 +0300)
committervsv <vsv@opencascade.com>
Mon, 16 Dec 2019 16:09:21 +0000 (19:09 +0300)
src/PartSet/PartSet_WidgetFeaturePointSelector.cpp
src/PartSet/PartSet_WidgetFeaturePointSelector.h

index 7b5aff07db9500f3c91859e0433dc260a255222c..173e146271b82ad4b76398464f417f558ea438de 100644 (file)
 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
+#include "PartSet_WidgetFeaturePointSelector.h"
+#include "PartSet_Tools.h"
+#include "PartSet_ExternalObjectsMgr.h"
+
 #include <Config_WidgetAPI.h>
 
 #include <Events_Loop.h>
@@ -40,9 +44,6 @@
 #include <ModuleBase_IWorkshop.h>
 #include <ModuleBase_IModule.h>
 
-#include "PartSet_WidgetFeaturePointSelector.h"
-#include "PartSet_Tools.h"
-
 #include <SketchPlugin_Point.h>
 
 #include <XGUI_Tools.h>
@@ -75,10 +76,13 @@ PartSet_WidgetFeaturePointSelector::PartSet_WidgetFeaturePointSelector(QWidget*
     myPreviewObjectAttribute = anAttributesList[2].toStdString();
     myPreviewPointAttribute = anAttributesList[3].toStdString();
   }
+  myExternalObjectMgr = new PartSet_ExternalObjectsMgr(theData->getProperty("use_external"),
+    theData->getProperty("can_create_external"), true);
 }
 
 PartSet_WidgetFeaturePointSelector::~PartSet_WidgetFeaturePointSelector()
 {
+  delete myExternalObjectMgr;
 }
 
 //********************************************************************
@@ -155,6 +159,19 @@ void PartSet_WidgetFeaturePointSelector::mouseReleased(ModuleBase_IViewWindow* t
   if (theEvent->button() != Qt::LeftButton)
     return;
 
+  ModuleBase_ISelection* aSelection = myWorkshop->selection();
+  QList<ModuleBase_ViewerPrsPtr> aSelected = aSelection->getSelected(ModuleBase_ISelection::Viewer);
+
+  ModuleBase_ViewerPrsPtr aPrs =
+    !aSelected.empty() ? aSelected.first() : ModuleBase_ViewerPrsPtr();
+  if (aPrs.get() && aPrs->object().get()) {
+    myPreviewObject = aSelection->getResult(aPrs);
+    GeomShapePtr aShape = aSelection->getShape(aPrs);
+    myExternalObjectMgr->getGeomSelection(aPrs, myPreviewObject, aShape,
+      myWorkshop, sketch(), true);
+  }
+  myPreviewPoint = PartSet_Tools::getPnt2d(theEvent, theWindow, mySketch);
+
   ObjectPtr aPreviewObject;
   GeomPnt2dPtr aPreviewPoint;
   if (myHasPreview) {
@@ -261,3 +278,23 @@ void PartSet_WidgetFeaturePointSelector::setPreSelection(
   // sub-segments in the viewer, secondly preselection of restart operation is processed by
   // special reentrant message sent by the feature
 }
+
+//********************************************************************
+void PartSet_WidgetFeaturePointSelector::getGeomSelection(const ModuleBase_ViewerPrsPtr& thePrs,
+  ObjectPtr& theObject, GeomShapePtr& theShape)
+{
+  ModuleBase_WidgetShapeSelector::getGeomSelection(thePrs, theObject, theShape);
+
+  myExternalObjectMgr->getGeomSelection(thePrs, theObject, theShape,
+    myWorkshop, sketch(), myIsInValidate);
+  myPreviewObject = theObject;
+}
+
+//********************************************************************
+void PartSet_WidgetFeaturePointSelector::restoreAttributeValue(const AttributePtr& theAttribute,
+  const bool theValid)
+{
+  ModuleBase_WidgetShapeSelector::restoreAttributeValue(theAttribute, theValid);
+  myExternalObjectMgr->removeExternal(sketch(), myFeature, myWorkshop, true);
+  myPreviewObject = ObjectPtr();
+}
index 972b30ede1e581a4ac69090b2e3aa3a25fd2fe83..445303133b239d8f484161de12757ef7dee54b72 100644 (file)
@@ -36,6 +36,7 @@ class ModuleBase_IWorkshop;
 class Config_WidgetAPI;
 class ModuleBase_IViewWindow;
 class ModuleBase_ViewerPrs;
+class PartSet_ExternalObjectsMgr;
 
 class GeomAPI_Pnt;
 class GeomAPI_Pnt2d;
@@ -115,10 +116,23 @@ protected:
   /// a shape. If the attribute do not uses the shape, it is empty
   virtual QList<std::shared_ptr<ModuleBase_ViewerPrs>> getAttributeSelection() const;
 
-protected:
   /// The methiod called when widget is activated
   virtual void activateCustom();
 
+  /// 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);
+
+  /// Creates a backup of the current values of the attribute
+  /// It should be realized in the specific widget because of different
+  /// parameters of the current attribute
+  /// \param theAttribute an attribute
+  /// \param theValid a boolean flag, if restore happens for valid parameters
+  void restoreAttributeValue(const AttributePtr& theAttribute, const bool theValid);
+
 protected:
   bool fillFeature(const std::shared_ptr<ModuleBase_ViewerPrs>& theSelectedPrs,
                    ModuleBase_IViewWindow* theWnd,
@@ -137,6 +151,7 @@ protected:
   bool myHasPreview;
   std::shared_ptr<ModelAPI_Object> myPreviewObject;
   std::shared_ptr<GeomAPI_Pnt2d>   myPreviewPoint;
+  PartSet_ExternalObjectsMgr* myExternalObjectMgr; ///< reference to external objects manager
 };
 
 #endif
\ No newline at end of file