Salome HOME
Updated copyright comment
[modules/shaper.git] / src / SketchSolver / SketchSolver_Manager.cpp
index 6f000ec6c8d91a46d443836ae7d4a8a231172ee9..8bebc53c4247037984ef7b9c14fb112e7c6903f4 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2014-2019  CEA/DEN, EDF R&D
+// Copyright (C) 2014-2024  CEA, EDF
 //
 // This library is free software; you can redistribute it and/or
 // modify it under the terms of the GNU Lesser General Public
@@ -22,6 +22,7 @@
 
 #include <Events_Loop.h>
 #include <GeomDataAPI_Point2D.h>
+#include <GeomDataAPI_Point2DArray.h>
 #include <ModelAPI_Events.h>
 #include <ModelAPI_ResultConstruction.h>
 #include <ModelAPI_Session.h>
@@ -87,6 +88,19 @@ static void featuresOrderedByType(const std::set<ObjectPtr>& theOriginalFeatures
   }
 }
 
+static void setPoint(AttributePtr theAttribute,
+                     const int thePointIndex,
+                     const std::shared_ptr<GeomAPI_Pnt2d> theValue)
+{
+  AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theAttribute);
+  AttributePoint2DArrayPtr aPointArrayAttr =
+      std::dynamic_pointer_cast<GeomDataAPI_Point2DArray>(theAttribute);
+  if (aPointAttr)
+    aPointAttr->setValue(theValue);
+  else if (aPointArrayAttr && thePointIndex >= 0)
+    aPointArrayAttr->setPnt(thePointIndex, theValue);
+}
+
 
 
 // ========================================================
@@ -180,8 +194,8 @@ void SketchSolver_Manager::processEvent(
         std::dynamic_pointer_cast<ModelAPI_ObjectMovedMessage>(theMessage);
 
     ObjectPtr aMovedObject = aMoveMsg->movedObject();
-    std::shared_ptr<GeomDataAPI_Point2D> aMovedPoint =
-        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aMoveMsg->movedAttribute());
+    AttributePtr aMovedAttribute = aMoveMsg->movedAttribute();
+    int aMovedPoint = aMoveMsg->movedPointIndex();
 
     const std::shared_ptr<GeomAPI_Pnt2d>& aFrom = aMoveMsg->originalPosition();
     const std::shared_ptr<GeomAPI_Pnt2d>& aTo = aMoveMsg->currentPosition();
@@ -192,8 +206,8 @@ void SketchSolver_Manager::processEvent(
           std::dynamic_pointer_cast<SketchPlugin_Feature>(aMovedFeature);
       if (aSketchFeature && !aSketchFeature->isMacro())
         needToResolve = moveFeature(aSketchFeature, aFrom, aTo);
-    } else if (aMovedPoint)
-      needToResolve = moveAttribute(aMovedPoint, aFrom, aTo);
+    } else if (aMovedAttribute)
+      needToResolve = moveAttribute(aMovedAttribute, aMovedPoint, aFrom, aTo);
 
   } else if (theMessage->eventID() == Events_Loop::loop()->eventByName(EVENT_OBJECT_DELETED)) {
     std::shared_ptr<ModelAPI_ObjectDeletedMessage> aDeleteMsg =
@@ -231,8 +245,8 @@ void SketchSolver_Manager::processEvent(
     if (aObjects.size() == 1) {
       std::set<ObjectPtr>::const_iterator aIt;
       for (aIt = aObjects.cbegin(); aIt != aObjects.cend(); aIt++) {
-        std::shared_ptr<SketchPlugin_Feature> aFeature =
-          std::dynamic_pointer_cast<SketchPlugin_Feature>(*aIt);
+        CompositeFeaturePtr aFeature =
+            std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(*aIt);
         if (aFeature) {
           SketchGroupPtr aGroup = findGroup(aFeature);
 
@@ -245,7 +259,7 @@ void SketchSolver_Manager::processEvent(
             aFeatures.push_back(*aIt);
           }
 
-          // TODO: send features to GUI
+          // send features to GUI
           static const Events_ID anEvent = Events_Loop::eventByName(EVENT_DOF_OBJECTS);
           ModelAPI_EventCreator::get()->sendUpdated(aFeatures, anEvent);
           Events_Loop::loop()->flush(anEvent);
@@ -349,7 +363,8 @@ bool SketchSolver_Manager::moveFeature(
 //  Purpose:  move given attribute in appropriate group
 // ============================================================================
 bool SketchSolver_Manager::moveAttribute(
-    const std::shared_ptr<GeomDataAPI_Point2D>& theMovedAttribute,
+    const std::shared_ptr<ModelAPI_Attribute>& theMovedAttribute,
+    const int theMovedPointIndex,
     const std::shared_ptr<GeomAPI_Pnt2d>& theFrom,
     const std::shared_ptr<GeomAPI_Pnt2d>& theTo)
 {
@@ -358,7 +373,7 @@ bool SketchSolver_Manager::moveAttribute(
       std::dynamic_pointer_cast<SketchPlugin_Constraint>(anOwner);
   if (aConstraint)
   {
-    theMovedAttribute->setValue(theTo);
+    setPoint(theMovedAttribute, theMovedPointIndex, theTo);
     Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
     return true;
   }
@@ -369,12 +384,12 @@ bool SketchSolver_Manager::moveAttribute(
   if (aSketchFeature)
     aGroup = findGroup(aSketchFeature);
   if (!aGroup) {
-    theMovedAttribute->setValue(theTo);
+    setPoint(theMovedAttribute, theMovedPointIndex, theTo);
     return false;
   }
 
   aGroup->blockEvents(true);
-  return aGroup->movePoint(theMovedAttribute, theFrom, theTo);
+  return aGroup->movePoint(theMovedAttribute, theMovedPointIndex, theFrom, theTo);
 }
 
 // ============================================================================
@@ -382,7 +397,7 @@ bool SketchSolver_Manager::moveAttribute(
 //  Purpose:  search groups of entities interacting with given feature
 // ============================================================================
 SketchGroupPtr SketchSolver_Manager::findGroup(
-    std::shared_ptr<SketchPlugin_Feature> theFeature)
+  std::shared_ptr<SketchPlugin_Feature> theFeature)
 {
   if (!isFeatureValid(theFeature))
     return SketchGroupPtr(); // do not process wrong features
@@ -398,17 +413,21 @@ SketchGroupPtr SketchSolver_Manager::findGroup(
       break;
     }
   }
+  return findGroup(aSketch);
+}
 
-  if (!aSketch)
+SketchGroupPtr SketchSolver_Manager::findGroup(CompositeFeaturePtr theSketch)
+{
+  if (!theSketch)
     return SketchGroupPtr(); // not a sketch's feature
 
   std::list<SketchGroupPtr>::const_iterator aGroupIt;
   for (aGroupIt = myGroups.begin(); aGroupIt != myGroups.end(); ++aGroupIt)
-    if ((*aGroupIt)->getWorkplane() == aSketch)
+    if ((*aGroupIt)->getWorkplane() == theSketch)
       return *aGroupIt;
 
   // group for the sketch does not created yet
-  SketchGroupPtr aNewGroup = SketchGroupPtr(new SketchSolver_Group(aSketch));
+  SketchGroupPtr aNewGroup = SketchGroupPtr(new SketchSolver_Group(theSketch));
   myGroups.push_back(aNewGroup);
   return aNewGroup;
 }