Salome HOME
updated copyright message
[modules/shaper.git] / src / SketchAPI / SketchAPI_SketchEntity.cpp
index 3e5f4f82446cbb63600d70da8e938a6104636b91..c718a07ecb21b6bd3d6318974d338aca19be5e41 100644 (file)
@@ -1,14 +1,42 @@
-// Name   : SketchAPI_SketchEntity.cpp
-// Purpose: 
+// Copyright (C) 2014-2023  CEA/DEN, EDF R&D
+//
+// 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:
-// 07/06/16 - Sergey POKHODENKO - Creation of the file
 
-//--------------------------------------------------------------------------------------
 #include "SketchAPI_SketchEntity.h"
+#include <SketchAPI_Arc.h>
+#include <SketchAPI_BSpline.h>
+#include <SketchAPI_Circle.h>
+#include <SketchAPI_Ellipse.h>
+#include <SketchAPI_EllipticArc.h>
+#include <SketchAPI_IntersectionPoint.h>
+#include <SketchAPI_Line.h>
+#include <SketchAPI_Point.h>
 //--------------------------------------------------------------------------------------
 #include <ModelHighAPI_Dumper.h>
 #include <ModelHighAPI_Tools.h>
+
+#include <SketchPlugin_Arc.h>
+#include <SketchPlugin_BSpline.h>
+#include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Ellipse.h>
+#include <SketchPlugin_IntersectionPoint.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_Point.h>
 //--------------------------------------------------------------------------------------
 SketchAPI_SketchEntity::SketchAPI_SketchEntity(
     const std::shared_ptr<ModelAPI_Feature> & theFeature)
@@ -57,7 +85,38 @@ void SketchAPI_SketchEntity::dump(ModelHighAPI_Dumper& theDumper) const
 bool SketchAPI_SketchEntity::isCopy() const
 {
   // check the feature is a copy of another entity
-  std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
-      std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(feature());
-  return aSketchEntity && aSketchEntity->isCopy();
+  AttributeBooleanPtr isCopy = feature()->boolean(SketchPlugin_SketchEntity::COPY_ID());
+  AttributeReferencePtr hasParent = feature()->reference(SketchPlugin_SketchEntity::PARENT_ID());
+  return (isCopy.get() && isCopy->value()) || (hasParent && hasParent->value());
+}
+
+std::list<std::shared_ptr<SketchAPI_SketchEntity> >
+SketchAPI_SketchEntity::wrap(const std::list<std::shared_ptr<ModelAPI_Feature> >& theFeatures)
+{
+  std::list<std::shared_ptr<SketchAPI_SketchEntity> > aResult;
+  std::list<std::shared_ptr<ModelAPI_Feature> >::const_iterator anIt = theFeatures.begin();
+  for (; anIt != theFeatures.end(); ++anIt) {
+    if ((*anIt)->getKind() == SketchPlugin_Line::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Line(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_Arc::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Arc(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_Circle::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Circle(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_Ellipse::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Ellipse(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_EllipticArc::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_EllipticArc(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_BSpline::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_BSpline(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_BSplinePeriodic::ID()) {
+      aResult.push_back(
+          std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_BSplinePeriodic(*anIt)));
+    }
+    else if ((*anIt)->getKind() == SketchPlugin_Point::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Point(*anIt)));
+    else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID())
+      aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(
+                                                    new SketchAPI_IntersectionPoint(*anIt)));
+  }
+  return aResult;
 }