From d74c5f916e2c7d0eb1ee2fa128f0458c3d22675f Mon Sep 17 00:00:00 2001 From: azv Date: Fri, 13 Sep 2019 13:01:31 +0300 Subject: [PATCH] Task 2.12. New entities: ellipses and arcs of ellipses (issue #3003) SketchAPI for Ellipse feature. --- src/ModelHighAPI/ModelHighAPI.i | 25 +- src/ModelHighAPI/ModelHighAPI_RefAttr.cpp | 2 +- src/PythonAPI/model/sketcher/tools.py | 3 + src/SketchAPI/CMakeLists.txt | 12 +- src/SketchAPI/SketchAPI.i | 221 +++++++++++++----- src/SketchAPI/SketchAPI_Ellipse.cpp | 169 ++++++++++++++ src/SketchAPI/SketchAPI_Ellipse.h | 146 ++++++++++++ src/SketchAPI/SketchAPI_MacroEllipse.cpp | 154 ++++++++++++ src/SketchAPI/SketchAPI_MacroEllipse.h | 119 ++++++++++ src/SketchAPI/SketchAPI_Sketch.cpp | 81 ++++++- src/SketchAPI/SketchAPI_Sketch.h | 35 +++ src/SketchAPI/SketchAPI_SketchEntity.cpp | 4 + src/SketchAPI/SketchAPI_swig.h | 2 + src/SketchPlugin/SketchPlugin_Ellipse.cpp | 20 +- .../SketchPlugin_MacroEllipse.cpp | 6 +- 15 files changed, 922 insertions(+), 77 deletions(-) create mode 100644 src/SketchAPI/SketchAPI_Ellipse.cpp create mode 100644 src/SketchAPI/SketchAPI_Ellipse.h create mode 100644 src/SketchAPI/SketchAPI_MacroEllipse.cpp create mode 100644 src/SketchAPI/SketchAPI_MacroEllipse.h diff --git a/src/ModelHighAPI/ModelHighAPI.i b/src/ModelHighAPI/ModelHighAPI.i index f26df1e5d..72971cc01 100644 --- a/src/ModelHighAPI/ModelHighAPI.i +++ b/src/ModelHighAPI/ModelHighAPI.i @@ -98,10 +98,22 @@ std::shared_ptr * temp_attribute; std::shared_ptr * temp_object; std::shared_ptr * 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(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 *), 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); @@ -112,7 +124,7 @@ } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_object, $descriptor(std::shared_ptr *), 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); @@ -123,7 +135,7 @@ } else if ((SWIG_ConvertPtrAndOwn($input, (void **)&temp_interface, $descriptor(std::shared_ptr *), 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); @@ -134,7 +146,7 @@ } 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; } } @@ -239,6 +251,11 @@ $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; %template(SelectionListList) std::list >; diff --git a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp index 30c15a924..03548d252 100644 --- a/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp +++ b/src/ModelHighAPI/ModelHighAPI_RefAttr.cpp @@ -79,7 +79,7 @@ void ModelHighAPI_RefAttr::appendToList( //-------------------------------------------------------------------------------------- bool ModelHighAPI_RefAttr::isEmpty() const { - return !(myAttribute && myObject); + return !(myAttribute || myObject); } //-------------------------------------------------------------------------------------- diff --git a/src/PythonAPI/model/sketcher/tools.py b/src/PythonAPI/model/sketcher/tools.py index 7bb8f5362..0d4890dda 100644 --- a/src/PythonAPI/model/sketcher/tools.py +++ b/src/PythonAPI/model/sketcher/tools.py @@ -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")) diff --git a/src/SketchAPI/CMakeLists.txt b/src/SketchAPI/CMakeLists.txt index b93b91f9e..ff40200ab 100644 --- a/src/SketchAPI/CMakeLists.txt +++ b/src/SketchAPI/CMakeLists.txt @@ -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 ) diff --git a/src/SketchAPI/SketchAPI.i b/src/SketchAPI/SketchAPI.i index 36732e2c2..9cde425da 100644 --- a/src/SketchAPI/SketchAPI.i +++ b/src/SketchAPI/SketchAPI.i @@ -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 >; %template(EntityList) std::list >; %template(SketchPointList) std::list >; +// std::pair -> [] +%template(PointRefAttrPair) std::pair, ModelHighAPI_RefAttr>; %typecheck(SWIG_TYPECHECK_POINTER) std::shared_ptr, const std::shared_ptr & { std::shared_ptr * temp_feature; @@ -120,63 +125,6 @@ } } -%typemap(in) const ModelHighAPI_RefAttr & (ModelHighAPI_RefAttr temp) { - std::shared_ptr * temp_attribute; - std::shared_ptr * temp_object; - std::shared_ptr * 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(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 *), 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 *), 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 *), 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::list > temp) { std::shared_ptr * temp_object; std::shared_ptr * temp_interface; @@ -224,6 +172,163 @@ } } +%typecheck(SWIG_TYPECHECK_POINTER) std::pair, ModelHighAPI_RefAttr>, const std::pair, ModelHighAPI_RefAttr> & { + std::shared_ptr * temp_attribute; + std::shared_ptr * temp_object; + std::shared_ptr * temp_interface; + ModelHighAPI_Selection* temp_selection; + std::pair, ModelHighAPI_RefAttr>* temp_pair; + std::shared_ptr * temp_point; + ModelHighAPI_RefAttr temp_refattr; + int newmem = 0; + std::list 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::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 *), 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 *), 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 *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_interface) { + $1 = 1; + } else { + $1 = 0; + } + } else + if ((SWIG_ConvertPtrAndOwn(item, (void **)&temp_pair, $descriptor(std::pair, 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 *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + if (temp_point) { + $1 = 1; + } else { + $1 = 0; + } + } else { + $1 = 0; + } + } +} + +%typemap(in) const std::pair, ModelHighAPI_RefAttr> & (std::pair, ModelHighAPI_RefAttr> temp) { + std::shared_ptr * temp_attribute; + std::shared_ptr * temp_object; + std::shared_ptr * temp_interface; + ModelHighAPI_Selection* temp_selection; + std::pair, ModelHighAPI_RefAttr>* temp_pair; + std::shared_ptr * temp_point = 0; + ModelHighAPI_RefAttr temp_refattr; + int newmem = 0; + std::list 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::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(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 *), 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 *), 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 *), 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, 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 *), SWIG_POINTER_EXCEPTION, &newmem)) == 0) { + // fall through + } + } + + if (temp_point || !temp_refattr.isEmpty()) { + if (temp_point) { + temp = std::pair, ModelHighAPI_RefAttr>(*temp_point, temp_refattr); + } else { + temp = std::pair, ModelHighAPI_RefAttr>(std::shared_ptr(), 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, ModelHighAPI_RefAttr> & {} + // all supported interfaces (the order is very important according dependencies: base class first) %include "SketchAPI_SketchEntity.h" %include "SketchAPI_Point.h" @@ -233,6 +338,8 @@ %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 index 000000000..40c5c4ab3 --- /dev/null +++ b/src/SketchAPI/SketchAPI_Ellipse.cpp @@ -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 + +#include +#include +#include + +SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr & theFeature) + : SketchAPI_SketchEntity(theFeature) +{ + initialize(); +} + +SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr& 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& theFeature, + const std::shared_ptr& theCenter, + const std::shared_ptr& theFocus, + double theMinorRadius) +: SketchAPI_SketchEntity(theFeature) +{ + if(initialize()) { + setByCenterFocusAndRadius(theCenter, theFocus, theMinorRadius); + } +} + +SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theExternal) + : SketchAPI_SketchEntity(theFeature) +{ + if (initialize()) { + setByExternal(theExternal); + } +} + +SketchAPI_Ellipse::SketchAPI_Ellipse(const std::shared_ptr& 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& theCenter, + const std::shared_ptr& 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 & 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 & 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 index 000000000..13e344369 --- /dev/null +++ b/src/SketchAPI/SketchAPI_Ellipse.h @@ -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 + +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& theFeature); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Ellipse(const std::shared_ptr& theFeature, + double theCenterX, double theCenterY, + double theFocusX, double theFocusY, + double theMinorRadius); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_Ellipse(const std::shared_ptr& theFeature, + const std::shared_ptr& theCenter, + const std::shared_ptr& theFocus, + double theMinorRadius); + + /// Constructor with external. + SKETCHAPI_EXPORT + SketchAPI_Ellipse(const std::shared_ptr& theFeature, + const ModelHighAPI_Selection& theExternal); + + /// Constructor with external. + SKETCHAPI_EXPORT + SketchAPI_Ellipse(const std::shared_ptr& 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& theCenter, + const std::shared_ptr& 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 & theCenter); + + /// Set focus. + SKETCHAPI_EXPORT + void setFocus(double theX, double theY); + + /// Set focus. + SKETCHAPI_EXPORT + void setFocus(const std::shared_ptr & 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 EllipsePtr; + +#endif // SketchPlugin_Ellipse_H_ diff --git a/src/SketchAPI/SketchAPI_MacroEllipse.cpp b/src/SketchAPI/SketchAPI_MacroEllipse.cpp new file mode 100644 index 000000000..ded0f75ba --- /dev/null +++ b/src/SketchAPI/SketchAPI_MacroEllipse.cpp @@ -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 + +#include +#include + +SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& theFeature) +: SketchAPI_SketchEntity(theFeature) +{ + initialize(); +} + +SketchAPI_MacroEllipse::SketchAPI_MacroEllipse(const std::shared_ptr& 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& theFeature, + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& 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& theFeature, + const std::shared_ptr& thePoint1, + const ModelHighAPI_RefAttr& thePoint1Ref, + const std::shared_ptr& thePoint2, + const ModelHighAPI_RefAttr& thePoint2Ref, + const std::shared_ptr& 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& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3) +{ + fillAttribute(thePoint1, mymajorAxisNegativePoint); + fillAttribute(thePoint2, mymajorAxisPositivePoint); + fillAttribute(thePoint3, mypassedPoint); + + execute(); +} + +static void fillAttribute(const std::shared_ptr& thePoint, + const ModelHighAPI_RefAttr& thePointRef, + std::shared_ptr thePointAttr, + AttributeRefAttrPtr thePointRefAttr) +{ + GeomPnt2dPtr aPoint = thePoint; + if (!thePointRef.isEmpty()) { + fillAttribute(thePointRef, thePointRefAttr); + std::shared_ptr anAttrPnt = + std::dynamic_pointer_cast(thePointRefAttr->attr()); + if (anAttrPnt) + aPoint = anAttrPnt->pnt(); + } + fillAttribute(aPoint, thePointAttr); +} + +void SketchAPI_MacroEllipse::initializePoints( + const std::shared_ptr& theMajorAxisPoint1, + const ModelHighAPI_RefAttr& theMajorAxisPoint1Ref, + const std::shared_ptr& theMajorAxisPoint2, + const ModelHighAPI_RefAttr& theMajorAxisPoint2Ref, + const std::shared_ptr& 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 index 000000000..6f74bbc98 --- /dev/null +++ b/src/SketchAPI/SketchAPI_MacroEllipse.h @@ -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 + +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& theFeature); + + /// Constructor with values. + SKETCHAPI_EXPORT + SketchAPI_MacroEllipse(const std::shared_ptr& 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& theFeature, + const std::shared_ptr& thePoint1, + const std::shared_ptr& thePoint2, + const std::shared_ptr& thePoint3, + bool byCenter = true); + + /// Constructor with values and/or references. + SKETCHAPI_EXPORT + SketchAPI_MacroEllipse(const std::shared_ptr& theFeature, + const std::shared_ptr& thePoint1, + const ModelHighAPI_RefAttr& thePoint1Ref, + const std::shared_ptr& thePoint2, + const ModelHighAPI_RefAttr& thePoint2Ref, + const std::shared_ptr& 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& theMajorAxisPoint1, + const std::shared_ptr& theMajorAxisPoint2, + const std::shared_ptr& thePassedPoint); + + /// Set points of ellipse. + void initializePoints(const std::shared_ptr& theMajorAxisPoint1, + const ModelHighAPI_RefAttr& theMajorAxisPoint1Ref, + const std::shared_ptr& theMajorAxisPoint2, + const ModelHighAPI_RefAttr& theMajorAxisPoint2Ref, + const std::shared_ptr& thePassedPoint, + const ModelHighAPI_RefAttr& thePassedPointRef); +}; + +/// Pointer on Circle object. +typedef std::shared_ptr MacroEllipsePtr; + +#endif // SketchAPI_MacroEllipse_H_ diff --git a/src/SketchAPI/SketchAPI_Sketch.cpp b/src/SketchAPI/SketchAPI_Sketch.cpp index e1aabba8a..4f8b12956 100644 --- a/src/SketchAPI/SketchAPI_Sketch.cpp +++ b/src/SketchAPI/SketchAPI_Sketch.cpp @@ -53,11 +53,13 @@ #include //-------------------------------------------------------------------------------------- #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 std::shared_ptr SketchAPI_Sketch::addCircle(const std::string & theExternalName) { - // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary? std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Circle::ID()); return CirclePtr(new SketchAPI_Circle(aFeature, theExternalName)); @@ -561,12 +562,86 @@ std::shared_ptr SketchAPI_Sketch::addArc(const ModelHighAPI_Selec std::shared_ptr SketchAPI_Sketch::addArc(const std::string & theExternalName) { - // TODO(spo): Add constraint SketchConstraintRigid like in PythonAPI. Is it necessary? std::shared_ptr aFeature = compositeFeature()->addFeature(SketchPlugin_Arc::ID()); return ArcPtr(new SketchAPI_Arc(aFeature, theExternalName)); } +//-------------------------------------------------------------------------------------- +std::shared_ptr SketchAPI_Sketch::addEllipse( + double theCenterX, double theCenterY, + double theFocusX, double theFocusY, + double theMinorRadius) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Ellipse::ID()); + return EllipsePtr(new SketchAPI_Ellipse(aFeature, + theCenterX, theCenterY, theFocusX, theFocusY, theMinorRadius)); +} + +std::shared_ptr SketchAPI_Sketch::addEllipse( + const std::shared_ptr& theCenter, + const std::shared_ptr& theFocus, + double theMinorRadius) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Ellipse::ID()); + return EllipsePtr(new SketchAPI_Ellipse(aFeature, theCenter, theFocus, theMinorRadius)); +} + +std::shared_ptr SketchAPI_Sketch::addEllipse( + double thePoint1X, double thePoint1Y, + double thePoint2X, double thePoint2Y, + double thePassedX, double thePassedY, + bool isPoint1Center) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_MacroEllipse::ID()); + return MacroEllipsePtr(new SketchAPI_MacroEllipse(aFeature, + thePoint1X, thePoint1Y, thePoint2X, thePoint1Y, thePassedX, thePassedY, isPoint1Center)); +} + +std::shared_ptr SketchAPI_Sketch::addEllipse( + const std::pair, ModelHighAPI_RefAttr>& thePoint1, + const std::pair, ModelHighAPI_RefAttr>& thePoint2, + const std::pair, ModelHighAPI_RefAttr>& thePassedPoint, + bool isPoint1Center) +{ + std::shared_ptr 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_Sketch::addEllipse( + const ModelHighAPI_Selection & theExternal) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Ellipse::ID()); + return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternal)); +} + +std::shared_ptr SketchAPI_Sketch::addEllipse( + const std::string & theExternalName) +{ + std::shared_ptr aFeature = + compositeFeature()->addFeature(SketchPlugin_Ellipse::ID()); + return EllipsePtr(new SketchAPI_Ellipse(aFeature, theExternalName)); +} + //-------------------------------------------------------------------------------------- std::shared_ptr SketchAPI_Sketch::addProjection( const ModelHighAPI_Selection & theExternalFeature, diff --git a/src/SketchAPI/SketchAPI_Sketch.h b/src/SketchAPI/SketchAPI_Sketch.h index 180ea15bb..726250f6d 100644 --- a/src/SketchAPI/SketchAPI_Sketch.h +++ b/src/SketchAPI/SketchAPI_Sketch.h @@ -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 addArc(const std::string & theExternalName); + /// Add ellipse + SKETCHAPI_EXPORT + std::shared_ptr addEllipse( + double theCenterX, double theCenterY, + double theFocusX, double theFocusY, + double theMinorRadius); + /// Add ellipse + SKETCHAPI_EXPORT + std::shared_ptr addEllipse( + const std::shared_ptr& theCenter, + const std::shared_ptr& theFocus, + double theRadius); + /// Add ellipse + SKETCHAPI_EXPORT + std::shared_ptr addEllipse( + double thePoint1X, double thePoint1Y, + double thePoint2X, double thePoint2Y, + double thePassedX, double thePassedY, + bool isPoint1Center = true); + /// Add ellipse + SKETCHAPI_EXPORT + std::shared_ptr addEllipse( + const std::pair, ModelHighAPI_RefAttr>& thePoint1, + const std::pair, ModelHighAPI_RefAttr>& thePoint2, + const std::pair, ModelHighAPI_RefAttr>& thePassedPoint, + bool isPoint1Center = true); + /// Add ellipse + SKETCHAPI_EXPORT + std::shared_ptr addEllipse(const ModelHighAPI_Selection & theExternal); + /// Add ellipse + SKETCHAPI_EXPORT + std::shared_ptr addEllipse(const std::string & theExternalName); + /// Add projection SKETCHAPI_EXPORT std::shared_ptr addProjection( diff --git a/src/SketchAPI/SketchAPI_SketchEntity.cpp b/src/SketchAPI/SketchAPI_SketchEntity.cpp index 808ac012b..5c7202268 100644 --- a/src/SketchAPI/SketchAPI_SketchEntity.cpp +++ b/src/SketchAPI/SketchAPI_SketchEntity.cpp @@ -20,6 +20,7 @@ #include "SketchAPI_SketchEntity.h" #include #include +#include #include #include #include @@ -29,6 +30,7 @@ #include #include +#include #include #include #include @@ -96,6 +98,8 @@ SketchAPI_SketchEntity::wrap(const std::list > aResult.push_back(std::shared_ptr(new SketchAPI_Arc(*anIt))); else if ((*anIt)->getKind() == SketchPlugin_Circle::ID()) aResult.push_back(std::shared_ptr(new SketchAPI_Circle(*anIt))); + else if ((*anIt)->getKind() == SketchPlugin_Ellipse::ID()) + aResult.push_back(std::shared_ptr(new SketchAPI_Ellipse(*anIt))); else if ((*anIt)->getKind() == SketchPlugin_Point::ID()) aResult.push_back(std::shared_ptr(new SketchAPI_Point(*anIt))); else if ((*anIt)->getKind() == SketchPlugin_IntersectionPoint::ID()) diff --git a/src/SketchAPI/SketchAPI_swig.h b/src/SketchAPI/SketchAPI_swig.h index 1f8748712..fa19b36c2 100644 --- a/src/SketchAPI/SketchAPI_swig.h +++ b/src/SketchAPI/SketchAPI_swig.h @@ -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" diff --git a/src/SketchPlugin/SketchPlugin_Ellipse.cpp b/src/SketchPlugin/SketchPlugin_Ellipse.cpp index 1c5f5fadd..6e88c8191 100644 --- a/src/SketchPlugin/SketchPlugin_Ellipse.cpp +++ b/src/SketchPlugin/SketchPlugin_Ellipse.cpp @@ -34,6 +34,8 @@ #include #include +#include + 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 aFocusAttr = std::dynamic_pointer_cast(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(attribute(SECOND_FOCUS_ID())) ->setValue(2.0 * aCenter2d->x() - aFocus2d->x(), 2.0 * aCenter2d->y() - aFocus2d->y()); std::dynamic_pointer_cast(attribute(MAJOR_AXIS_START_ID())) diff --git a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp index f46286af6..0b5ecf95c 100644 --- a/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp +++ b/src/SketchPlugin/SketchPlugin_MacroEllipse.cpp @@ -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(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(attribute(FIRST_POINT_ID())) -//// ->setValue(myCenter); aMajorRadiusAttr->setValue(myMajorRadius); aMinorRadiusAttr->setValue(myMinorRadius); data()->blockSendAttributeUpdated(aWasBlocked, false); -- 2.39.2