#include <TopoDS_Shape.hxx>
#include <Geom_Circle.hxx>
#include <Geom_Curve.hxx>
+#include <Geom_Ellipse.hxx>
#include <Geom_Line.hxx>
#include <Geom_TrimmedCurve.hxx>
#include <BRep_Tool.hxx>
return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Circle);
}
+bool GeomAPI_Curve::isEllipse() const
+{
+ return !isNull() && MY_CURVE->DynamicType() == STANDARD_TYPE(Geom_Ellipse);
+}
+
std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::getPoint(double theParam)
{
GeomAdaptor_Curve aAdaptor(MY_CURVE, myStart, myEnd);
GEOMAPI_EXPORT
virtual bool isCircle() const;
+ /// Returns whether the curve is elliptic
+ GEOMAPI_EXPORT
+ virtual bool isEllipse() const;
+
/// Returns start parameter of the curve
GEOMAPI_EXPORT
double startParam() const { return myStart; }
aType = 1;
else if (aType != 1)
return false;
- } else if (aEdge.isCircle()) {
+ } else if (aEdge.isCircle() || aEdge.isArc()) {
if (aCount == 1)
aType = 2;
else if (aType != 2)
return false;
- } else if (aEdge.isArc()) {
+ } else if (aEdge.isEllipse()) {
if (aCount == 1)
aType = 3;
else if (aType != 3)
TestConstraintDistanceHorizontal.py
TestConstraintDistanceVertical.py
TestConstraintEqual.py
+ TestConstraintEqualEllipse.py
TestConstraintFixed.py
TestConstraintHorizontal.py
TestConstraintHorizontalValidator.py
#include "SketchPlugin_ConstraintDistance.h"
#include "SketchPlugin_ConstraintRigid.h"
#include "SketchPlugin_ConstraintTangent.h"
+#include "SketchPlugin_Ellipse.h"
#include "SketchPlugin_Fillet.h"
#include "SketchPlugin_Line.h"
#include "SketchPlugin_MacroArc.h"
aType[i] = aFeature->getKind();
if (aFeature->getKind() != SketchPlugin_Line::ID() &&
aFeature->getKind() != SketchPlugin_Circle::ID() &&
- aFeature->getKind() != SketchPlugin_Arc::ID()) {
- theError = "The %1 feature kind of attribute is wrong. It should be %2 or %3 or %4";
+ aFeature->getKind() != SketchPlugin_Arc::ID() &&
+ aFeature->getKind() != SketchPlugin_Ellipse::ID()) {
+ theError = "The %1 feature kind of attribute is wrong. It should be %2 or %3 or %4 or %5";
theError.arg(aFeature->getKind()).arg(SketchPlugin_Line::ID())
- .arg(SketchPlugin_Circle::ID()).arg(SketchPlugin_Arc::ID());
+ .arg(SketchPlugin_Circle::ID()).arg(SketchPlugin_Arc::ID())
+ .arg(SketchPlugin_Ellipse::ID());
// wrong type of attribute
return false;
}
}
- if ((aType[0] == SketchPlugin_Line::ID() || aType[1] == SketchPlugin_Line::ID()) &&
- aType[0] != aType[1]) {
+ bool isOk = aType[0] == aType[1];
+ if (!isOk) {
+ // circle and arc may be equal
+ isOk = (aType[0] == SketchPlugin_Arc::ID() && aType[1] == SketchPlugin_Circle::ID())
+ || (aType[0] == SketchPlugin_Circle::ID() && aType[1] == SketchPlugin_Arc::ID());
+ }
+ if (!isOk) {
+ // ellipse and elliptic arc may be equal
+ // TODO
+ }
+ if (!isOk) {
theError = "Feature with kinds %1 and %2 can not be equal.";
theError.arg(aType[0]).arg(aType[1]);
return false;
--- /dev/null
+# Copyright (C) 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
+#
+
+"""
+ Test constraint "Equal" applied to the pair of ellipses
+"""
+
+from salome.shaper import model
+import math
+
+model.begin()
+partSet = model.moduleDocument()
+Sketch_1 = model.addSketch(partSet, model.defaultPlane("XOY"))
+SketchEllipse_1 = Sketch_1.addEllipse(-27.88698315421018, 6.197107367602265, -8.725072906579975, 15.87998754592604, 11.10896680773502)
+[SketchPoint_1, SketchPoint_2, SketchPoint_3, SketchPoint_4, SketchPoint_5, SketchPoint_6, SketchPoint_7, SketchLine_1, SketchLine_2] = SketchEllipse_1.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
+SketchEllipse_2 = Sketch_1.addEllipse(15.14848467636108, -15.95181340919842, 21.12194589112931, -20.27742325437541, 9.877448119278471)
+[SketchPoint_8, SketchPoint_9, SketchPoint_10, SketchPoint_11, SketchPoint_12, SketchPoint_13, SketchPoint_14, SketchLine_3, SketchLine_4] = SketchEllipse_2.construction(center = "aux", firstFocus = "aux", secondFocus = "aux", majorAxisStart = "aux", majorAxisEnd = "aux", minorAxisStart = "aux", minorAxisEnd = "aux", majorAxis = "aux", minorAxis = "aux")
+SketchConstraintEqual_1 = Sketch_1.setEqual(SketchEllipse_1.result(), SketchEllipse_2.result())
+model.do()
+model.end()
+
+TOLERANCE = 1.e-7
+
+dist1 = model.distancePointPoint(SketchEllipse_1.majorAxisNegative(), SketchEllipse_1.majorAxisPositive())
+dist2 = model.distancePointPoint(SketchEllipse_2.majorAxisNegative(), SketchEllipse_2.majorAxisPositive())
+assert(math.fabs(dist1 - dist2) < TOLERANCE)
+
+dist1 = model.distancePointPoint(SketchEllipse_1.minorAxisNegative(), SketchEllipse_1.minorAxisPositive())
+dist2 = model.distancePointPoint(SketchEllipse_2.minorAxisNegative(), SketchEllipse_2.minorAxisPositive())
+assert(math.fabs(dist1 - dist2) < TOLERANCE)
+
+assert(model.checkPythonDump())
icon="icons/Sketch/equal.png"
helpfile="equalFeature.html">
<sketch_shape_selector id="ConstraintEntityA"
- label="First object" tooltip="Select line, circle or arc" shape_types="edge">
+ label="First object" tooltip="Select edge" shape_types="edge">
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityB"/>
</sketch_shape_selector>
<sketch_shape_selector id="ConstraintEntityB"
- label="Second object" tooltip="Select line, circle or arc" shape_types="edge">
+ label="Second object" tooltip="Select edge" shape_types="edge">
<validator id="SketchPlugin_EqualAttr" parameters="ConstraintEntityA"/>
<validator id="PartSet_DifferentObjects"/>
<validator id="SketchPlugin_ExternalValidator" parameters="ConstraintEntityA"/>
// Predefined values for identifiers
const ConstraintID CID_UNKNOWN = 0;
const ConstraintID CID_MOVEMENT = -1;
-const ConstraintID CID_FICTIVE = 1024;
+const ConstraintID CID_FICTIVE = 99;
/// Types of entities
enum SketchSolver_EntityType {
void PlaneGCSSolver_Solver::addFictiveConstraintIfNecessary()
{
- if (!myConstraints.empty() &&
- myConstraints.find(CID_MOVEMENT) == myConstraints.end())
- return;
+ bool hasOnlyMovement = true;
+ for (ConstraintMap::iterator anIt = myConstraints.begin();
+ anIt != myConstraints.end() && hasOnlyMovement; ++anIt)
+ hasOnlyMovement = anIt->first == CID_MOVEMENT;
+ if (!hasOnlyMovement)
+ return; // regular constraints are available too
if (myFictiveConstraint)
return; // no need several fictive constraints
void PlaneGCSSolver_Solver::removeFictiveConstraint()
{
if (myFictiveConstraint) {
- myEquationSystem->removeConstraint(myFictiveConstraint);
+ myEquationSystem->clearByTag(myFictiveConstraint->getTag());
myParameters.pop_back();
GCS::VEC_pD aParams = myFictiveConstraint->params();
- for (GCS::VEC_pD::iterator anIt = aParams.begin(); anIt != aParams.end(); ++ anIt)
- delete *anIt;
+ for (GCS::VEC_pD::iterator anIt = aParams.begin(); anIt != aParams.end(); ++anIt) {
+ double* aPar = *anIt;
+ delete aPar;
+ }
delete myFictiveConstraint;
myFictiveConstraint = 0;
}
int aNbLines = 0;
int aNbArcs = 0;
int aNbCircs = 0;
+ int aNbEllipses = 0;
bool isArcFirst = false; // in line-arc equivalence, the line should be first
std::vector<EntityWrapperPtr>::iterator anAttrIt = theAttributes.begin() + 2;
for (; anAttrIt != theAttributes.end(); ++anAttrIt) {
++aNbArcs;
isArcFirst = (aNbLines == 0);
}
+ else if (aType == ENTITY_ELLIPSE || aType == ENTITY_ELLIPTICAL_ARC)
+ ++aNbEllipses;
}
- if (aNbLines + aNbArcs + aNbCircs != 2 ||
- (aNbLines == aNbCircs && aNbArcs == 0)) {
+ if (aNbLines + aNbArcs + aNbCircs + aNbEllipses != 2 ||
+ (aNbArcs == 1 && aNbEllipses != 0) || aNbEllipses == 1) {
myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
return;
}
std::shared_ptr<GeomAPI_Curve> aCurve =
std::shared_ptr<GeomAPI_Curve>(new GeomAPI_Curve(aShape));
- if (aCurve->isCircle()) {
+ if (aCurve->isCircle() || aCurve->isEllipse()) {
Handle(Geom_Curve) aCurv = aCurve->impl<Handle_Geom_Curve>();
GeomAPI_ProjectPointOnCurve anExtr(theP, aCurv);
double aParam = anExtr.LowerDistanceParameter();