Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchAPI / SketchAPI_IntersectionPoint.cpp
index 75ddb603ce5d90885d4bd94a725be5efa345c1d2..6cc79abd2b1bd5092adc5f6296d8496ec943ab84 100644 (file)
@@ -1,14 +1,30 @@
-// Name   : SketchAPI_IntersectionPoint.cpp
-// Purpose: 
+// 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
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+// Lesser General Public License for more details.
+//
+// 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
+//
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
 //
-// History:
-// 16/06/16 - Sergey POKHODENKO - Creation of the file
 
-//--------------------------------------------------------------------------------------
 #include "SketchAPI_IntersectionPoint.h"
+#include "SketchAPI_Point.h"
+//--------------------------------------------------------------------------------------
+#include <SketchPlugin_Point.h>
 //--------------------------------------------------------------------------------------
 #include <GeomAPI_Pnt2d.h>
 //--------------------------------------------------------------------------------------
+#include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 //--------------------------------------------------------------------------------------
@@ -25,17 +41,17 @@ SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
 : SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
-    setByExternalLine(theExternal);
+    setByExternalEdge(theExternal);
   }
 }
 
 SketchAPI_IntersectionPoint::SketchAPI_IntersectionPoint(
     const std::shared_ptr<ModelAPI_Feature> & theFeature,
-    const std::string & theExternalName )
+    const std::wstring & theExternalName )
 : SketchAPI_SketchEntity(theFeature)
 {
   if (initialize()) {
-    setByExternalLineName(theExternalName);
+    setByExternalEdgeName(theExternalName);
   }
 }
 
@@ -45,18 +61,70 @@ SketchAPI_IntersectionPoint::~SketchAPI_IntersectionPoint()
 }
 
 //--------------------------------------------------------------------------------------
-void SketchAPI_IntersectionPoint::setByExternalLine(const ModelHighAPI_Selection & theExternalLine)
+void SketchAPI_IntersectionPoint::setByExternalEdge(const ModelHighAPI_Selection & theExternalLine)
 {
-  fillAttribute(theExternalLine, externalLine());
+  fillAttribute(theExternalLine, externalFeature());
 
   execute();
 }
 
-void SketchAPI_IntersectionPoint::setByExternalLineName(const std::string & theExternalLineName)
+void SketchAPI_IntersectionPoint::setByExternalEdgeName(const std::wstring & theExternalLineName)
 {
-  fillAttribute(ModelHighAPI_Selection("EDGE", theExternalLineName), externalLine());
+  fillAttribute(ModelHighAPI_Selection("EDGE", theExternalLineName), externalFeature());
 
   execute();
 }
 
+void SketchAPI_IntersectionPoint::setIncludeToResult(bool theKeepResult)
+{
+  fillAttribute(theKeepResult, includeToResult());
+  execute(true);
+}
+
 //--------------------------------------------------------------------------------------
+
+std::list<std::shared_ptr<SketchAPI_SketchEntity> >
+SketchAPI_IntersectionPoint::intersectionPoints() const
+{
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> > anEntities;
+
+  std::list<ObjectPtr> anIntersections =
+      feature()->reflist(SketchPlugin_IntersectionPoint::INTERSECTION_POINTS_ID())->list();
+  for (std::list<ObjectPtr>::iterator anIt = anIntersections.begin();
+       anIt != anIntersections.end(); ++anIt) {
+    FeaturePtr aFeature = ModelAPI_Feature::feature(*anIt);
+    if (aFeature && aFeature->getKind() == SketchPlugin_Point::ID())
+    {
+      std::shared_ptr<SketchAPI_SketchEntity> anEnt(new SketchAPI_Point(aFeature));
+      anEntities.push_back(anEnt);
+    }
+  }
+
+  return anEntities;
+}
+
+//--------------------------------------------------------------------------------------
+
+void SketchAPI_IntersectionPoint::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  FeaturePtr aBase = feature();
+  const std::string& aSketchName = theDumper.parentName(aBase);
+
+  AttributeSelectionPtr anExternal = externalFeature();
+  AttributeBooleanPtr isIncludeToRes = includeToResult();
+  theDumper << aBase << " = " << aSketchName << ".addIntersectionPoint("
+            << anExternal << ", " << isIncludeToRes << ")" << std::endl;
+  // dump "auxiliary" flag if necessary
+  SketchAPI_SketchEntity::dump(theDumper);
+
+  // Dump variables for a list of intersected points
+  theDumper << "[";
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> > aList = intersectionPoints();
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> >::const_iterator anIt = aList.begin();
+  for (; anIt != aList.end(); ++anIt) {
+    if (anIt != aList.begin())
+      theDumper << ", ";
+    theDumper << (*anIt)->feature();
+  }
+  theDumper << "] = " << theDumper.name(aBase) << ".intersectionPoints()" << std::endl;
+}