Salome HOME
Update copyrights
[modules/shaper.git] / src / SketchAPI / SketchAPI_Arc.cpp
index ba8e4cb8b10cb473f447f5a9ee77e560612d2579..4f973996c92b0e6732f0275a046e42f8abc84323 100644 (file)
@@ -1,8 +1,21 @@
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D -->
-
-// File:        SketchAPI_Arc.cpp
-// Created:     09 June 2016
-// Author:      Dmitry Bobylev
+// Copyright (C) 2014-2019  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
+//
 
 #include "SketchAPI_Arc.h"
 
 #include <ModelHighAPI_Selection.h>
 #include <ModelHighAPI_Tools.h>
 
-//==================================================================================================
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintTangent.h>
+
+/// Obtain constraints prepared by tangent arc
+static std::list<FeaturePtr> tangentArcConstraints(const FeaturePtr& theArc);
+
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature> & theFeature)
 : SketchAPI_SketchEntity(theFeature)
 {
   initialize();
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              double theCenterX, double theCenterY,
                              double theStartX, double theStartY,
@@ -29,11 +48,12 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
 : SketchAPI_SketchEntity(theFeature)
 {
   if(initialize()) {
-    setByCenterStartEnd(theCenterX, theCenterY, theStartX, theStartY, theEndX, theEndY, theInversed);
+    setByCenterStartEnd(theCenterX, theCenterY, theStartX,
+                        theStartY, theEndX, theEndY, theInversed);
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                              const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
@@ -46,55 +66,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
-SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                             double theStartX, double theStartY,
-                             double theEndX, double theEndY,
-                             double thePassedX, double thePassedY)
-: SketchAPI_SketchEntity(theFeature)
-{
-  if (initialize()) {
-    setByStartEndPassed(theStartX, theStartY, theEndX, theEndY, thePassedX, thePassedY);
-  }
-}
-
-//==================================================================================================
-SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                             const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
-                             const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
-                             const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
-: SketchAPI_SketchEntity(theFeature)
-{
-  if (initialize()) {
-    setByStartEndPassed(theStart, theEnd, thePassed);
-  }
-}
-
-//==================================================================================================
-SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                             const ModelHighAPI_RefAttr& theTangentPoint,
-                             double theEndX, double theEndY,
-                             bool theInversed)
-: SketchAPI_SketchEntity(theFeature)
-{
-  if (initialize()) {
-    setByTangent(theTangentPoint, theEndX, theEndY, theInversed);
-  }
-}
-
-//==================================================================================================
-SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
-                             const ModelHighAPI_RefAttr& theTangentPoint,
-                             const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
-                             bool theInversed)
-: SketchAPI_SketchEntity(theFeature)
-{
-  if (initialize()) {
-    setByTangent(theTangentPoint, theEnd, theInversed);
-  }
-}
-
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const ModelHighAPI_Selection& theExternal)
 : SketchAPI_SketchEntity(theFeature)
@@ -104,7 +76,7 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature,
                              const std::string& theExternalName)
 : SketchAPI_SketchEntity(theFeature)
@@ -114,95 +86,41 @@ SketchAPI_Arc::SketchAPI_Arc(const std::shared_ptr<ModelAPI_Feature>& theFeature
   }
 }
 
-//==================================================================================================
+//================================================================================================
 SketchAPI_Arc::~SketchAPI_Arc()
 {
 
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByCenterStartEnd(double theCenterX, double theCenterY,
                                         double theStartX, double theStartY,
                                         double theEndX, double theEndY,
                                         bool theInversed)
 {
-  fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType);
   fillAttribute(center(), theCenterX, theCenterY);
   fillAttribute(startPoint(), theStartX, theStartY);
   fillAttribute(endPoint(), theEndX, theEndY);
-  fillAttribute(theInversed, myinversed);
+  fillAttribute(theInversed, myreversed);
 
   execute();
 }
 
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByCenterStartEnd(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
                                         const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
                                         const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
                                         bool theInversed)
 {
-  fillAttribute(SketchPlugin_Arc::ARC_TYPE_CENTER_START_END(), myarcType);
   fillAttribute(theCenter, mycenter);
   fillAttribute(theStart, mystartPoint);
   fillAttribute(theEnd, myendPoint);
-  fillAttribute(theInversed, myinversed);
+  fillAttribute(theInversed, myreversed);
 
   execute();
 }
 
-//==================================================================================================
-void SketchAPI_Arc::setByStartEndPassed(double theStartX, double theStartY,
-                                        double theEndX, double theEndY,
-                                        double thePassedX, double thePassedY)
-{
-  fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
-  fillAttribute(startPoint(), theStartX, theStartY);
-  fillAttribute(endPoint(), theEndX, theEndY);
-  fillAttribute(passedPoint(), thePassedX, thePassedY);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Arc::setByStartEndPassed(const std::shared_ptr<GeomAPI_Pnt2d>& theStart,
-                                        const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
-                                        const std::shared_ptr<GeomAPI_Pnt2d>& thePassed)
-{
-  fillAttribute(SketchPlugin_Arc::ARC_TYPE_THREE_POINTS(), myarcType);
-  fillAttribute(theStart, mystartPoint);
-  fillAttribute(theEnd, myendPoint);
-  fillAttribute(thePassed, mypassedPoint);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
-                                 double theEndX, double theEndY,
-                                 bool theInversed)
-{
-  fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
-  fillAttribute(theTangentPoint, mytangentPoint);
-  fillAttribute(endPoint(), theEndX, theEndY);
-  fillAttribute(theInversed, myinversed);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Arc::setByTangent(const ModelHighAPI_RefAttr& theTangentPoint,
-                                 const std::shared_ptr<GeomAPI_Pnt2d>& theEnd,
-                                 bool theInversed)
-{
-  fillAttribute(SketchPlugin_Arc::ARC_TYPE_TANGENT(), myarcType);
-  fillAttribute(theTangentPoint, mytangentPoint);
-  fillAttribute(theEnd, myendPoint);
-  fillAttribute(theInversed, myinversed);
-
-  execute();
-}
-
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
 {
   fillAttribute(theExternal, external());
@@ -210,7 +128,7 @@ void SketchAPI_Arc::setByExternal(const ModelHighAPI_Selection & theExternal)
   execute();
 }
 
-//==================================================================================================
+//===============================================================================================
 void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
 {
   fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
@@ -218,23 +136,7 @@ void SketchAPI_Arc::setByExternalName(const std::string & theExternalName)
   execute();
 }
 
-//==================================================================================================
-void SketchAPI_Arc::setRadius(double theRadius)
-{
-  fillAttribute(ModelHighAPI_Double(theRadius), myradius);
-
-  execute();
-}
-
-//==================================================================================================
-void SketchAPI_Arc::setAngle(double theAngle)
-{
-  fillAttribute(ModelHighAPI_Double(theAngle), myangle);
-
-  execute();
-}
-
-//==================================================================================================
+//================================================================================================
 void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
 {
   if (isCopy())
@@ -244,25 +146,13 @@ void SketchAPI_Arc::dump(ModelHighAPI_Dumper& theDumper) const
   const std::string& aSketchName = theDumper.parentName(aBase);
 
   AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
-  if (anExternal->value()) {
+  if (anExternal->context()) {
     // arc is external
     theDumper << aBase << " = " << aSketchName << ".addArc(" << anExternal << ")" << std::endl;
   } else {
-    AttributeStringPtr aType = arcType();
-    if (aType->value() == SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()) {
-      // arc given by center and start, end points
-      theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
-                << startPoint() << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
-    } else if (aType->value() == SketchPlugin_Arc::ARC_TYPE_THREE_POINTS()) {
-      // arc given by three points
-      theDumper << aBase << " = " << aSketchName << ".addArc(" << startPoint() << ", "
-                << endPoint() << ", " << passedPoint() << ")" << std::endl;
-    } else {
-      // tangent arc
-      AttributeRefAttrPtr aTangentPoint = tangentPoint();
-      theDumper << aBase << " = " << aSketchName << ".addArc("
-                << aTangentPoint << ", " << endPoint() << ", " << inversed() << ")" << std::endl;
-    }
+    // arc given by center and start, end points
+    theDumper << aBase << " = " << aSketchName << ".addArc(" << center() << ", "
+              << startPoint() << ", " << endPoint() << ", " << reversed() << ")" << std::endl;
   }
   // dump "auxiliary" flag if necessary
   SketchAPI_SketchEntity::dump(theDumper);