]> SALOME platform Git repositories - modules/shaper.git/blobdiff - src/PartSet/PartSet_WidgetFeaturePointSelector.cpp
Salome HOME
Issue #18429: Provide selection of external objects for angle constraint.
[modules/shaper.git] / src / PartSet / PartSet_WidgetFeaturePointSelector.cpp
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();
+}