]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003)
authorazv <azv@opencascade.com>
Fri, 13 Sep 2019 10:01:31 +0000 (13:01 +0300)
committerazv <azv@opencascade.com>
Sun, 15 Sep 2019 11:09:09 +0000 (14:09 +0300)
SketchAPI for Ellipse feature.

15 files changed:
src/ModelHighAPI/ModelHighAPI.i
src/ModelHighAPI/ModelHighAPI_RefAttr.cpp
src/PythonAPI/model/sketcher/tools.py
src/SketchAPI/CMakeLists.txt
src/SketchAPI/SketchAPI.i
src/SketchAPI/SketchAPI_Ellipse.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_Ellipse.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_MacroEllipse.cpp [new file with mode: 0644]
src/SketchAPI/SketchAPI_MacroEllipse.h [new file with mode: 0644]
src/SketchAPI/SketchAPI_Sketch.cpp
src/SketchAPI/SketchAPI_Sketch.h
src/SketchAPI/SketchAPI_SketchEntity.cpp
src/SketchAPI/SketchAPI_swig.h
src/SketchPlugin/SketchPlugin_Ellipse.cpp
src/SketchPlugin/SketchPlugin_MacroEllipse.cpp

index f26df1e5d32b3b5610fb1c06347d111d0284936f..72971cc015fdb391b1226a44f2c303097ff74f1d 100644 (file)
   std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
   std::shared_ptr<ModelAPI_Object> * temp_object;
   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+  ModelHighAPI_Selection* temp_selection;
   int newmem = 0;
+  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+    if (!temp_selection) {
+      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+      return NULL;
+    }
+    temp = ModelHighAPI_RefAttr(std::shared_ptr<ModelAPI_Object>(temp_selection->resultSubShapePair().first));
+    if (newmem & SWIG_CAST_NEW_MEMORY) {
+      delete temp_selection;
+    }
+    $1 = &temp;
+  } else
   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
     if (!temp_attribute) {
-      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
       return NULL;
     }
     temp = ModelHighAPI_RefAttr(*temp_attribute);
   } else
   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
     if (!temp_object) {
-      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
       return NULL;
     }
     temp = ModelHighAPI_RefAttr(*temp_object);
   } else
   if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
     if (!temp_interface) {
-      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
       return NULL;
     }
     temp = ModelHighAPI_RefAttr(*temp_interface);
   } else
   if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
   } else {
-    PyErr_SetString(PyExc_ValueError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+    PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
     return NULL;
   }
 }
   $result = SWIG_NewPointerObj( (void*) ptr, $1_descriptor, 1 );
 }
 
+%typemap(out) const ModelHighAPI_RefAttr & {
+  $1_basetype * ptr = new $1_basetype(*$1);
+  $result = SWIG_NewPointerObj( (void*) ptr, $1_descriptor, 1 );
+}
+
 // std::list -> []
 %template(SelectionList) std::list<ModelHighAPI_Selection>;
 %template(SelectionListList) std::list<std::list<ModelHighAPI_Selection> >;
index 30c15a9240a3c1b4f00e4441e6154026bb717047..03548d25270fe4ec2d63747e93fd1e8b68803bab 100644 (file)
@@ -79,7 +79,7 @@ void ModelHighAPI_RefAttr::appendToList(
 //--------------------------------------------------------------------------------------
 bool ModelHighAPI_RefAttr::isEmpty() const
 {
-  return !(myAttribute && myObject);
+  return !(myAttribute || myObject);
 }
 
 //--------------------------------------------------------------------------------------
index 7bb8f5362520a4aa868c69d6f8c0fe4f5a2be667..0d4890dda0c060edef3b6a17572f13a960f8c50c 100644 (file)
@@ -18,6 +18,7 @@
 #
 
 import ModelHighAPI
+from GeomAPI import *
 from GeomDataAPI import *
 from ModelAPI import *
 import math
@@ -111,6 +112,8 @@ def toList(thePoint):
         return thePoint
     elif issubclass(type(thePoint), GeomDataAPI_Point2D):
         return [thePoint.x(), thePoint.y()]
+    elif issubclass(type(thePoint), GeomAPI_Pnt2d):
+        return [thePoint.x(), thePoint.y()]
     else:
         aFeature = toSketchFeature(thePoint)
         aPoint = geomDataAPI_Point2D(aFeature.attribute("PointCoordinates"))
index b93b91f9e4590e8cdc4059f51874d8677c6b16f5..ff40200abe4509d4e08d898cdb8d34af5ebfcd11 100644 (file)
@@ -25,17 +25,19 @@ SET(PROJECT_HEADERS
   SketchAPI_Circle.h
   SketchAPI_Constraint.h
   SketchAPI_ConstraintAngle.h
+  SketchAPI_Ellipse.h
   SketchAPI_IntersectionPoint.h
   SketchAPI_Line.h
   SketchAPI_MacroArc.h
   SketchAPI_MacroCircle.h
+  SketchAPI_MacroEllipse.h
   SketchAPI_Mirror.h
-  SketchAPI_Sketch.h
-  SketchAPI_SketchEntity.h
   SketchAPI_Point.h
   SketchAPI_Projection.h
   SketchAPI_Rectangle.h
   SketchAPI_Rotation.h
+  SketchAPI_Sketch.h
+  SketchAPI_SketchEntity.h
   SketchAPI_Translation.h
 )
 
@@ -44,17 +46,19 @@ SET(PROJECT_SOURCES
   SketchAPI_Circle.cpp
   SketchAPI_Constraint.cpp
   SketchAPI_ConstraintAngle.cpp
+  SketchAPI_Ellipse.cpp
   SketchAPI_IntersectionPoint.cpp
   SketchAPI_Line.cpp
   SketchAPI_MacroArc.cpp
   SketchAPI_MacroCircle.cpp
+  SketchAPI_MacroEllipse.cpp
   SketchAPI_Mirror.cpp
-  SketchAPI_Sketch.cpp
-  SketchAPI_SketchEntity.cpp
   SketchAPI_Point.cpp
   SketchAPI_Projection.cpp
   SketchAPI_Rectangle.cpp
   SketchAPI_Rotation.cpp
+  SketchAPI_Sketch.cpp
+  SketchAPI_SketchEntity.cpp
   SketchAPI_Translation.cpp
 )
 
index 36732e2c2f1abb6472a6ae428108dbdb8b6fbb0d..9cde425da08595ca54d99e3ee6f6e7cfe8d59889 100644 (file)
@@ -41,6 +41,7 @@
 // standard definitions
 %include "typemaps.i"
 %include "std_list.i"
+%include "std_pair.i"
 %include "std_shared_ptr.i"
 
 // shared pointers
@@ -48,6 +49,8 @@
 %shared_ptr(SketchAPI_MacroArc)
 %shared_ptr(SketchAPI_Circle)
 %shared_ptr(SketchAPI_MacroCircle)
+%shared_ptr(SketchAPI_Ellipse)
+%shared_ptr(SketchAPI_MacroEllipse)
 %shared_ptr(SketchAPI_Constraint)
 %shared_ptr(SketchAPI_ConstraintAngle)
 %shared_ptr(SketchAPI_IntersectionPoint)
@@ -65,6 +68,8 @@
 %template(InterfaceList) std::list<std::shared_ptr<ModelHighAPI_Interface> >;
 %template(EntityList)    std::list<std::shared_ptr<SketchAPI_SketchEntity> >;
 %template(SketchPointList) std::list<std::shared_ptr<SketchAPI_Point> >;
+// std::pair -> []
+%template(PointRefAttrPair) std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>;
 
 %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr<ModelAPI_Feature>, const std::shared_ptr<ModelAPI_Feature> & {
   std::shared_ptr<ModelAPI_Feature> * temp_feature;
   }
 }
 
-%typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) {
-  std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
-  std::shared_ptr<ModelAPI_Object> * temp_object;
-  std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
-  ModelHighAPI_Selection* temp_selection;
-  int newmem = 0;
-  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
-    if (!temp_selection) {
-      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
-      return NULL;
-    }
-    temp = ModelHighAPI_RefAttr(std::shared_ptr<ModelAPI_Object>(temp_selection->resultSubShapePair().first));
-    if (newmem & SWIG_CAST_NEW_MEMORY) {
-      delete temp_selection;
-    }
-    $1 = &temp;
-  } else
-  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
-    if (!temp_attribute) {
-      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
-      return NULL;
-    }
-    temp = ModelHighAPI_RefAttr(*temp_attribute);
-    if (newmem & SWIG_CAST_NEW_MEMORY) {
-      delete temp_attribute;
-    }
-    $1 = &temp;
-  } else
-  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
-    if (!temp_object) {
-      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
-      return NULL;
-    }
-    temp = ModelHighAPI_RefAttr(*temp_object);
-    if (newmem & SWIG_CAST_NEW_MEMORY) {
-      delete temp_object;
-    }
-    $1 = &temp;
-  } else
-  if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
-    if (!temp_interface) {
-      PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
-      return NULL;
-    }
-    temp = ModelHighAPI_RefAttr(*temp_interface);
-    if (newmem & SWIG_CAST_NEW_MEMORY) {
-      delete temp_interface;
-    }
-    $1 = &temp;
-  } else
-  if ((SWIG_ConvertPtr($input, (void **)&$1, $1_descriptor, SWIG_POINTER_EXCEPTION)) == 0) {
-  } else {
-    PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
-    return NULL;
-  }
-}
-
 %typemap(in) const std::list<std::shared_ptr<ModelAPI_Object> > & (std::list<std::shared_ptr<ModelAPI_Object> > temp) {
   std::shared_ptr<ModelAPI_Object> * temp_object;
   std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
   }
 }
 
+%typecheck(SWIG_TYPECHECK_POINTER) std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>, const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & {
+  std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
+  std::shared_ptr<ModelAPI_Object> * temp_object;
+  std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+  ModelHighAPI_Selection* temp_selection;
+  std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>* temp_pair;
+  std::shared_ptr<GeomAPI_Pnt2d> * temp_point;
+  ModelHighAPI_RefAttr temp_refattr;
+  int newmem = 0;
+  std::list<PyObject*> temp_inputlist;
+  if (PySequence_Check($input)) {
+    for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
+      PyObject * temp = PySequence_GetItem($input, i);
+      temp_inputlist.push_back(temp);
+    }
+  } else {
+    temp_inputlist.push_back($input);
+  }
+
+  $1 = 1;
+  for (std::list<PyObject*>::iterator it = temp_inputlist.begin(); it != temp_inputlist.end() && $1; ++it) {
+    PyObject* item = *it;
+
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_selection) {
+        $1 = 1;
+      } else {
+        $1 = 0;
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_attribute) {
+        $1 = 1;
+      } else {
+        $1 = 0;
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_object) {
+        $1 = 1;
+      } else {
+        $1 = 0;
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_interface) {
+        $1 = 1;
+      } else {
+        $1 = 0;
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_pair, $descriptor(std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_pair) {
+        $1 = 1;
+      } else {
+        $1 = 0;
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_point) {
+        $1 = 1;
+      } else {
+        $1 = 0;
+      }
+    } else {
+      $1 = 0;
+    }
+  }
+}
+
+%typemap(in) const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & (std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> temp) {
+  std::shared_ptr<ModelAPI_Attribute> * temp_attribute;
+  std::shared_ptr<ModelAPI_Object> * temp_object;
+  std::shared_ptr<ModelHighAPI_Interface> * temp_interface;
+  ModelHighAPI_Selection* temp_selection;
+  std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>* temp_pair;
+  std::shared_ptr<GeomAPI_Pnt2d> * temp_point = 0;
+  ModelHighAPI_RefAttr temp_refattr;
+  int newmem = 0;
+  std::list<PyObject*> temp_inputlist;
+  if (PySequence_Check($input)) {
+    for (Py_ssize_t i = 0; i < PySequence_Size($input); ++i) {
+      PyObject * temp = PySequence_GetItem($input, i);
+      temp_inputlist.push_back(temp);
+    }
+  } else {
+    temp_inputlist.push_back($input);
+  }
+
+  for (std::list<PyObject*>::iterator it = temp_inputlist.begin(); it != temp_inputlist.end(); ++it) {
+    PyObject* item = *it;
+
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_selection, $descriptor(ModelHighAPI_Selection*), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_selection) {
+        temp_refattr = ModelHighAPI_RefAttr(std::shared_ptr<ModelAPI_Object>(temp_selection->resultSubShapePair().first));
+        if (newmem & SWIG_CAST_NEW_MEMORY) {
+          delete temp_selection;
+        }
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_attribute, $descriptor(std::shared_ptr<ModelAPI_Attribute> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_attribute) {
+        temp_refattr = ModelHighAPI_RefAttr(*temp_attribute);
+        if (newmem & SWIG_CAST_NEW_MEMORY) {
+          delete temp_attribute;
+        }
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_object, $descriptor(std::shared_ptr<ModelAPI_Object> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_object) {
+        temp_refattr = ModelHighAPI_RefAttr(*temp_object);
+        if (newmem & SWIG_CAST_NEW_MEMORY) {
+          delete temp_object;
+        }
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_interface, $descriptor(std::shared_ptr<ModelHighAPI_Interface> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_interface) {
+        temp_refattr = ModelHighAPI_RefAttr(*temp_interface);
+        if (newmem & SWIG_CAST_NEW_MEMORY) {
+          delete temp_interface;
+        }
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_pair, $descriptor(std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      if (temp_pair) {
+        temp_point = &temp_pair->first;
+        temp_refattr = temp_pair->second;
+        if (newmem & SWIG_CAST_NEW_MEMORY) {
+          delete temp_pair;
+        }
+      }
+    } else
+    if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_point, $descriptor(std::shared_ptr<GeomAPI_Pnt2d> *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) {
+      // fall through
+    }
+  }
+
+  if (temp_point || !temp_refattr.isEmpty()) {
+    if (temp_point) {
+      temp = std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>(*temp_point, temp_refattr);
+    } else {
+      temp = std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>(std::shared_ptr<GeomAPI_Pnt2d>(), temp_refattr);
+    }
+    if (temp_point && (newmem & SWIG_CAST_NEW_MEMORY)) {
+      delete temp_point;
+    }
+    $1 = &temp;
+  } else {
+    PyErr_SetString(PyExc_TypeError, "argument must be ModelHighAPI_RefAttr, ModelHighAPI_Selection, ModelHighAPI_Interface, ModelAPI_Attribute or ModelAPI_Object.");
+    return NULL;
+  }
+}
+
+// fix compilarion error: 'res*' was not declared in this scope
+%typemap(freearg) const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr> & {}
+
 // all supported interfaces (the order is very important according dependencies: base class first)
 %include "SketchAPI_SketchEntity.h"
 %include "SketchAPI_Point.h"
 %include "SketchAPI_MacroCircle.h"
 %include "SketchAPI_Arc.h"
 %include "SketchAPI_MacroArc.h"
+%include "SketchAPI_Ellipse.h"
+%include "SketchAPI_MacroEllipse.h"
 %include "SketchAPI_Projection.h"
 %include "SketchAPI_Mirror.h"
 %include "SketchAPI_Translation.h"
diff --git a/src/SketchAPI/SketchAPI_Ellipse.cpp b/src/SketchAPI/SketchAPI_Ellipse.cpp
new file mode 100644 (file)
index 0000000..40c5c4a
--- /dev/null
@@ -0,0 +1,169 @@
+// 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_Ellipse.h"
+
+#include <GeomAPI_Pnt2d.h>
+
+#include <ModelHighAPI_Dumper.h>
+#include <ModelHighAPI_Selection.h>
+#include <ModelHighAPI_Tools.h>
+
+SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature> & theFeature)
+  : SketchAPI_SketchEntity(theFeature)
+{
+  initialize();
+}
+
+SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     double theCenterX, double theCenterY,
+                                     double theFocusX, double theFocusY,
+                                     double theMinorRadius)
+  : SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByCenterFocusAndRadius(theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius);
+  }
+}
+
+SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                                     const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
+                                     double theMinorRadius)
+: SketchAPI_SketchEntity(theFeature)
+{
+  if(initialize()) {
+    setByCenterFocusAndRadius(theCenter, theFocus, theMinorRadius);
+  }
+}
+
+SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const ModelHighAPI_Selection& theExternal)
+  : SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByExternal(theExternal);
+  }
+}
+
+SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                     const std::string& theExternalName)
+  : SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    setByExternalName(theExternalName);
+  }
+}
+
+SketchAPI_Ellipse::~SketchAPI_Ellipse()
+{
+}
+
+void SketchAPI_Ellipse::setByCenterFocusAndRadius(double theCenterX, double theCenterY,
+                                                  double theFocusX, double theFocusY,
+                                                  double theMinorRadius)
+{
+  fillAttribute(center(), theCenterX, theCenterY);
+  fillAttribute(firstFocus(), theFocusX, theFocusY);
+  fillAttribute(theMinorRadius, myminorRadius);
+
+  execute();
+}
+
+void SketchAPI_Ellipse::setByCenterFocusAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                                                  const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
+                                                  double theMinorRadius)
+{
+  fillAttribute(theCenter, mycenter);
+  fillAttribute(theFocus, myfirstFocus);
+  fillAttribute(theMinorRadius, myminorRadius);
+
+  execute();
+}
+
+void SketchAPI_Ellipse::setByExternal(const ModelHighAPI_Selection & theExternal)
+{
+  fillAttribute(theExternal, external());
+  execute();
+}
+
+void SketchAPI_Ellipse::setByExternalName(const std::string & theExternalName)
+{
+  fillAttribute(ModelHighAPI_Selection("EDGE", theExternalName), external());
+  execute();
+}
+
+void SketchAPI_Ellipse::setCenter(double theX, double theY)
+{
+  fillAttribute(center(), theX, theY);
+  execute();
+}
+
+void SketchAPI_Ellipse::setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter)
+{
+  fillAttribute(theCenter, mycenter);
+  execute();
+}
+
+void SketchAPI_Ellipse::setFocus(double theX, double theY)
+{
+  fillAttribute(firstFocus(), theX, theY);
+  execute();
+}
+
+void SketchAPI_Ellipse::setFocus(const std::shared_ptr<GeomAPI_Pnt2d> & theFocus)
+{
+  fillAttribute(theFocus, myfirstFocus);
+  execute();
+}
+
+void SketchAPI_Ellipse::setMinorRadius(double theMinorRadius)
+{
+  fillAttribute(theMinorRadius, myminorRadius);
+  execute();
+}
+
+ModelHighAPI_Selection SketchAPI_Ellipse::majorAxis() const
+{
+}
+
+ModelHighAPI_Selection SketchAPI_Ellipse::minorAxis() const
+{
+}
+
+void SketchAPI_Ellipse::dump(ModelHighAPI_Dumper& theDumper) const
+{
+  if (isCopy())
+    return; // no need to dump copied feature
+
+  FeaturePtr aBase = feature();
+  const std::string& aSketchName = theDumper.parentName(aBase);
+
+  AttributeSelectionPtr anExternal = aBase->selection(SketchPlugin_SketchEntity::EXTERNAL_ID());
+  if (anExternal->context()) {
+    // circle is external
+    theDumper << aBase << " = " << aSketchName << ".addEllipse(" << anExternal << ")" << std::endl;
+  } else {
+    // ellipse given by center, focus and radius
+    theDumper << aBase << " = " << aSketchName << ".addEllipse("
+              << center() << ", " << firstFocus() << ", " << minorRadius() << ")" << std::endl;
+  }
+  // dump "auxiliary" flag if necessary
+  SketchAPI_SketchEntity::dump(theDumper);
+}
diff --git a/src/SketchAPI/SketchAPI_Ellipse.h b/src/SketchAPI/SketchAPI_Ellipse.h
new file mode 100644 (file)
index 0000000..13e3443
--- /dev/null
@@ -0,0 +1,146 @@
+// 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
+//
+
+#ifndef SketchAPI_Ellipse_H_
+#define SketchAPI_Ellipse_H_
+
+#include "SketchAPI.h"
+#include "SketchAPI_SketchEntity.h"
+
+#include <SketchPlugin_Ellipse.h>
+
+class ModelHighAPI_Selection;
+
+/// \class SketchAPI_Ellipse
+/// \ingroup CPPHighAPI
+/// \brief Interface for Ellipse feature.
+class SketchAPI_Ellipse : public SketchAPI_SketchEntity
+{
+public:
+  /// Constructor without values.
+  SKETCHAPI_EXPORT
+  explicit SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                    double theCenterX, double theCenterY,
+                    double theFocusX, double theFocusY,
+                    double theMinorRadius);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                    const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
+                    double theMinorRadius);
+
+  /// Constructor with external.
+  SKETCHAPI_EXPORT
+  SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                    const ModelHighAPI_Selection& theExternal);
+
+  /// Constructor with external.
+  SKETCHAPI_EXPORT
+  SketchAPI_Ellipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                    const std::string& theExternalName);
+
+  /// Destructor.
+  SKETCHAPI_EXPORT
+  virtual ~SketchAPI_Ellipse();
+
+  INTERFACE_10(SketchPlugin_Ellipse::ID(),
+               center, SketchPlugin_Ellipse::CENTER_ID(),
+               GeomDataAPI_Point2D, /** Center point */,
+               firstFocus, SketchPlugin_Ellipse::FIRST_FOCUS_ID(),
+               GeomDataAPI_Point2D, /** Focus in positive direction of a major axis */,
+               secondFocus, SketchPlugin_Ellipse::SECOND_FOCUS_ID(),
+               GeomDataAPI_Point2D, /** Focus in negative direction of a major axis */,
+               majorAxisNegative, SketchPlugin_Ellipse::MAJOR_AXIS_START_ID(),
+               GeomDataAPI_Point2D, /** Start point of major axis */,
+               majorAxisPositive, SketchPlugin_Ellipse::MAJOR_AXIS_END_ID(),
+               GeomDataAPI_Point2D, /** End point of major axis */,
+               minorAxisNegative, SketchPlugin_Ellipse::MINOR_AXIS_START_ID(),
+               GeomDataAPI_Point2D, /** Start point of minor axis */,
+               minorAxisPositive, SketchPlugin_Ellipse::MINOR_AXIS_END_ID(),
+               GeomDataAPI_Point2D, /** End point of minor axis */,
+               majorRadius, SketchPlugin_Ellipse::MAJOR_RADIUS_ID(),
+               ModelAPI_AttributeDouble, /** Major radius */,
+               minorRadius, SketchPlugin_Ellipse::MINOR_RADIUS_ID(),
+               ModelAPI_AttributeDouble, /** Minor radius */,
+               external, SketchPlugin_Ellipse::EXTERNAL_ID(),
+               ModelAPI_AttributeSelection, /** External */)
+
+  /// Set by center, focus and radius.
+  SKETCHAPI_EXPORT
+  void setByCenterFocusAndRadius(double theCenterX, double theCenterY,
+                                 double theFocusX, double theFocusY,
+                                 double theMinorRadius);
+
+  /// Set by center, focus and radius.
+  SKETCHAPI_EXPORT
+  void setByCenterFocusAndRadius(const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+                                 const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
+                                 double theMinorRadius);
+
+  /// Set by external.
+  SKETCHAPI_EXPORT
+  void setByExternal(const ModelHighAPI_Selection& theExternal);
+
+  /// Set by external name.
+  SKETCHAPI_EXPORT
+  void setByExternalName(const std::string& theExternalName);
+
+  /// Set center.
+  SKETCHAPI_EXPORT
+  void setCenter(double theX, double theY);
+
+  /// Set center.
+  SKETCHAPI_EXPORT
+  void setCenter(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter);
+
+  /// Set focus.
+  SKETCHAPI_EXPORT
+  void setFocus(double theX, double theY);
+
+  /// Set focus.
+  SKETCHAPI_EXPORT
+  void setFocus(const std::shared_ptr<GeomAPI_Pnt2d> & theCenter);
+
+  /// Set radius.
+  SKETCHAPI_EXPORT
+  void setMinorRadius(double theRadius);
+
+  /// Return major axis of the ellipse
+  SKETCHAPI_EXPORT
+  ModelHighAPI_Selection majorAxis() const;
+
+  /// Return minor axis of the ellipse
+  SKETCHAPI_EXPORT
+  ModelHighAPI_Selection minorAxis() const;
+
+  /// Dump wrapped feature
+  SKETCHAPI_EXPORT
+  virtual void dump(ModelHighAPI_Dumper& theDumper) const;
+};
+
+/// Pointer on Ellipse object.
+typedef std::shared_ptr<SketchAPI_Ellipse> EllipsePtr;
+
+#endif // SketchPlugin_Ellipse_H_
diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.cpp b/src/SketchAPI/SketchAPI_MacroEllipse.cpp
new file mode 100644 (file)
index 0000000..ded0f75
--- /dev/null
@@ -0,0 +1,154 @@
+// 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_MacroEllipse.h"
+
+#include <GeomAPI_Pnt2d.h>
+
+#include <ModelHighAPI_RefAttr.h>
+#include <ModelHighAPI_Tools.h>
+
+SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature)
+: SketchAPI_SketchEntity(theFeature)
+{
+  initialize();
+}
+
+SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                               double theX1, double theY1,
+                                               double theX2, double theY2,
+                                               double theX3, double theY3,
+                                               bool byCenter)
+  : SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    if (byCenter)
+      setByCenterAndPassedPoints();
+    else
+      setByMajorAxisAndPassedPoint();
+
+    initializePoints(theX1, theY1, theX2, theY2, theX3, theY3);
+  }
+}
+
+SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+                                               bool byCenter)
+  : SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    if (byCenter)
+      setByCenterAndPassedPoints();
+    else
+      setByMajorAxisAndPassedPoint();
+
+    initializePoints(thePoint1, thePoint2, thePoint3);
+  }
+}
+
+SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                                               const ModelHighAPI_RefAttr&           thePoint1Ref,
+                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                                               const ModelHighAPI_RefAttr&           thePoint2Ref,
+                                               const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+                                               const ModelHighAPI_RefAttr&           thePoint3Ref,
+                                               bool byCenter)
+  : SketchAPI_SketchEntity(theFeature)
+{
+  if (initialize()) {
+    if (byCenter)
+      setByCenterAndPassedPoints();
+    else
+      setByMajorAxisAndPassedPoint();
+
+    initializePoints(thePoint1, thePoint1Ref, thePoint2, thePoint2Ref, thePoint3, thePoint3Ref);
+  }
+}
+
+SketchAPI_MacroEllipse::~SketchAPI_MacroEllipse()
+{
+}
+
+void SketchAPI_MacroEllipse::setByCenterAndPassedPoints()
+{
+  fillAttribute(SketchPlugin_MacroEllipse::ELLIPSE_TYPE_BY_CENTER_AXIS_POINT(), myellipseType);
+}
+
+void SketchAPI_MacroEllipse::setByMajorAxisAndPassedPoint()
+{
+  fillAttribute(SketchPlugin_MacroEllipse::ELLIPSE_TYPE_BY_AXIS_AND_POINT(), myellipseType);
+}
+
+void SketchAPI_MacroEllipse::initializePoints(double theX1, double theY1,
+                                              double theX2, double theY2,
+                                              double theX3, double theY3)
+{
+  fillAttribute(majorAxisNegativePoint(), theX1, theY1);
+  fillAttribute(majorAxisPositivePoint(), theX2, theY2);
+  fillAttribute(passedPoint(), theX3, theY3);
+
+  execute();
+}
+
+void SketchAPI_MacroEllipse::initializePoints(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                                              const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3)
+{
+  fillAttribute(thePoint1, mymajorAxisNegativePoint);
+  fillAttribute(thePoint2, mymajorAxisPositivePoint);
+  fillAttribute(thePoint3, mypassedPoint);
+
+  execute();
+}
+
+static void fillAttribute(const std::shared_ptr<GeomAPI_Pnt2d>& thePoint,
+                          const ModelHighAPI_RefAttr& thePointRef,
+                          std::shared_ptr<GeomDataAPI_Point2D> thePointAttr,
+                          AttributeRefAttrPtr thePointRefAttr)
+{
+  GeomPnt2dPtr aPoint = thePoint;
+  if (!thePointRef.isEmpty()) {
+    fillAttribute(thePointRef, thePointRefAttr);
+    std::shared_ptr<GeomDataAPI_Point2D> anAttrPnt =
+        std::dynamic_pointer_cast<GeomDataAPI_Point2D>(thePointRefAttr->attr());
+    if (anAttrPnt)
+      aPoint = anAttrPnt->pnt();
+  }
+  fillAttribute(aPoint, thePointAttr);
+}
+
+void SketchAPI_MacroEllipse::initializePoints(
+    const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint1,
+    const ModelHighAPI_RefAttr&           theMajorAxisPoint1Ref,
+    const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint2,
+    const ModelHighAPI_RefAttr&           theMajorAxisPoint2Ref,
+    const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+    const ModelHighAPI_RefAttr&           thePassedPointRef)
+{
+  fillAttribute(theMajorAxisPoint1, theMajorAxisPoint1Ref,
+                mymajorAxisNegativePoint, mymajorAxisNegativePointRef);
+  fillAttribute(theMajorAxisPoint2, theMajorAxisPoint2Ref,
+                mymajorAxisPositivePoint, mymajorAxisPositivePointRef);
+  fillAttribute(thePassedPoint, thePassedPointRef, mypassedPoint, mypassedPointRef);
+
+  execute();
+}
diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.h b/src/SketchAPI/SketchAPI_MacroEllipse.h
new file mode 100644 (file)
index 0000000..6f74bbc
--- /dev/null
@@ -0,0 +1,119 @@
+// 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
+//
+
+#ifndef SketchAPI_MacroEllipse_H_
+#define SketchAPI_MacroEllipse_H_
+
+#include "SketchAPI.h"
+#include "SketchAPI_SketchEntity.h"
+
+#include <SketchPlugin_MacroEllipse.h>
+
+class ModelHighAPI_RefAttr;
+
+/// \class SketchAPI_MacroEllipse
+/// \ingroup CPPHighAPI
+/// \brief Interface for Ellipse feature.
+class SketchAPI_MacroEllipse: public SketchAPI_SketchEntity
+{
+public:
+  /// Constructor without values.
+  SKETCHAPI_EXPORT
+  explicit SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                         double theX1, double theY1,
+                         double theX2, double theY2,
+                         double theX3, double theY3,
+                         bool byCenter = true);
+
+  /// Constructor with values.
+  SKETCHAPI_EXPORT
+  SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+                         bool byCenter = true);
+
+  /// Constructor with values and/or references.
+  SKETCHAPI_EXPORT
+  SketchAPI_MacroEllipse(const std::shared_ptr<ModelAPI_Feature>& theFeature,
+                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint1,
+                         const ModelHighAPI_RefAttr&           thePoint1Ref,
+                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint2,
+                         const ModelHighAPI_RefAttr&           thePoint2Ref,
+                         const std::shared_ptr<GeomAPI_Pnt2d>& thePoint3,
+                         const ModelHighAPI_RefAttr&           thePoint3Ref,
+                         bool byCenter = true);
+
+  /// Destructor.
+  SKETCHAPI_EXPORT
+  virtual ~SketchAPI_MacroEllipse();
+
+  INTERFACE_9(SketchPlugin_MacroEllipse::ID(),
+              ellipseType, SketchPlugin_MacroEllipse::ELLIPSE_TYPE(),
+              ModelAPI_AttributeString, /** Ellipse type */,
+              centerPoint, SketchPlugin_MacroEllipse::FIRST_POINT_ID(),
+              GeomDataAPI_Point2D, /** Center point */,
+              centerPointRef, SketchPlugin_MacroEllipse::FIRST_POINT_REF_ID(),
+              ModelAPI_AttributeRefAttr, /** Reference to a center point */,
+              majorAxisNegativePoint, SketchPlugin_MacroEllipse::FIRST_POINT_ID(),
+              GeomDataAPI_Point2D, /** Major axis negative point point */,
+              majorAxisNegativePointRef, SketchPlugin_MacroEllipse::FIRST_POINT_REF_ID(),
+              ModelAPI_AttributeRefAttr, /** Reference to the negative point on a major axis */,
+              majorAxisPositivePoint, SketchPlugin_MacroEllipse::SECOND_POINT_ID(),
+              GeomDataAPI_Point2D, /** Major axis positive point point */,
+              majorAxisPositivePointRef, SketchPlugin_MacroEllipse::SECOND_POINT_REF_ID(),
+              ModelAPI_AttributeRefAttr, /** Reference to the positive point on a major axis */,
+              passedPoint, SketchPlugin_MacroEllipse::PASSED_POINT_ID(),
+              GeomDataAPI_Point2D, /** Passed point */,
+              passedPointRef, SketchPlugin_MacroEllipse::PASSED_POINT_REF_ID(),
+              ModelAPI_AttributeRefAttr, /** Reference to a passed point */)
+
+private:
+  /// Set flag of creation by center, major semi-axis and passed point.
+  void setByCenterAndPassedPoints();
+  /// Set flag of creation by major axis and passed point.
+  void setByMajorAxisAndPassedPoint();
+
+  /// Set points of ellipse.
+  void initializePoints(double theMajorAxisX1, double theMajorAxisY1,
+                        double theMajorAxisX2, double theMajorAxisY2,
+                        double thePassedX, double thePassedY);
+
+  /// Set points of ellipse.
+  void initializePoints(const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint1,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint2,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint);
+
+  /// Set points of ellipse.
+  void initializePoints(const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint1,
+                        const ModelHighAPI_RefAttr&           theMajorAxisPoint1Ref,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& theMajorAxisPoint2,
+                        const ModelHighAPI_RefAttr&           theMajorAxisPoint2Ref,
+                        const std::shared_ptr<GeomAPI_Pnt2d>& thePassedPoint,
+                        const ModelHighAPI_RefAttr&           thePassedPointRef);
+};
+
+/// Pointer on Circle object.
+typedef std::shared_ptr<SketchAPI_MacroEllipse> MacroEllipsePtr;
+
+#endif // SketchAPI_MacroEllipse_H_
index e1aabba8adf3eac43c6e913336d0c696425389bc..4f8b129563b265228e19941ac8b96375971d681f 100644 (file)
 #include <ModelHighAPI_Tools.h>
 //--------------------------------------------------------------------------------------
 #include "SketchAPI_Arc.h"
-#include "SketchAPI_MacroArc.h"
 #include "SketchAPI_Circle.h"
+#include "SketchAPI_Ellipse.h"
 #include "SketchAPI_IntersectionPoint.h"
 #include "SketchAPI_Line.h"
+#include "SketchAPI_MacroArc.h"
 #include "SketchAPI_MacroCircle.h"
+#include "SketchAPI_MacroEllipse.h"
 #include "SketchAPI_Mirror.h"
 #include "SketchAPI_Point.h"
 #include "SketchAPI_Projection.h"
@@ -466,7 +468,6 @@ std::shared_ptr<SketchAPI_Circle>
 
 std::shared_ptr<SketchAPI_Circle> SketchAPI_Sketch::addCircle(const std::string & theExternalName)
 {
-  // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Circle::ID());
   return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName));
@@ -561,12 +562,86 @@ std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const ModelHighAPI_Selec
 
 std::shared_ptr<SketchAPI_Arc> SketchAPI_Sketch::addArc(const std::string & theExternalName)
 {
-  // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary?
   std::shared_ptr<ModelAPI_Feature> aFeature =
     compositeFeature()->addFeature(SketchPlugin_Arc::ID());
   return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName));
 }
 
+//--------------------------------------------------------------------------------------
+std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
+    double theCenterX, double theCenterY,
+    double theFocusX, double theFocusY,
+    double theMinorRadius)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
+  return EllipsePtr(new SketchAPI_Ellipse(aFeature,
+      theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius));
+}
+
+std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
+    const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+    const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
+    double theMinorRadius)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
+  return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius));
+}
+
+std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
+    double thePoint1X, double thePoint1Y,
+    double thePoint2X, double thePoint2Y,
+    double thePassedX, double thePassedY,
+    bool isPoint1Center)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
+  return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature,
+      thePoint1X, thePoint1Y, thePoint2X, thePoint1Y, thePassedX, thePassedY, isPoint1Center));
+}
+
+std::shared_ptr<SketchAPI_MacroEllipse> SketchAPI_Sketch::addEllipse(
+    const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint1,
+    const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint2,
+    const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePassedPoint,
+    bool isPoint1Center)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID());
+  MacroEllipsePtr anEllipse;
+  if (thePoint1.second.isEmpty() &&
+      thePoint2.second.isEmpty() &&
+      thePassedPoint.second.isEmpty()) {
+    anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
+        thePoint1.first, thePoint2.first, thePassedPoint.first, isPoint1Center));
+  }
+  else {
+    anEllipse.reset(new SketchAPI_MacroEllipse(aFeature,
+        thePoint1.first, thePoint1.second,
+        thePoint2.first, thePoint2.second,
+        thePassedPoint.first, thePassedPoint.second,
+        isPoint1Center));
+  }
+  return anEllipse;
+}
+
+std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
+    const ModelHighAPI_Selection & theExternal)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
+  return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal));
+}
+
+std::shared_ptr<SketchAPI_Ellipse> SketchAPI_Sketch::addEllipse(
+    const std::string & theExternalName)
+{
+  std::shared_ptr<ModelAPI_Feature> aFeature =
+      compositeFeature()->addFeature(SketchPlugin_Ellipse::ID());
+  return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName));
+}
+
 //--------------------------------------------------------------------------------------
 std::shared_ptr<SketchAPI_Projection> SketchAPI_Sketch::addProjection(
     const ModelHighAPI_Selection & theExternalFeature,
index 180ea15bb7f2f7a7ac6d8e394e712bb28234c6a3..726250f6dc08c36b93a7b9f9bc7084258fef46ca 100644 (file)
@@ -42,6 +42,8 @@ class SketchAPI_Arc;
 class SketchAPI_MacroArc;
 class SketchAPI_Circle;
 class SketchAPI_MacroCircle;
+class SketchAPI_Ellipse;
+class SketchAPI_MacroEllipse;
 class SketchAPI_IntersectionPoint;
 class SketchAPI_Line;
 class SketchAPI_Mirror;
@@ -264,6 +266,39 @@ public:
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Arc> addArc(const std::string & theExternalName);
 
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(
+      double theCenterX, double theCenterY,
+      double theFocusX, double theFocusY,
+      double theMinorRadius);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(
+      const std::shared_ptr<GeomAPI_Pnt2d>& theCenter,
+      const std::shared_ptr<GeomAPI_Pnt2d>& theFocus,
+      double theRadius);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
+      double thePoint1X, double thePoint1Y,
+      double thePoint2X, double thePoint2Y,
+      double thePassedX, double thePassedY,
+      bool isPoint1Center = true);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_MacroEllipse> addEllipse(
+      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint1,
+      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePoint2,
+      const std::pair<std::shared_ptr<GeomAPI_Pnt2d>, ModelHighAPI_RefAttr>& thePassedPoint,
+      bool isPoint1Center = true);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(const ModelHighAPI_Selection & theExternal);
+  /// Add ellipse
+  SKETCHAPI_EXPORT
+  std::shared_ptr<SketchAPI_Ellipse> addEllipse(const std::string & theExternalName);
+
   /// Add projection
   SKETCHAPI_EXPORT
   std::shared_ptr<SketchAPI_Projection> addProjection(
index 808ac012bec5144211356681803c203a2a2fcd9a..5c7202268073dcc4c6ccf77d3c07d332229863ea 100644 (file)
@@ -20,6 +20,7 @@
 #include "SketchAPI_SketchEntity.h"
 #include <SketchAPI_Arc.h>
 #include <SketchAPI_Circle.h>
+#include <SketchAPI_Ellipse.h>
 #include <SketchAPI_IntersectionPoint.h>
 #include <SketchAPI_Line.h>
 #include <SketchAPI_Point.h>
@@ -29,6 +30,7 @@
 
 #include <SketchPlugin_Arc.h>
 #include <SketchPlugin_Circle.h>
+#include <SketchPlugin_Ellipse.h>
 #include <SketchPlugin_IntersectionPoint.h>
 #include <SketchPlugin_Line.h>
 #include <SketchPlugin_Point.h>
@@ -96,6 +98,8 @@ SketchAPI_SketchEntity::wrap(const std::list<std::shared_ptr<ModelAPI_Feature> >
       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_Point::ID())
       aResult.push_back(std::shared_ptr<SketchAPI_SketchEntity>(new SketchAPI_Point(*anIt)));
     else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID())
index 1f8748712ddff145543c7bf32a1992777962fffc..fa19b36c252e37cd72f9a9d25e77d37a66c4d5b3 100644 (file)
@@ -27,6 +27,8 @@
   #include "SketchAPI_MacroArc.h"
   #include "SketchAPI_Circle.h"
   #include "SketchAPI_MacroCircle.h"
+  #include "SketchAPI_Ellipse.h"
+  #include "SketchAPI_MacroEllipse.h"
   #include "SketchAPI_Constraint.h"
   #include "SketchAPI_ConstraintAngle.h"
   #include "SketchAPI_IntersectionPoint.h"
index 1c5f5fadd7aaf154197793d4987b4a48210264da..6e88c8191102c0c6e4c7fc1b578a6e81dc88a3a7 100644 (file)
@@ -34,6 +34,8 @@
 #include <ModelAPI_Session.h>
 #include <ModelAPI_Validator.h>
 
+#include <cmath>
+
 static const double tolerance = 1e-7;
 
 
@@ -54,6 +56,13 @@ void SketchPlugin_Ellipse::initDerivedClassAttributes()
   data()->addAttribute(MAJOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
   data()->addAttribute(MINOR_RADIUS_ID(), ModelAPI_AttributeDouble::typeId());
 
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), SECOND_FOCUS_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MAJOR_AXIS_START_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MAJOR_AXIS_END_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MINOR_AXIS_START_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MINOR_AXIS_END_ID());
+  ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), MAJOR_RADIUS_ID());
+
   data()->addAttribute(EXTERNAL_ID(), ModelAPI_AttributeSelection::typeId());
   ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), EXTERNAL_ID());
 }
@@ -140,19 +149,16 @@ bool SketchPlugin_Ellipse::fillCharacteristicPoints()
   std::shared_ptr<GeomDataAPI_Point2D> aFocusAttr =
       std::dynamic_pointer_cast<GeomDataAPI_Point2D>(data()->attribute(FIRST_FOCUS_ID()));
 
-  AttributeDoublePtr aMajorRadiusAttr = real(MAJOR_RADIUS_ID());
   AttributeDoublePtr aMinorRadiusAttr = real(MINOR_RADIUS_ID());
 
   if (!aCenterAttr->isInitialized() ||
       !aFocusAttr->isInitialized() ||
-      !aMajorRadiusAttr->isInitialized() ||
       !aMinorRadiusAttr->isInitialized()) {
     return false;
   }
 
-  double aMajorRadius = aMajorRadiusAttr->value();
   double aMinorRadius = aMinorRadiusAttr->value();
-  if (aMajorRadius < tolerance || aMinorRadius < tolerance) {
+  if (aMinorRadius < tolerance) {
     return false;
   }
 
@@ -162,6 +168,12 @@ bool SketchPlugin_Ellipse::fillCharacteristicPoints()
   GeomDir2dPtr aMajorDir2d(new GeomAPI_Dir2d(aFocus2d->x() - aCenter2d->x(),
     aFocus2d->y() - aCenter2d->y()));
   GeomDir2dPtr aMinorDir2d(new GeomAPI_Dir2d(-aMajorDir2d->y(), aMajorDir2d->x()));
+
+  AttributeDoublePtr aMajorRadiusAttr = real(MAJOR_RADIUS_ID());
+  double aFocalDist = aCenter2d->distance(aFocus2d);
+  double aMajorRadius = sqrt(aFocalDist * aFocalDist + aMinorRadius * aMinorRadius);
+  aMajorRadiusAttr->setValue(aMajorRadius);
+
   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(SECOND_FOCUS_ID()))
     ->setValue(2.0 * aCenter2d->x() - aFocus2d->x(), 2.0 * aCenter2d->y() - aFocus2d->y());
   std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(MAJOR_AXIS_START_ID()))
index f46286af69e6be9d1e958e4a344074d122f5a71b..0b5ecf95c263b582edce9defe56443857e790a3b 100644 (file)
@@ -122,7 +122,8 @@ void SketchPlugin_MacroEllipse::attributeChanged(const std::string& theID)
 
       AttributeRefAttrPtr aPointRef = refattr(aPointRefName[aPntIndex]);
       // calculate ellipse parameters
-      GeomPnt2dPtr aPassedPoint;
+      GeomPnt2dPtr aPassedPoint =
+          std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aPointAttr)->pnt();
       GeomShapePtr aTangentCurve;
       SketchPlugin_Tools::convertRefAttrToPointOrTangentCurve(
         aPointRef, aPointAttr, aTangentCurve, aPassedPoint);
@@ -165,9 +166,6 @@ void SketchPlugin_MacroEllipse::attributeChanged(const std::string& theID)
     AttributeDoublePtr aMinorRadiusAttr = real(MINOR_RADIUS_ID());
 
     bool aWasBlocked = data()->blockSendAttributeUpdated(true);
-    // center attribute is used in processEvent() to set reference to reentrant arc
-////    std::dynamic_pointer_cast<GeomDataAPI_Point2D>(attribute(FIRST_POINT_ID()))
-////        ->setValue(myCenter);
     aMajorRadiusAttr->setValue(myMajorRadius);
     aMinorRadiusAttr->setValue(myMinorRadius);
     data()->blockSendAttributeUpdated(aWasBlocked, false);