Salome HOME
updated copyright message
[modules/shaper.git] / src / PartSet / PartSet_ExternalObjectsMgr.cpp
old mode 100755 (executable)
new mode 100644 (file)
index 793940c..20d73ad
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2017  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2023  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
 //
 // You should have received a copy of the GNU Lesser General Public
 // License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 //
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
 
 #include "PartSet_ExternalObjectsMgr.h"
+
+#include "PartSet_CenterPrs.h"
 #include "PartSet_Tools.h"
 
 #include <XGUI_Workshop.h>
@@ -83,12 +84,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 +139,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;
@@ -135,7 +167,7 @@ void PartSet_ExternalObjectsMgr::removeExternal(const CompositeFeaturePtr& theSk
 
 void PartSet_ExternalObjectsMgr::removeExternalObject(const ObjectPtr& theObject,
                                                       const CompositeFeaturePtr& /*theSketch*/,
-                                                      const FeaturePtr& theFeature,
+                                                      const FeaturePtr& /*theFeature*/,
                                                       ModuleBase_IWorkshop* theWorkshop)
 {
   if (theObject.get()) {