SketchSolver.h
SketchSolver_Error.h
SketchSolver_Group.h
- SketchSolver_Builder.h
SketchSolver_IConstraintWrapper.h
SketchSolver_IEntityWrapper.h
- SketchSolver_ISolver.h
SketchSolver_Manager.h
SketchSolver_Storage.h
)
SET(SKETCHSOLVER_SOURCES
SketchSolver_Group.cpp
- SketchSolver_Builder.cpp
SketchSolver_Manager.cpp
SketchSolver_Storage.cpp
)
SET(PLANEGCSSOLVER_HEADERS
PlaneGCSSolver_Defs.h
PlaneGCSSolver_Solver.h
- PlaneGCSSolver_Builder.h
PlaneGCSSolver_Storage.h
PlaneGCSSolver_ConstraintWrapper.h
PlaneGCSSolver_EntityWrapper.h
PlaneGCSSolver_PointWrapper.h
PlaneGCSSolver_ScalarWrapper.h
PlaneGCSSolver_AngleWrapper.h
+ PlaneGCSSolver_Tools.h
)
SET(PLANEGCSSOLVER_SOURCES
PlaneGCSSolver_Solver.cpp
- PlaneGCSSolver_Builder.cpp
PlaneGCSSolver_Storage.cpp
PlaneGCSSolver_ConstraintWrapper.cpp
PlaneGCSSolver_EntityWrapper.cpp
PlaneGCSSolver_PointWrapper.cpp
PlaneGCSSolver_ScalarWrapper.cpp
PlaneGCSSolver_AngleWrapper.cpp
+ PlaneGCSSolver_Tools.cpp
)
SET(PLANEGCSSOLVER_BUILDER_HEADERS
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PlaneGCSSolver_Builder.cpp
-// Created: 14 Dec 2015
-// Author: Artem ZHIDKOV
-
-#include <PlaneGCSSolver_Builder.h>
-#include <PlaneGCSSolver_Storage.h>
-#include <PlaneGCSSolver_EntityWrapper.h>
-#include <PlaneGCSSolver_PointWrapper.h>
-#include <PlaneGCSSolver_ScalarWrapper.h>
-#include <PlaneGCSSolver_ConstraintWrapper.h>
-
-#include <SketchSolver_Manager.h>
-
-#include <GeomDataAPI_Point2D.h>
-#include <SketchPlugin_Line.h>
-#include <SketchPlugin_ConstraintAngle.h>
-
-#include <cmath>
-
-
-#define GCS_ENTITY_WRAPPER(x) std::dynamic_pointer_cast<PlaneGCSSolver_EntityWrapper>(x)
-#define GCS_POINT_WRAPPER(x) std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(x)
-#define GCS_SCALAR_WRAPPER(x) std::dynamic_pointer_cast<PlaneGCSSolver_ScalarWrapper>(x)
-
-
-
-static ConstraintWrapperPtr
- createConstraintCoincidence(std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2);
-static ConstraintWrapperPtr
- createConstraintPointOnEntity(const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
-static ConstraintWrapperPtr
- createConstraintDistancePointPoint(std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2);
-static ConstraintWrapperPtr
- createConstraintDistancePointLine(std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
-static ConstraintWrapperPtr
- createConstraintRadius(std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
-static ConstraintWrapperPtr
- createConstraintAngle(ConstraintPtr theConstraint,
- std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
-static ConstraintWrapperPtr
- createConstraintHorizVert(const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
-static ConstraintWrapperPtr
- createConstraintParallel(std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
-static ConstraintWrapperPtr
- createConstraintPerpendicular(std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
-static ConstraintWrapperPtr
- createConstraintEqual(const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2,
- std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theIntermed);
-static ConstraintWrapperPtr
- createConstraintTangent(const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
-static ConstraintWrapperPtr
- createConstraintCollinear(ConstraintPtr theConstraint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
-static ConstraintWrapperPtr
- createConstraintMiddlePoint(std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
-
-
-
-// Initialization of pointer to builder
-static BuilderPtr gBuilder = PlaneGCSSolver_Builder::getInstance();
-
-BuilderPtr PlaneGCSSolver_Builder::getInstance()
-{
- static BuilderPtr mySelf;
- if (!mySelf) {
- mySelf = BuilderPtr(new PlaneGCSSolver_Builder);
- SketchSolver_Manager::instance()->setBuilder(mySelf);
- }
- return mySelf;
-}
-
-StoragePtr PlaneGCSSolver_Builder::createStorage(const SolverPtr& theSolver) const
-{
- return StoragePtr(new PlaneGCSSolver_Storage(theSolver));
-}
-
-SolverPtr PlaneGCSSolver_Builder::createSolver() const
-{
- return SolverPtr(new PlaneGCSSolver_Solver);
-}
-
-
-ConstraintWrapperPtr PlaneGCSSolver_Builder::createConstraint(
- ConstraintPtr theConstraint,
- const SketchSolver_ConstraintType& theType,
- const EntityWrapperPtr& theValue,
- const EntityWrapperPtr& thePoint1,
- const EntityWrapperPtr& thePoint2,
- const EntityWrapperPtr& theEntity1,
- const EntityWrapperPtr& theEntity2) const
-{
- ConstraintWrapperPtr aResult;
- ScalarWrapperPtr anIntermediate;
-
- std::shared_ptr<PlaneGCSSolver_PointWrapper> aPoint1 = GCS_POINT_WRAPPER(thePoint1);
- std::shared_ptr<PlaneGCSSolver_PointWrapper> aPoint2 = GCS_POINT_WRAPPER(thePoint2);
-
- switch (theType) {
- case CONSTRAINT_PT_PT_COINCIDENT:
- aResult = createConstraintCoincidence(aPoint1, aPoint2);
- break;
- case CONSTRAINT_PT_ON_LINE:
- case CONSTRAINT_PT_ON_CIRCLE:
- aResult = createConstraintPointOnEntity(theType, aPoint1, GCS_ENTITY_WRAPPER(theEntity1));
- break;
- case CONSTRAINT_MIDDLE_POINT:
- aResult = createConstraintMiddlePoint(aPoint1, GCS_ENTITY_WRAPPER(theEntity1));
- break;
- case CONSTRAINT_PT_PT_DISTANCE:
- aResult = createConstraintDistancePointPoint(GCS_SCALAR_WRAPPER(theValue), aPoint1, aPoint2);
- break;
- case CONSTRAINT_PT_LINE_DISTANCE:
- aResult = createConstraintDistancePointLine(GCS_SCALAR_WRAPPER(theValue),
- aPoint1,
- GCS_ENTITY_WRAPPER(theEntity1));
- break;
- case CONSTRAINT_RADIUS:
- aResult = createConstraintRadius(GCS_SCALAR_WRAPPER(theValue),
- GCS_ENTITY_WRAPPER(theEntity1));
- break;
- case CONSTRAINT_ANGLE:
- aResult = createConstraintAngle(theConstraint,
- GCS_SCALAR_WRAPPER(theValue),
- GCS_ENTITY_WRAPPER(theEntity1), GCS_ENTITY_WRAPPER(theEntity2));
- break;
- case CONSTRAINT_FIXED:
- break;
- case CONSTRAINT_HORIZONTAL:
- case CONSTRAINT_VERTICAL:
- aResult = createConstraintHorizVert(theType, GCS_ENTITY_WRAPPER(theEntity1));
- break;
- case CONSTRAINT_PARALLEL:
- aResult = createConstraintParallel(GCS_ENTITY_WRAPPER(theEntity1),
- GCS_ENTITY_WRAPPER(theEntity2));
- break;
- case CONSTRAINT_PERPENDICULAR:
- aResult = createConstraintPerpendicular(GCS_ENTITY_WRAPPER(theEntity1),
- GCS_ENTITY_WRAPPER(theEntity2));
- break;
- case CONSTRAINT_EQUAL_LINES:
- anIntermediate = GCS_SCALAR_WRAPPER(theValue); // parameter is used to store length of lines
- case CONSTRAINT_EQUAL_LINE_ARC:
- case CONSTRAINT_EQUAL_RADIUS:
- aResult = createConstraintEqual(theType,
- GCS_ENTITY_WRAPPER(theEntity1),
- GCS_ENTITY_WRAPPER(theEntity2),
- anIntermediate);
- break;
- case CONSTRAINT_TANGENT_ARC_LINE:
- case CONSTRAINT_TANGENT_CIRCLE_LINE:
- case CONSTRAINT_TANGENT_ARC_ARC:
- aResult = createConstraintTangent(theType,
- GCS_ENTITY_WRAPPER(theEntity1),
- GCS_ENTITY_WRAPPER(theEntity2));
- break;
- case CONSTRAINT_COLLINEAR:
- aResult = createConstraintCollinear(theConstraint,
- GCS_ENTITY_WRAPPER(theEntity1), GCS_ENTITY_WRAPPER(theEntity2));
- break;
- case CONSTRAINT_MULTI_TRANSLATION:
- case CONSTRAINT_MULTI_ROTATION:
- case CONSTRAINT_SYMMETRIC:
- default:
- break;
- }
-
- return aResult;
-}
-
-ConstraintWrapperPtr PlaneGCSSolver_Builder::createConstraint(
- ConstraintPtr theConstraint,
- const SketchSolver_ConstraintType& theType,
- const EntityWrapperPtr& theValue,
- const bool theFullValue,
- const EntityWrapperPtr& thePoint1,
- const EntityWrapperPtr& thePoint2,
- const std::list<EntityWrapperPtr>& theTrsfEnt) const
-{
- if (theType != CONSTRAINT_MULTI_ROTATION && theType != CONSTRAINT_MULTI_TRANSLATION)
- return ConstraintWrapperPtr();
-
- std::list<EntityWrapperPtr> aConstrAttrList = theTrsfEnt;
- if (thePoint2)
- aConstrAttrList.push_front(thePoint2);
- aConstrAttrList.push_front(thePoint1);
-
- ScalarWrapperPtr aValue = GCS_SCALAR_WRAPPER(theValue);
-
- std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
- new PlaneGCSSolver_ConstraintWrapper(std::list<GCSConstraintPtr>(), theType));
- aResult->setEntities(aConstrAttrList);
- if (aValue)
- aResult->setValueParameter(aValue);
- aResult->setIsFullValue(theFullValue);
- return aResult;
-}
-
-std::shared_ptr<GeomAPI_Pnt2d> PlaneGCSSolver_Builder::point(EntityWrapperPtr theEntity) const
-{
- if (theEntity->type() != ENTITY_POINT)
- return std::shared_ptr<GeomAPI_Pnt2d>();
-
- std::shared_ptr<PlaneGCSSolver_PointWrapper> aPointWrapper =
- std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(theEntity);
- const GCSPointPtr& aPoint = aPointWrapper->point();
- return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(*aPoint->x, *aPoint->y));
-}
-
-std::shared_ptr<GeomAPI_Lin2d> PlaneGCSSolver_Builder::line(EntityWrapperPtr theEntity) const
-{
- if (theEntity->type() != ENTITY_LINE)
- return std::shared_ptr<GeomAPI_Lin2d>();
-
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> anEntity =
- std::dynamic_pointer_cast<PlaneGCSSolver_EntityWrapper>(theEntity);
- std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(anEntity->entity());
- return std::shared_ptr<GeomAPI_Lin2d>(
- new GeomAPI_Lin2d(*(aLine->p1.x), *(aLine->p1.y), *(aLine->p2.x), *(aLine->p2.y)));
-}
-
-std::shared_ptr<GeomAPI_Lin2d> PlaneGCSSolver_Builder::line(FeaturePtr theFeature) const
-{
- if (theFeature->getKind() != SketchPlugin_Line::ID())
- return std::shared_ptr<GeomAPI_Lin2d>();
-
- AttributePoint2DPtr aStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theFeature->attribute(SketchPlugin_Line::START_ID()));
- AttributePoint2DPtr aEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theFeature->attribute(SketchPlugin_Line::END_ID()));
-
- return std::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aStart->pnt(), aEnd->pnt()));
-}
-
-
-
-
-
-// ================ Auxiliary functions ==========================
-ConstraintWrapperPtr createConstraintCoincidence(
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2)
-{
- GCSPointPtr aPoint1 = thePoint1->point();
- GCSPointPtr aPoint2 = thePoint2->point();
-
- // Create equality constraint for corresponding attributes of the points
- std::list<GCSConstraintPtr> aConstrList;
- aConstrList.push_back(
- GCSConstraintPtr(new GCS::ConstraintEqual(aPoint1->x, aPoint2->x)));
- aConstrList.push_back(
- GCSConstraintPtr(new GCS::ConstraintEqual(aPoint1->y, aPoint2->y)));
-
- return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(
- aConstrList, CONSTRAINT_PT_PT_COINCIDENT));
-}
-
-ConstraintWrapperPtr createConstraintPointOnEntity(
- const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
-{
- GCSConstraintPtr aNewConstr;
-
- switch (theEntity->type()) {
- case ENTITY_LINE: {
- std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
- aNewConstr = GCSConstraintPtr(new GCS::ConstraintPointOnLine(*(thePoint->point()), *aLine));
- break;
- }
- case ENTITY_ARC:
- case ENTITY_CIRCLE: {
- std::shared_ptr<GCS::Circle> aCirc =
- std::dynamic_pointer_cast<GCS::Circle>(theEntity->entity());
- aNewConstr = GCSConstraintPtr(
- new GCS::ConstraintP2PDistance(*(thePoint->point()), aCirc->center, aCirc->rad));
- break;
- }
- default:
- return ConstraintWrapperPtr();
- }
-
- return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType));
-}
-
-ConstraintWrapperPtr createConstraintMiddlePoint(
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
-{
- GCSPointPtr aPoint = thePoint->point();
- std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
- if (!aLine)
- return ConstraintWrapperPtr();
-
- std::list<GCSConstraintPtr> aConstrList;
- aConstrList.push_back(
- GCSConstraintPtr(new GCS::ConstraintPointOnPerpBisector(*aPoint, aLine->p1, aLine->p2)));
- aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintPointOnLine(*aPoint, *aLine)));
-
- return ConstraintWrapperPtr(
- new PlaneGCSSolver_ConstraintWrapper(aConstrList, CONSTRAINT_MIDDLE_POINT));
-}
-
-
-ConstraintWrapperPtr createConstraintDistancePointPoint(
- std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2)
-{
- GCSConstraintPtr aNewConstr(new GCS::ConstraintP2PDistance(
- *(thePoint1->point()), *(thePoint2->point()), theValue->scalar()));
- std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
- new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_PT_DISTANCE));
- aResult->setValueParameter(theValue);
- return aResult;
-}
-
-ConstraintWrapperPtr createConstraintDistancePointLine(
- std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
-{
- std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
- GCSConstraintPtr aNewConstr(new GCS::ConstraintP2LDistance(
- *(thePoint->point()), *(aLine), theValue->scalar()));
- std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
- new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_LINE_DISTANCE));
- aResult->setValueParameter(theValue);
- return aResult;
-}
-
-ConstraintWrapperPtr createConstraintRadius(
- std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
-{
- std::shared_ptr<GCS::Circle> aCircle =
- std::dynamic_pointer_cast<GCS::Circle>(theEntity->entity());
- GCSConstraintPtr aNewConstr(new GCS::ConstraintEqual(aCircle->rad, theValue->scalar()));
- std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
- new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_RADIUS));
- aResult->setValueParameter(theValue);
- return aResult;
-}
-
-ConstraintWrapperPtr createConstraintAngle(
- ConstraintPtr theConstraint,
- std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
-{
- std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
- bool isLine1Rev = theConstraint->boolean(
- SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->value();
- GCS::Point aLine1Pt1 = isLine1Rev ? aLine1->p2 : aLine1->p1;
- GCS::Point aLine1Pt2 = isLine1Rev ? aLine1->p1 : aLine1->p2;
-
- std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
- bool isLine2Rev = theConstraint->boolean(
- SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value();
- GCS::Point aLine2Pt1 = isLine2Rev ? aLine2->p2 : aLine2->p1;
- GCS::Point aLine2Pt2 = isLine2Rev ? aLine2->p1 : aLine2->p2;
-
- GCSConstraintPtr aNewConstr(new GCS::ConstraintL2LAngle(
- aLine1Pt1, aLine1Pt2, aLine2Pt1, aLine2Pt2, theValue->scalar()));
-
- std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
- new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_ANGLE));
- aResult->setValueParameter(theValue);
- return aResult;
-}
-
-ConstraintWrapperPtr createConstraintHorizVert(
- const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
-{
- std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
- GCSConstraintPtr aNewConstr;
- if (theType == CONSTRAINT_HORIZONTAL)
- aNewConstr = GCSConstraintPtr(new GCS::ConstraintEqual(aLine->p1.y, aLine->p2.y));
- else
- aNewConstr = GCSConstraintPtr(new GCS::ConstraintEqual(aLine->p1.x, aLine->p2.x));
-
- return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType));
-}
-
-ConstraintWrapperPtr createConstraintCollinear(
- ConstraintPtr theConstraint,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
-{
- std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
- std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
-
- // create two point-on-line constraints
- std::list<GCSConstraintPtr> aConstrList;
- aConstrList.push_back( GCSConstraintPtr(new GCS::ConstraintPointOnLine(aLine2->p1, *aLine1)) );
- aConstrList.push_back( GCSConstraintPtr(new GCS::ConstraintPointOnLine(aLine2->p2, *aLine1)) );
-
- return ConstraintWrapperPtr(
- new PlaneGCSSolver_ConstraintWrapper(aConstrList, CONSTRAINT_COLLINEAR));
-}
-
-ConstraintWrapperPtr createConstraintParallel(
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
-{
- std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
- std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
- GCSConstraintPtr aNewConstr(new GCS::ConstraintParallel(*(aLine1), *(aLine2)));
-
- return ConstraintWrapperPtr(
- new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PARALLEL));
-}
-
-ConstraintWrapperPtr createConstraintPerpendicular(
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
-{
- std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
- std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
- GCSConstraintPtr aNewConstr(new GCS::ConstraintPerpendicular(*(aLine1), *(aLine2)));
-
- return ConstraintWrapperPtr(
- new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PERPENDICULAR));
-}
-
-ConstraintWrapperPtr createConstraintEqual(
- const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2,
- std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theIntermed)
-{
- if (theType == CONSTRAINT_EQUAL_LINE_ARC)
- return ConstraintWrapperPtr(); // line-arc equivalence is not supported yet
-
- std::list<GCSConstraintPtr> aConstrList;
- if (theType == CONSTRAINT_EQUAL_LINES) {
- std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
- std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
-
- aConstrList.push_back(GCSConstraintPtr(
- new GCS::ConstraintP2PDistance(aLine1->p1, aLine1->p2, theIntermed->scalar())));
- aConstrList.push_back(GCSConstraintPtr(
- new GCS::ConstraintP2PDistance(aLine2->p1, aLine2->p2, theIntermed->scalar())));
- // update value of intermediate parameter
- double x = *aLine1->p1.x - *aLine1->p2.x;
- double y = *aLine1->p1.y - *aLine1->p2.y;
- double aLen = sqrt(x*x + y*y);
- theIntermed->setValue(aLen);
- } else {
- std::shared_ptr<GCS::Circle> aCirc1 =
- std::dynamic_pointer_cast<GCS::Circle>(theEntity1->entity());
- std::shared_ptr<GCS::Circle> aCirc2 =
- std::dynamic_pointer_cast<GCS::Circle>(theEntity2->entity());
-
- aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintEqual(aCirc1->rad, aCirc2->rad)));
- }
-
- std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
- new PlaneGCSSolver_ConstraintWrapper(aConstrList, theType));
- if (theIntermed)
- aResult->setValueParameter(theIntermed);
- return aResult;
-}
-
-ConstraintWrapperPtr createConstraintTangent(
- const SketchSolver_ConstraintType& theType,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
- std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
-{
- GCSConstraintPtr aNewConstr;
- if (theType == CONSTRAINT_TANGENT_ARC_LINE || theType == CONSTRAINT_TANGENT_CIRCLE_LINE) {
- std::shared_ptr<GCS::Circle> aCirc =
- std::dynamic_pointer_cast<GCS::Circle>(theEntity1->entity());
- std::shared_ptr<GCS::Line> aLine =
- std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
-
- aNewConstr =
- GCSConstraintPtr(new GCS::ConstraintP2LDistance(aCirc->center, *aLine, aCirc->rad));
- } else {
- std::shared_ptr<GCS::Circle> aCirc1 =
- std::dynamic_pointer_cast<GCS::Circle>(theEntity1->entity());
- std::shared_ptr<GCS::Circle> aCirc2 =
- std::dynamic_pointer_cast<GCS::Circle>(theEntity2->entity());
-
- double aDX = *(aCirc1->center.x) - *(aCirc2->center.x);
- double aDY = *(aCirc1->center.y) - *(aCirc2->center.y);
- double aDist = sqrt(aDX * aDX + aDY * aDY);
- aNewConstr = GCSConstraintPtr(new GCS::ConstraintTangentCircumf(aCirc1->center, aCirc2->center,
- aCirc1->rad, aCirc2->rad, (aDist < *(aCirc1->rad) || aDist < *(aCirc2->rad))));
- }
-
- return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType));
-}
-
-bool PlaneGCSSolver_Builder::isArcArcTangencyInternal(
- EntityWrapperPtr theArc1, EntityWrapperPtr theArc2) const
-{
- std::shared_ptr<GCS::Circle> aCirc1 = std::dynamic_pointer_cast<GCS::Circle>(
- GCS_ENTITY_WRAPPER(theArc1)->entity());
- std::shared_ptr<GCS::Circle> aCirc2 = std::dynamic_pointer_cast<GCS::Circle>(
- GCS_ENTITY_WRAPPER(theArc2)->entity());
-
- if (!aCirc1 || !aCirc2)
- return false;
-
- double aDX = *(aCirc1->center.x) - *(aCirc2->center.x);
- double aDY = *(aCirc1->center.y) - *(aCirc2->center.y);
- double aDist = sqrt(aDX * aDX + aDY * aDY);
-
- return (aDist < *(aCirc1->rad) || aDist < *(aCirc2->rad));
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: PlaneGCSSolver_Builder.h
-// Created: 14 Dec 2015
-// Author: Artem ZHIDKOV
-
-#ifndef PlaneGCSSolver_Builder_H_
-#define PlaneGCSSolver_Builder_H_
-
-#include <PlaneGCSSolver_Defs.h>
-
-#include <SketchSolver_Builder.h>
-#include <SketchSolver_Constraint.h>
-
-#include <SketchPlugin_Constraint.h>
-
-#include <ModelAPI_CompositeFeature.h>
-
-/** \class PlaneGCSSolver_Builder
- * \ingroup Plugins
- * \brief Create bridges between SketchPlugin constraints and PlaneGCS constraints
- */
-class PlaneGCSSolver_Builder : public SketchSolver_Builder
-{
- /// Default constructor
- PlaneGCSSolver_Builder() {}
-
-public:
- /// \brief Returns single instance of builder
- static BuilderPtr getInstance();
-
- /// \brief Creates a storage specific for used solver
- virtual StoragePtr createStorage(const SolverPtr& theSolver) const;
- /// \brief Creates specific solver
- virtual SolverPtr createSolver() const;
-
- /// \brief Creates new constraint using given parameters
- /// \param theConstraint [in] original constraint
- /// \param theType [in] type of constraint
- /// \param theValue [in] numeric characteristic of constraint
- /// (e.g. distance or radius) if applicable
- /// \param theEntity1 [in] first attribute of constraint
- /// \param theEntity2 [in] second attribute of constraint
- /// \param theEntity3 [in] third attribute of constraint
- /// \param theEntity4 [in] fourth attribute of constraint
- /// \return Created wrapper of constraints applicable for specific solver.
- virtual ConstraintWrapperPtr
- createConstraint(ConstraintPtr theConstraint,
- const SketchSolver_ConstraintType& theType,
- const EntityWrapperPtr& theValue,
- const EntityWrapperPtr& theEntity1,
- const EntityWrapperPtr& theEntity2 = EntityWrapperPtr(),
- const EntityWrapperPtr& theEntity3 = EntityWrapperPtr(),
- const EntityWrapperPtr& theEntity4 = EntityWrapperPtr()) const;
-
- /// \brief Creates new multi-translation or multi-rotation constraint
- /// \param theConstraint [in] original constraint
- /// \param theType [in] type of constraint
- /// \param theValue [in] numeric characteristic of constraint (angle for multi-rotation)
- /// if applicable
- /// \param theFullValue [in] indicates theValue shows full translation delta/rotation
- /// angle or delta/angle between neighbor entities
- /// \param thePoint1 [in] center for multi-rotation or start point for multi-translation
- /// \param thePoint2 [in] end point for multi-translation (empty for multi-rotation)
- /// \param theTrsfEnt [in] list of transformed entities
- virtual ConstraintWrapperPtr
- createConstraint(ConstraintPtr theConstraint,
- const SketchSolver_ConstraintType& theType,
- const EntityWrapperPtr& theValue,
- const bool theFullValue,
- const EntityWrapperPtr& thePoint1,
- const EntityWrapperPtr& thePoint2,
- const std::list<EntityWrapperPtr>& theTrsfEnt) const;
-
- /// \brief Convert entity to point
- /// \return empty pointer if the entity is not a point
- virtual std::shared_ptr<GeomAPI_Pnt2d> point(EntityWrapperPtr theEntity) const;
- /// \brief Convert entity to line
- /// \return empty pointer if the entity is not a line
- virtual std::shared_ptr<GeomAPI_Lin2d> line(EntityWrapperPtr theEntity) const;
-
- /// \brief Convert entity to line
- /// \return empty pointer if the entity is not a line
- virtual std::shared_ptr<GeomAPI_Lin2d> line(FeaturePtr theFeature) const;
-
- /// \brief Check if two connected arcs have centers
- /// in same direction relatively to connection point
- virtual bool isArcArcTangencyInternal(EntityWrapperPtr theArc1,
- EntityWrapperPtr theArc2) const;
-};
-
-#endif
// Created: 14 Dec 2014
// Author: Artem ZHIDKOV
-#include "PlaneGCSSolver_Solver.h"
+#include <PlaneGCSSolver_Solver.h>
#include <Events_LongOp.h>
}
}
-SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve()
+PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Solver::solve()
{
// clear list of conflicting constraints
if (myConfCollected) {
GCS::SolveStatus aResult = (GCS::SolveStatus)myEquationSystem->solve(myParameters);
Events_LongOp::end(this);
- SketchSolver_SolveStatus aStatus;
+ SolveStatus aStatus;
if (aResult == GCS::Success) {
myEquationSystem->applySolution();
if (myDOF < 0)
#ifndef PlaneGCSSolver_Solver_H_
#define PlaneGCSSolver_Solver_H_
-#include <SketchSolver_ISolver.h>
#include <SketchSolver_IConstraintWrapper.h>
#include <PlaneGCSSolver_Defs.h>
#include <GCS.h>
/// \brief The main class that performs the high-level operations for connection to the PlaneGCS.
-class PlaneGCSSolver_Solver : public SketchSolver_ISolver
+class PlaneGCSSolver_Solver
{
public:
+ /// The result of constraints solution
+ enum SolveStatus {
+ STATUS_OK,
+ STATUS_INCONSISTENT,
+ STATUS_EMPTYSET,
+ STATUS_FAILED, // set if no one other status is applicable
+ STATUS_UNKNOWN // set for newly created groups
+ };
+
PlaneGCSSolver_Solver();
~PlaneGCSSolver_Solver();
/// \brief Solve the set of equations
/// \return identifier whether solution succeeded
- virtual SketchSolver_SolveStatus solve();
-
- /// \brief Prepare for solving. Store initial values of parameters for undo
- virtual void prepare()
- { /* do nothing */ }
+ SolveStatus solve();
/// \brief Revert solution to initial values
- virtual void undo();
+ void undo();
/// \brief Check the constraint is conflicted with others
- virtual bool isConflicting(const ConstraintID& theConstraint) const;
+ bool isConflicting(const ConstraintID& theConstraint) const;
/// \brief Degrees of freedom
- virtual int dof();
+ int dof();
private:
void collectConflicting();
int myDOF; ///< degrees of freedom
};
+typedef std::shared_ptr<PlaneGCSSolver_Solver> SolverPtr;
+
#endif
// Author: Artem ZHIDKOV
#include <PlaneGCSSolver_Storage.h>
-#include <PlaneGCSSolver_Builder.h>
#include <PlaneGCSSolver_Solver.h>
#include <PlaneGCSSolver_ConstraintWrapper.h>
#include <PlaneGCSSolver_EntityWrapper.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_XY.h>
#include <GeomDataAPI_Point2D.h>
+#include <ModelAPI_AttributeRefAttr.h>
#include <SketchPlugin_Projection.h>
#include <cmath>
if (aFound != myConstraintMap.end()) {
ConstraintID anID = aFound->second->id();
// Remove solver's constraints
- std::shared_ptr<PlaneGCSSolver_Solver> aSolver =
- std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(mySketchSolver);
- aSolver->removeConstraint(anID);
+ mySketchSolver->removeConstraint(anID);
// Remove constraint
myConstraintMap.erase(aFound);
std::map<EntityWrapperPtr, ConstraintWrapperPtr>::iterator
aFound = myArcConstraintMap.find(aFIter->second);
if (aFound != myArcConstraintMap.end()) {
- std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(
- mySketchSolver)->removeConstraint(aFound->second->id());
+ mySketchSolver->removeConstraint(aFound->second->id());
myArcConstraintMap.erase(aFound);
}
}
double* PlaneGCSSolver_Storage::createParameter()
{
- return std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(mySketchSolver)->createParameter();
+ return mySketchSolver->createParameter();
}
void PlaneGCSSolver_Storage::removeParameters(const GCS::SET_pD& theParams)
{
- std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(mySketchSolver)->removeParameters(theParams);
-}
-
-
-bool PlaneGCSSolver_Storage::isRedundant(
- GCSConstraintPtr theCheckedConstraint,
- ConstraintWrapperPtr theParentConstraint,
- std::list<std::set<double*> >& theCoincidentPoints) const
-{
- if (theParentConstraint->type() == CONSTRAINT_SYMMETRIC) {
- if (theCheckedConstraint->getTypeId() == GCS::Perpendicular) {
- BuilderPtr aBuilder = PlaneGCSSolver_Builder::getInstance();
- // check the initial point is placed on the mirror line
- std::list<EntityWrapperPtr> aSubs = theParentConstraint->entities();
- std::shared_ptr<GeomAPI_Pnt2d> aPoint = aBuilder->point(aSubs.front());
- std::shared_ptr<GeomAPI_Lin2d> aLine = aBuilder->line(aSubs.back());
- return aLine->distance(aPoint) < tolerance;
- }
- }
- else if (theParentConstraint->type() == CONSTRAINT_PT_PT_COINCIDENT) {
- // Verify that the coincidence between points is already added
- GCS::VEC_pD aParams = theCheckedConstraint->params();
-
- std::list<std::set<double*> >::iterator aCoincIt, aFound1, aFound2;
- aFound1 = aFound2 = theCoincidentPoints.end();
- for (aCoincIt = theCoincidentPoints.begin();
- aCoincIt != theCoincidentPoints.end(); ++aCoincIt) {
- if (aFound1 == theCoincidentPoints.end() && aCoincIt->find(aParams[0]) != aCoincIt->end())
- aFound1 = aCoincIt;
- if (aFound2 == theCoincidentPoints.end() && aCoincIt->find(aParams[1]) != aCoincIt->end())
- aFound2 = aCoincIt;
- if (aFound1 != theCoincidentPoints.end() && aFound2 != theCoincidentPoints.end())
- break;
- }
- if (aCoincIt != theCoincidentPoints.end()) { // both point are found
- if (aFound1 == aFound2)
- return true;
- // merge two groups of coincidence
- aFound1->insert(aFound2->begin(), aFound2->end());
- theCoincidentPoints.erase(aFound2);
- } else {
- if (aFound1 != theCoincidentPoints.end())
- aFound1->insert(aParams[1]);
- else if (aFound2 != theCoincidentPoints.end())
- aFound2->insert(aParams[0]);
- else {
- std::set<double*> aNewCoincidence;
- aNewCoincidence.insert(aParams[0]);
- aNewCoincidence.insert(aParams[1]);
- theCoincidentPoints.push_back(aNewCoincidence);
- }
- }
- }
-
- return false;
+ mySketchSolver->removeParameters(theParams);
}
// indicates attribute containing in the external feature
#include <SketchSolver.h>
#include <SketchSolver_Storage.h>
-#include <SketchSolver_ISolver.h>
class PlaneGCSSolver_EntityBuilder;
virtual void removeInvalidEntities();
private:
- /// \brief Verifies the constraint should not be added into the solver
- ///
- /// This is a workaround method to avoid some kinds of conflicting constraints:
- /// * symmetric of two points placed on the mirror line (do not add perpendicular constraint)
- bool isRedundant(GCSConstraintPtr theCheckedConstraint,
- ConstraintWrapperPtr theParentConstraint,
- std::list<std::set<double*> >& theCoincidentPoints) const;
-
/// \brief Convert feature using specified builder.
EntityWrapperPtr createFeature(const FeaturePtr& theFeature,
PlaneGCSSolver_EntityBuilder* theBuilder);
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: SketchSolver_Builder.cpp
+// Created: 25 Mar 2015
+// Author: Artem ZHIDKOV
+
+#include <PlaneGCSSolver_Tools.h>
+#include <PlaneGCSSolver_EntityWrapper.h>
+#include <PlaneGCSSolver_PointWrapper.h>
+#include <PlaneGCSSolver_ScalarWrapper.h>
+#include <PlaneGCSSolver_ConstraintWrapper.h>
+
+#include <SketchSolver_Constraint.h>
+#include <SketchSolver_ConstraintAngle.h>
+#include <SketchSolver_ConstraintCoincidence.h>
+#include <SketchSolver_ConstraintCollinear.h>
+#include <SketchSolver_ConstraintDistance.h>
+#include <SketchSolver_ConstraintEqual.h>
+#include <SketchSolver_ConstraintFixed.h>
+#include <SketchSolver_ConstraintLength.h>
+#include <SketchSolver_ConstraintMiddle.h>
+#include <SketchSolver_ConstraintMirror.h>
+#include <SketchSolver_ConstraintTangent.h>
+#include <SketchSolver_ConstraintMultiRotation.h>
+#include <SketchSolver_ConstraintMultiTranslation.h>
+
+#include <SketchPlugin_ConstraintAngle.h>
+#include <SketchPlugin_ConstraintCoincidence.h>
+#include <SketchPlugin_ConstraintCollinear.h>
+#include <SketchPlugin_ConstraintDistance.h>
+#include <SketchPlugin_ConstraintEqual.h>
+#include <SketchPlugin_ConstraintLength.h>
+#include <SketchPlugin_ConstraintMiddle.h>
+#include <SketchPlugin_ConstraintMirror.h>
+#include <SketchPlugin_ConstraintRigid.h>
+#include <SketchPlugin_ConstraintTangent.h>
+#include <SketchPlugin_Line.h>
+#include <SketchPlugin_MultiRotation.h>
+#include <SketchPlugin_MultiTranslation.h>
+
+#include <cmath>
+
+
+#define GCS_ENTITY_WRAPPER(x) std::dynamic_pointer_cast<PlaneGCSSolver_EntityWrapper>(x)
+#define GCS_POINT_WRAPPER(x) std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(x)
+#define GCS_SCALAR_WRAPPER(x) std::dynamic_pointer_cast<PlaneGCSSolver_ScalarWrapper>(x)
+
+
+
+static ConstraintWrapperPtr
+ createConstraintCoincidence(std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2);
+static ConstraintWrapperPtr
+ createConstraintPointOnEntity(const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
+static ConstraintWrapperPtr
+ createConstraintDistancePointPoint(std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2);
+static ConstraintWrapperPtr
+ createConstraintDistancePointLine(std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
+static ConstraintWrapperPtr
+ createConstraintRadius(std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
+static ConstraintWrapperPtr
+ createConstraintAngle(ConstraintPtr theConstraint,
+ std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
+static ConstraintWrapperPtr
+ createConstraintHorizVert(const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
+static ConstraintWrapperPtr
+ createConstraintParallel(std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
+static ConstraintWrapperPtr
+ createConstraintPerpendicular(std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
+static ConstraintWrapperPtr
+ createConstraintEqual(const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2,
+ std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theIntermed);
+static ConstraintWrapperPtr
+ createConstraintTangent(const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
+static ConstraintWrapperPtr
+ createConstraintCollinear(ConstraintPtr theConstraint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2);
+static ConstraintWrapperPtr
+ createConstraintMiddlePoint(std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity);
+
+
+
+
+
+SolverConstraintPtr PlaneGCSSolver_Tools::createConstraint(ConstraintPtr theConstraint)
+{
+ if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintCollinear::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintCollinear(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintDistance(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintEqual::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintEqual(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintLength(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintMiddle(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintMirror(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintTangent(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintRigid::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintFixed(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintMultiTranslation(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintMultiRotation(theConstraint));
+ } else if (theConstraint->getKind() == SketchPlugin_ConstraintAngle::ID()) {
+ return SolverConstraintPtr(new SketchSolver_ConstraintAngle(theConstraint));
+ }
+ // All other types of constraints
+ return SolverConstraintPtr(new SketchSolver_Constraint(theConstraint));
+}
+
+SolverConstraintPtr PlaneGCSSolver_Tools::createMovementConstraint(FeaturePtr theMovedFeature)
+{
+ return SolverConstraintPtr(new SketchSolver_ConstraintFixed(theMovedFeature));
+}
+
+
+
+ConstraintWrapperPtr PlaneGCSSolver_Tools::createConstraint(
+ ConstraintPtr theConstraint,
+ const SketchSolver_ConstraintType& theType,
+ const EntityWrapperPtr& theValue,
+ const EntityWrapperPtr& thePoint1,
+ const EntityWrapperPtr& thePoint2,
+ const EntityWrapperPtr& theEntity1,
+ const EntityWrapperPtr& theEntity2)
+{
+ ConstraintWrapperPtr aResult;
+ ScalarWrapperPtr anIntermediate;
+
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> aPoint1 = GCS_POINT_WRAPPER(thePoint1);
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> aPoint2 = GCS_POINT_WRAPPER(thePoint2);
+
+ switch (theType) {
+ case CONSTRAINT_PT_PT_COINCIDENT:
+ aResult = createConstraintCoincidence(aPoint1, aPoint2);
+ break;
+ case CONSTRAINT_PT_ON_LINE:
+ case CONSTRAINT_PT_ON_CIRCLE:
+ aResult = createConstraintPointOnEntity(theType, aPoint1, GCS_ENTITY_WRAPPER(theEntity1));
+ break;
+ case CONSTRAINT_MIDDLE_POINT:
+ aResult = createConstraintMiddlePoint(aPoint1, GCS_ENTITY_WRAPPER(theEntity1));
+ break;
+ case CONSTRAINT_PT_PT_DISTANCE:
+ aResult = createConstraintDistancePointPoint(GCS_SCALAR_WRAPPER(theValue), aPoint1, aPoint2);
+ break;
+ case CONSTRAINT_PT_LINE_DISTANCE:
+ aResult = createConstraintDistancePointLine(GCS_SCALAR_WRAPPER(theValue),
+ aPoint1,
+ GCS_ENTITY_WRAPPER(theEntity1));
+ break;
+ case CONSTRAINT_RADIUS:
+ aResult = createConstraintRadius(GCS_SCALAR_WRAPPER(theValue),
+ GCS_ENTITY_WRAPPER(theEntity1));
+ break;
+ case CONSTRAINT_ANGLE:
+ aResult = createConstraintAngle(theConstraint,
+ GCS_SCALAR_WRAPPER(theValue),
+ GCS_ENTITY_WRAPPER(theEntity1), GCS_ENTITY_WRAPPER(theEntity2));
+ break;
+ case CONSTRAINT_FIXED:
+ break;
+ case CONSTRAINT_HORIZONTAL:
+ case CONSTRAINT_VERTICAL:
+ aResult = createConstraintHorizVert(theType, GCS_ENTITY_WRAPPER(theEntity1));
+ break;
+ case CONSTRAINT_PARALLEL:
+ aResult = createConstraintParallel(GCS_ENTITY_WRAPPER(theEntity1),
+ GCS_ENTITY_WRAPPER(theEntity2));
+ break;
+ case CONSTRAINT_PERPENDICULAR:
+ aResult = createConstraintPerpendicular(GCS_ENTITY_WRAPPER(theEntity1),
+ GCS_ENTITY_WRAPPER(theEntity2));
+ break;
+ case CONSTRAINT_EQUAL_LINES:
+ anIntermediate = GCS_SCALAR_WRAPPER(theValue); // parameter is used to store length of lines
+ case CONSTRAINT_EQUAL_LINE_ARC:
+ case CONSTRAINT_EQUAL_RADIUS:
+ aResult = createConstraintEqual(theType,
+ GCS_ENTITY_WRAPPER(theEntity1),
+ GCS_ENTITY_WRAPPER(theEntity2),
+ anIntermediate);
+ break;
+ case CONSTRAINT_TANGENT_ARC_LINE:
+ case CONSTRAINT_TANGENT_CIRCLE_LINE:
+ case CONSTRAINT_TANGENT_ARC_ARC:
+ aResult = createConstraintTangent(theType,
+ GCS_ENTITY_WRAPPER(theEntity1),
+ GCS_ENTITY_WRAPPER(theEntity2));
+ break;
+ case CONSTRAINT_COLLINEAR:
+ aResult = createConstraintCollinear(theConstraint,
+ GCS_ENTITY_WRAPPER(theEntity1), GCS_ENTITY_WRAPPER(theEntity2));
+ break;
+ case CONSTRAINT_MULTI_TRANSLATION:
+ case CONSTRAINT_MULTI_ROTATION:
+ case CONSTRAINT_SYMMETRIC:
+ default:
+ break;
+ }
+
+ return aResult;
+}
+
+std::shared_ptr<GeomAPI_Pnt2d> PlaneGCSSolver_Tools::point(EntityWrapperPtr theEntity)
+{
+ if (theEntity->type() != ENTITY_POINT)
+ return std::shared_ptr<GeomAPI_Pnt2d>();
+
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> aPointWrapper =
+ std::dynamic_pointer_cast<PlaneGCSSolver_PointWrapper>(theEntity);
+ const GCSPointPtr& aPoint = aPointWrapper->point();
+ return std::shared_ptr<GeomAPI_Pnt2d>(new GeomAPI_Pnt2d(*aPoint->x, *aPoint->y));
+}
+
+std::shared_ptr<GeomAPI_Lin2d> PlaneGCSSolver_Tools::line(EntityWrapperPtr theEntity)
+{
+ if (theEntity->type() != ENTITY_LINE)
+ return std::shared_ptr<GeomAPI_Lin2d>();
+
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> anEntity =
+ std::dynamic_pointer_cast<PlaneGCSSolver_EntityWrapper>(theEntity);
+ std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(anEntity->entity());
+ return std::shared_ptr<GeomAPI_Lin2d>(
+ new GeomAPI_Lin2d(*(aLine->p1.x), *(aLine->p1.y), *(aLine->p2.x), *(aLine->p2.y)));
+}
+
+std::shared_ptr<GeomAPI_Lin2d> PlaneGCSSolver_Tools::line(FeaturePtr theFeature)
+{
+ if (theFeature->getKind() != SketchPlugin_Line::ID())
+ return std::shared_ptr<GeomAPI_Lin2d>();
+
+ AttributePoint2DPtr aStart = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Line::START_ID()));
+ AttributePoint2DPtr aEnd = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(SketchPlugin_Line::END_ID()));
+
+ return std::shared_ptr<GeomAPI_Lin2d>(new GeomAPI_Lin2d(aStart->pnt(), aEnd->pnt()));
+}
+
+
+
+
+
+// ================ Auxiliary functions ==========================
+ConstraintWrapperPtr createConstraintCoincidence(
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2)
+{
+ GCSPointPtr aPoint1 = thePoint1->point();
+ GCSPointPtr aPoint2 = thePoint2->point();
+
+ // Create equality constraint for corresponding attributes of the points
+ std::list<GCSConstraintPtr> aConstrList;
+ aConstrList.push_back(
+ GCSConstraintPtr(new GCS::ConstraintEqual(aPoint1->x, aPoint2->x)));
+ aConstrList.push_back(
+ GCSConstraintPtr(new GCS::ConstraintEqual(aPoint1->y, aPoint2->y)));
+
+ return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(
+ aConstrList, CONSTRAINT_PT_PT_COINCIDENT));
+}
+
+ConstraintWrapperPtr createConstraintPointOnEntity(
+ const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
+{
+ GCSConstraintPtr aNewConstr;
+
+ switch (theEntity->type()) {
+ case ENTITY_LINE: {
+ std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
+ aNewConstr = GCSConstraintPtr(new GCS::ConstraintPointOnLine(*(thePoint->point()), *aLine));
+ break;
+ }
+ case ENTITY_ARC:
+ case ENTITY_CIRCLE: {
+ std::shared_ptr<GCS::Circle> aCirc =
+ std::dynamic_pointer_cast<GCS::Circle>(theEntity->entity());
+ aNewConstr = GCSConstraintPtr(
+ new GCS::ConstraintP2PDistance(*(thePoint->point()), aCirc->center, aCirc->rad));
+ break;
+ }
+ default:
+ return ConstraintWrapperPtr();
+ }
+
+ return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType));
+}
+
+ConstraintWrapperPtr createConstraintMiddlePoint(
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
+{
+ GCSPointPtr aPoint = thePoint->point();
+ std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
+ if (!aLine)
+ return ConstraintWrapperPtr();
+
+ std::list<GCSConstraintPtr> aConstrList;
+ aConstrList.push_back(
+ GCSConstraintPtr(new GCS::ConstraintPointOnPerpBisector(*aPoint, aLine->p1, aLine->p2)));
+ aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintPointOnLine(*aPoint, *aLine)));
+
+ return ConstraintWrapperPtr(
+ new PlaneGCSSolver_ConstraintWrapper(aConstrList, CONSTRAINT_MIDDLE_POINT));
+}
+
+
+ConstraintWrapperPtr createConstraintDistancePointPoint(
+ std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint1,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint2)
+{
+ GCSConstraintPtr aNewConstr(new GCS::ConstraintP2PDistance(
+ *(thePoint1->point()), *(thePoint2->point()), theValue->scalar()));
+ std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
+ new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_PT_DISTANCE));
+ aResult->setValueParameter(theValue);
+ return aResult;
+}
+
+ConstraintWrapperPtr createConstraintDistancePointLine(
+ std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_PointWrapper> thePoint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
+{
+ std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
+ GCSConstraintPtr aNewConstr(new GCS::ConstraintP2LDistance(
+ *(thePoint->point()), *(aLine), theValue->scalar()));
+ std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
+ new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_LINE_DISTANCE));
+ aResult->setValueParameter(theValue);
+ return aResult;
+}
+
+ConstraintWrapperPtr createConstraintRadius(
+ std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
+{
+ std::shared_ptr<GCS::Circle> aCircle =
+ std::dynamic_pointer_cast<GCS::Circle>(theEntity->entity());
+ GCSConstraintPtr aNewConstr(new GCS::ConstraintEqual(aCircle->rad, theValue->scalar()));
+ std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
+ new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_RADIUS));
+ aResult->setValueParameter(theValue);
+ return aResult;
+}
+
+ConstraintWrapperPtr createConstraintAngle(
+ ConstraintPtr theConstraint,
+ std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theValue,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
+{
+ std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
+ bool isLine1Rev = theConstraint->boolean(
+ SketchPlugin_ConstraintAngle::ANGLE_REVERSED_FIRST_LINE_ID())->value();
+ GCS::Point aLine1Pt1 = isLine1Rev ? aLine1->p2 : aLine1->p1;
+ GCS::Point aLine1Pt2 = isLine1Rev ? aLine1->p1 : aLine1->p2;
+
+ std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
+ bool isLine2Rev = theConstraint->boolean(
+ SketchPlugin_ConstraintAngle::ANGLE_REVERSED_SECOND_LINE_ID())->value();
+ GCS::Point aLine2Pt1 = isLine2Rev ? aLine2->p2 : aLine2->p1;
+ GCS::Point aLine2Pt2 = isLine2Rev ? aLine2->p1 : aLine2->p2;
+
+ GCSConstraintPtr aNewConstr(new GCS::ConstraintL2LAngle(
+ aLine1Pt1, aLine1Pt2, aLine2Pt1, aLine2Pt2, theValue->scalar()));
+
+ std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
+ new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_ANGLE));
+ aResult->setValueParameter(theValue);
+ return aResult;
+}
+
+ConstraintWrapperPtr createConstraintHorizVert(
+ const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity)
+{
+ std::shared_ptr<GCS::Line> aLine = std::dynamic_pointer_cast<GCS::Line>(theEntity->entity());
+ GCSConstraintPtr aNewConstr;
+ if (theType == CONSTRAINT_HORIZONTAL)
+ aNewConstr = GCSConstraintPtr(new GCS::ConstraintEqual(aLine->p1.y, aLine->p2.y));
+ else
+ aNewConstr = GCSConstraintPtr(new GCS::ConstraintEqual(aLine->p1.x, aLine->p2.x));
+
+ return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType));
+}
+
+ConstraintWrapperPtr createConstraintCollinear(
+ ConstraintPtr theConstraint,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
+{
+ std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
+ std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
+
+ // create two point-on-line constraints
+ std::list<GCSConstraintPtr> aConstrList;
+ aConstrList.push_back( GCSConstraintPtr(new GCS::ConstraintPointOnLine(aLine2->p1, *aLine1)) );
+ aConstrList.push_back( GCSConstraintPtr(new GCS::ConstraintPointOnLine(aLine2->p2, *aLine1)) );
+
+ return ConstraintWrapperPtr(
+ new PlaneGCSSolver_ConstraintWrapper(aConstrList, CONSTRAINT_COLLINEAR));
+}
+
+ConstraintWrapperPtr createConstraintParallel(
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
+{
+ std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
+ std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
+ GCSConstraintPtr aNewConstr(new GCS::ConstraintParallel(*(aLine1), *(aLine2)));
+
+ return ConstraintWrapperPtr(
+ new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PARALLEL));
+}
+
+ConstraintWrapperPtr createConstraintPerpendicular(
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
+{
+ std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
+ std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
+ GCSConstraintPtr aNewConstr(new GCS::ConstraintPerpendicular(*(aLine1), *(aLine2)));
+
+ return ConstraintWrapperPtr(
+ new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PERPENDICULAR));
+}
+
+ConstraintWrapperPtr createConstraintEqual(
+ const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2,
+ std::shared_ptr<PlaneGCSSolver_ScalarWrapper> theIntermed)
+{
+ if (theType == CONSTRAINT_EQUAL_LINE_ARC)
+ return ConstraintWrapperPtr(); // line-arc equivalence is not supported yet
+
+ std::list<GCSConstraintPtr> aConstrList;
+ if (theType == CONSTRAINT_EQUAL_LINES) {
+ std::shared_ptr<GCS::Line> aLine1 = std::dynamic_pointer_cast<GCS::Line>(theEntity1->entity());
+ std::shared_ptr<GCS::Line> aLine2 = std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
+
+ aConstrList.push_back(GCSConstraintPtr(
+ new GCS::ConstraintP2PDistance(aLine1->p1, aLine1->p2, theIntermed->scalar())));
+ aConstrList.push_back(GCSConstraintPtr(
+ new GCS::ConstraintP2PDistance(aLine2->p1, aLine2->p2, theIntermed->scalar())));
+ // update value of intermediate parameter
+ double x = *aLine1->p1.x - *aLine1->p2.x;
+ double y = *aLine1->p1.y - *aLine1->p2.y;
+ double aLen = sqrt(x*x + y*y);
+ theIntermed->setValue(aLen);
+ } else {
+ std::shared_ptr<GCS::Circle> aCirc1 =
+ std::dynamic_pointer_cast<GCS::Circle>(theEntity1->entity());
+ std::shared_ptr<GCS::Circle> aCirc2 =
+ std::dynamic_pointer_cast<GCS::Circle>(theEntity2->entity());
+
+ aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintEqual(aCirc1->rad, aCirc2->rad)));
+ }
+
+ std::shared_ptr<PlaneGCSSolver_ConstraintWrapper> aResult(
+ new PlaneGCSSolver_ConstraintWrapper(aConstrList, theType));
+ if (theIntermed)
+ aResult->setValueParameter(theIntermed);
+ return aResult;
+}
+
+ConstraintWrapperPtr createConstraintTangent(
+ const SketchSolver_ConstraintType& theType,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity1,
+ std::shared_ptr<PlaneGCSSolver_EntityWrapper> theEntity2)
+{
+ GCSConstraintPtr aNewConstr;
+ if (theType == CONSTRAINT_TANGENT_ARC_LINE || theType == CONSTRAINT_TANGENT_CIRCLE_LINE) {
+ std::shared_ptr<GCS::Circle> aCirc =
+ std::dynamic_pointer_cast<GCS::Circle>(theEntity1->entity());
+ std::shared_ptr<GCS::Line> aLine =
+ std::dynamic_pointer_cast<GCS::Line>(theEntity2->entity());
+
+ aNewConstr =
+ GCSConstraintPtr(new GCS::ConstraintP2LDistance(aCirc->center, *aLine, aCirc->rad));
+ } else {
+ std::shared_ptr<GCS::Circle> aCirc1 =
+ std::dynamic_pointer_cast<GCS::Circle>(theEntity1->entity());
+ std::shared_ptr<GCS::Circle> aCirc2 =
+ std::dynamic_pointer_cast<GCS::Circle>(theEntity2->entity());
+
+ double aDX = *(aCirc1->center.x) - *(aCirc2->center.x);
+ double aDY = *(aCirc1->center.y) - *(aCirc2->center.y);
+ double aDist = sqrt(aDX * aDX + aDY * aDY);
+ aNewConstr = GCSConstraintPtr(new GCS::ConstraintTangentCircumf(aCirc1->center, aCirc2->center,
+ aCirc1->rad, aCirc2->rad, (aDist < *(aCirc1->rad) || aDist < *(aCirc2->rad))));
+ }
+
+ return ConstraintWrapperPtr(new PlaneGCSSolver_ConstraintWrapper(aNewConstr, theType));
+}
+
+bool PlaneGCSSolver_Tools::isArcArcTangencyInternal(
+ EntityWrapperPtr theArc1, EntityWrapperPtr theArc2)
+{
+ std::shared_ptr<GCS::Circle> aCirc1 = std::dynamic_pointer_cast<GCS::Circle>(
+ GCS_ENTITY_WRAPPER(theArc1)->entity());
+ std::shared_ptr<GCS::Circle> aCirc2 = std::dynamic_pointer_cast<GCS::Circle>(
+ GCS_ENTITY_WRAPPER(theArc2)->entity());
+
+ if (!aCirc1 || !aCirc2)
+ return false;
+
+ double aDX = *(aCirc1->center.x) - *(aCirc2->center.x);
+ double aDY = *(aCirc1->center.y) - *(aCirc2->center.y);
+ double aDist = sqrt(aDX * aDX + aDY * aDY);
+
+ return (aDist < *(aCirc1->rad) || aDist < *(aCirc2->rad));
+}
--- /dev/null
+// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
+
+// File: PlaneGCSSolver_Tools.h
+// Created: 01 Mar 2017
+// Author: Artem ZHIDKOV
+
+#ifndef PlaneGCSSolver_Tools_H_
+#define PlaneGCSSolver_Tools_H_
+
+#include <SketchSolver_Constraint.h>
+#include <SketchPlugin_Constraint.h>
+
+#include <GeomAPI_Lin2d.h>
+#include <GeomAPI_Pnt2d.h>
+
+/** \namespace PlaneGCSSolver_Tools
+ * \ingroup Plugins
+ * \brief Converter tools
+ */
+namespace PlaneGCSSolver_Tools
+{
+ /// \brief Creates a solver's constraint using given SketchPlugin constraint
+ /// or returns empty pointer if not all attributes are correct
+ SolverConstraintPtr createConstraint(ConstraintPtr theConstraint);
+
+ /// \brief Creates temporary constraint to fix the feature after movement
+ SolverConstraintPtr createMovementConstraint(FeaturePtr theMovedFeature);
+
+ /// \brief Creates new constraint using given parameters
+ /// \param theConstraint [in] original constraint
+ /// \param theType [in] type of constraint
+ /// \param theValue [in] numeric characteristic of constraint
+ /// (e.g. distance or radius) if applicable
+ /// \param theEntity1 [in] first attribute of constraint
+ /// \param theEntity2 [in] second attribute of constraint
+ /// \param theEntity3 [in] third attribute of constraint
+ /// \param theEntity4 [in] fourth attribute of constraint
+ /// \return Created wrapper of constraints applicable for specific solver.
+ ConstraintWrapperPtr createConstraint(ConstraintPtr theConstraint,
+ const SketchSolver_ConstraintType& theType,
+ const EntityWrapperPtr& theValue,
+ const EntityWrapperPtr& theEntity1,
+ const EntityWrapperPtr& theEntity2 = EntityWrapperPtr(),
+ const EntityWrapperPtr& theEntity3 = EntityWrapperPtr(),
+ const EntityWrapperPtr& theEntity4 = EntityWrapperPtr());
+
+ /// \brief Convert entity to point
+ /// \return empty pointer if the entity is not a point
+ std::shared_ptr<GeomAPI_Pnt2d> point(EntityWrapperPtr theEntity);
+ /// \brief Convert entity to line
+ /// \return empty pointer if the entity is not a line
+ std::shared_ptr<GeomAPI_Lin2d> line(EntityWrapperPtr theEntity);
+
+ /// \brief Convert entity to line
+ /// \return empty pointer if the entity is not a line
+ std::shared_ptr<GeomAPI_Lin2d> line(FeaturePtr theFeature);
+
+ /// \brief Check if two connected arcs have centers
+ /// in same direction relatively to connection point
+ bool isArcArcTangencyInternal(EntityWrapperPtr theArc1,
+ EntityWrapperPtr theArc2);
+};
+
+#endif
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: SketchSolver_Builder.cpp
-// Created: 25 Mar 2015
-// Author: Artem ZHIDKOV
-
-#include "SketchSolver_Builder.h"
-#include <SketchSolver_Constraint.h>
-#include <SketchSolver_ConstraintAngle.h>
-#include <SketchSolver_ConstraintCoincidence.h>
-#include <SketchSolver_ConstraintCollinear.h>
-#include <SketchSolver_ConstraintDistance.h>
-#include <SketchSolver_ConstraintEqual.h>
-#include <SketchSolver_ConstraintFixed.h>
-#include <SketchSolver_ConstraintLength.h>
-#include <SketchSolver_ConstraintMiddle.h>
-#include <SketchSolver_ConstraintMirror.h>
-#include <SketchSolver_ConstraintTangent.h>
-#include <SketchSolver_ConstraintMultiRotation.h>
-#include <SketchSolver_ConstraintMultiTranslation.h>
-
-#ifdef _DEBUG
-#include <Events_InfoMessage.h>
-#include <ModelAPI_AttributeRefList.h>
-#include <ModelAPI_ResultConstruction.h>
-#include <SketchSolver_Error.h>
-#endif
-
-#include <SketchPlugin_ConstraintAngle.h>
-#include <SketchPlugin_ConstraintCoincidence.h>
-#include <SketchPlugin_ConstraintCollinear.h>
-#include <SketchPlugin_ConstraintDistance.h>
-#include <SketchPlugin_ConstraintEqual.h>
-#include <SketchPlugin_ConstraintLength.h>
-#include <SketchPlugin_ConstraintMiddle.h>
-#include <SketchPlugin_ConstraintMirror.h>
-#include <SketchPlugin_ConstraintRigid.h>
-#include <SketchPlugin_ConstraintTangent.h>
-#include <SketchPlugin_MultiRotation.h>
-#include <SketchPlugin_MultiTranslation.h>
-
-#include <cmath>
-
-SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theConstraint) const
-{
- SolverConstraintPtr aResult;
- DataPtr aData = theConstraint->data();
-
-#ifdef _DEBUG
- // Verify attributes of constraint and generate errors
- std::list<AttributePtr> anAttrList = aData->attributes(std::string());
- std::list<AttributePtr>::iterator anIter = anAttrList.begin();
- for (; anIter != anAttrList.end(); anIter++) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIter);
- if (aRefAttr) {
- if (aRefAttr->isObject() && aRefAttr->object()) {
- ResultConstructionPtr aRC =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(aRefAttr->object());
- if (!aRC)
- Events_InfoMessage("SketchSolver_Builder",
- SketchSolver_Error::NEED_OBJECT_NOT_FEATURE(), this).send();
- }
- continue;
- }
- AttributeRefListPtr aRefList = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(*anIter);
- if (aRefList) {
- std::list<ObjectPtr> aList = aRefList->list();
- std::list<ObjectPtr>::iterator aListIter = aList.begin();
- for (; aListIter != aList.end(); aListIter++) {
- ResultConstructionPtr aRC =
- std::dynamic_pointer_cast<ModelAPI_ResultConstruction>(*aListIter);
- if (*aListIter && !aRC)
- Events_InfoMessage("SketchSolver_Builder",
- SketchSolver_Error::NEED_OBJECT_NOT_FEATURE(), this).send();
- }
- }
- }
-#endif
-
- if (theConstraint->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintCoincidence(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintCollinear::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintCollinear(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintDistance::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintDistance(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintEqual::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintEqual(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintLength(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintMiddle::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintMiddle(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintMirror(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintTangent(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintRigid::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintFixed(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_MultiTranslation::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintMultiTranslation(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_MultiRotation::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintMultiRotation(theConstraint));
- } else if (theConstraint->getKind() == SketchPlugin_ConstraintAngle::ID()) {
- return SolverConstraintPtr(new SketchSolver_ConstraintAngle(theConstraint));
- }
- // All other types of constraints
- return SolverConstraintPtr(new SketchSolver_Constraint(theConstraint));
-}
-
-SolverConstraintPtr SketchSolver_Builder::createMovementConstraint(FeaturePtr theMovedFeature) const
-{
- return SolverConstraintPtr(new SketchSolver_ConstraintFixed(theMovedFeature));
-}
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: SketchSolver_Builder.h
-// Created: 25 Mar 2015
-// Author: Artem ZHIDKOV
-
-#ifndef SketchSolver_Builder_H_
-#define SketchSolver_Builder_H_
-
-#include <SketchSolver_Constraint.h>
-#include <SketchPlugin_Constraint.h>
-
-#include <GeomAPI_Lin2d.h>
-#include <GeomAPI_Pnt2d.h>
-
-/** \class SketchSolver_Builder
- * \ingroup Plugins
- * \brief Abstract class for builders of solver's entities
- */
-class SketchSolver_Builder
-{
-public:
- /// \brief Creates a storage specific for used solver
- virtual StoragePtr createStorage(const SolverPtr&) const = 0;
- /// \brief Creates specific solver
- virtual SolverPtr createSolver() const = 0;
-
- /// \brief Creates a solver's constraint using given SketchPlugin constraint
- /// or returns empty pointer if not all attributes are correct
- SolverConstraintPtr createConstraint(ConstraintPtr theConstraint) const;
-
- /// \brief Creates temporary constraint to fix the feature after movement
- SolverConstraintPtr createMovementConstraint(FeaturePtr theMovedFeature) const;
-
- /// \brief Creates new constraint using given parameters
- /// \param theConstraint [in] original constraint
- /// \param theType [in] type of constraint
- /// \param theValue [in] numeric characteristic of constraint
- /// (e.g. distance or radius) if applicable
- /// \param theEntity1 [in] first attribute of constraint
- /// \param theEntity2 [in] second attribute of constraint
- /// \param theEntity3 [in] third attribute of constraint
- /// \param theEntity4 [in] fourth attribute of constraint
- /// \return Created wrapper of constraints applicable for specific solver.
- virtual ConstraintWrapperPtr
- createConstraint(ConstraintPtr theConstraint,
- const SketchSolver_ConstraintType& theType,
- const EntityWrapperPtr& theValue,
- const EntityWrapperPtr& theEntity1,
- const EntityWrapperPtr& theEntity2 = EntityWrapperPtr(),
- const EntityWrapperPtr& theEntity3 = EntityWrapperPtr(),
- const EntityWrapperPtr& theEntity4 = EntityWrapperPtr()) const = 0;
-
- /// \brief Creates new multi-translation or multi-rotation constraint
- /// \param theConstraint [in] original constraint
- /// \param theType [in] type of constraint
- /// \param theValue [in] numeric characteristic of constraint (angle for multi-rotation)
- /// if applicable
- /// \param theFullValue [in] indicates theValue shows full translation delta/rotation angle or
- /// delta/angle between neighbor entities
- /// \param thePoint1 [in] center for multi-rotation or start point for multi-translation
- /// \param thePoint2 [in] end point for multi-translation (empty for multi-rotation)
- /// \param theTrsfEnt [in] list of transformed entities
- virtual ConstraintWrapperPtr
- createConstraint(ConstraintPtr theConstraint,
- const SketchSolver_ConstraintType& theType,
- const EntityWrapperPtr& theValue,
- const bool theFullValue,
- const EntityWrapperPtr& thePoint1,
- const EntityWrapperPtr& thePoint2,
- const std::list<EntityWrapperPtr>& theTrsfEnt) const = 0;
-
-
- /// \brief Convert entity to point
- /// \return empty pointer if the entity is not a point
- virtual std::shared_ptr<GeomAPI_Pnt2d> point(EntityWrapperPtr theEntity) const = 0;
- /// \brief Convert entity to line
- /// \return empty pointer if the entity is not a line
- virtual std::shared_ptr<GeomAPI_Lin2d> line(EntityWrapperPtr theEntity) const = 0;
-
- /// \brief Convert entity to line
- /// \return empty pointer if the entity is not a line
- virtual std::shared_ptr<GeomAPI_Lin2d> line(FeaturePtr theFeature) const = 0;
-
- /// \brief Check if two connected arcs have centers
- /// in same direction relatively to connection point
- virtual bool isArcArcTangencyInternal(EntityWrapperPtr theArc1,
- EntityWrapperPtr theArc2) const = 0;
-};
-
-typedef std::shared_ptr<SketchSolver_Builder> BuilderPtr;
-
-#endif
// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
#include <SketchSolver_Constraint.h>
-#include <SketchSolver_Group.h>
#include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
#include <PlaneGCSSolver_AttributeBuilder.h>
+#include <PlaneGCSSolver_Tools.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_Circle.h>
if (aConstrType == CONSTRAINT_UNKNOWN)
aConstrType = getType();
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
- ConstraintWrapperPtr aNewConstraint = aBuilder->createConstraint(
+ ConstraintWrapperPtr aNewConstraint = PlaneGCSSolver_Tools::createConstraint(
myBaseConstraint, aConstrType,
aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
myStorage->addConstraint(myBaseConstraint, aNewConstraint);
myAttributes.clear();
DataPtr aData = myBaseConstraint->data();
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
myType = TYPE(myBaseConstraint);
#include <SketchSolver_ConstraintCoincidence.h>
#include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
+#include <PlaneGCSSolver_Tools.h>
#include <PlaneGCSSolver_UpdateCoincidence.h>
void SketchSolver_ConstraintCoincidence::process()
return;
}
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
- mySolverConstraint = aBuilder->createConstraint(
+ mySolverConstraint = PlaneGCSSolver_Tools::createConstraint(
myBaseConstraint, getType(),
aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]);
#include <SketchSolver_ConstraintMirror.h>
#include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
+#include <PlaneGCSSolver_Tools.h>
#include <PlaneGCSSolver_UpdateFeature.h>
#include <GeomAPI_XY.h>
void SketchSolver_ConstraintMirror::adjustConstraint()
{
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
-
AttributeRefAttrPtr aMirrLineRefAttr =
myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A());
std::shared_ptr<GeomAPI_Lin2d> aMirrorLine =
- aBuilder->line(ModelAPI_Feature::feature(aMirrLineRefAttr->object()));
+ PlaneGCSSolver_Tools::line(ModelAPI_Feature::feature(aMirrLineRefAttr->object()));
AttributeRefListPtr aBaseRefList =
myBaseConstraint->reflist(SketchPlugin_Constraint::ENTITY_B());
#include <SketchSolver_ConstraintTangent.h>
#include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
+
+#include <PlaneGCSSolver_Tools.h>
#include <GeomAPI_Pnt2d.h>
#include <SketchPlugin_Circle.h>
return aCoincidences.size() <= 1;
}
-/// \brief Check if two connected arcs have centers
-/// in same direction relatively to connection point
-static bool isInternalTangency(EntityWrapperPtr theEntity1, EntityWrapperPtr theEntity2)
-{
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
- return aBuilder->isArcArcTangencyInternal(theEntity1, theEntity2);
-}
-
-
void SketchSolver_ConstraintTangent::getAttributes(
EntityWrapperPtr& theValue,
std::vector<EntityWrapperPtr>& theAttributes)
}
else if (aNbArcs == 2) {
myType = CONSTRAINT_TANGENT_ARC_ARC;
- isArcArcInternal = isInternalTangency(theAttributes[2], theAttributes[3]);
+ isArcArcInternal =
+ PlaneGCSSolver_Tools::isArcArcTangencyInternal(theAttributes[2], theAttributes[3]);
}
else {
myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE();
EntityWrapperPtr anEntity2 =
myStorage->entity(myBaseConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- if (isArcArcInternal != isInternalTangency(anEntity1, anEntity2)) {
+ if (isArcArcInternal != PlaneGCSSolver_Tools::isArcArcTangencyInternal(anEntity1, anEntity2)) {
// fully rebuld constraint, because it is unable to access attributes of PlaneGCS constraint
remove();
process();
#include <SketchSolver_Manager.h>
#include <PlaneGCSSolver_Solver.h>
+#include <PlaneGCSSolver_Storage.h>
+#include <PlaneGCSSolver_Tools.h>
#include <Events_InfoMessage.h>
#include <ModelAPI_AttributeString.h>
SketchSolver_Group::SketchSolver_Group(const CompositeFeaturePtr& theWorkplane)
: mySketch(theWorkplane),
- myPrevResult(STATUS_UNKNOWN),
+ myPrevResult(PlaneGCSSolver_Solver::STATUS_UNKNOWN),
myIsEventsBlocked(false)
{
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
- mySketchSolver = aBuilder->createSolver();
- myStorage = aBuilder->createStorage(mySketchSolver);
+ mySketchSolver = SolverPtr(new PlaneGCSSolver_Solver);
+ myStorage = StoragePtr(new PlaneGCSSolver_Storage(mySketchSolver));
}
SketchSolver_Group::~SketchSolver_Group()
{
bool isNewConstraint = myConstraints.find(theConstraint) == myConstraints.end();
if (isNewConstraint) {
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
// Add constraint to the current group
- SolverConstraintPtr aConstraint = aBuilder->createConstraint(theConstraint);
+ SolverConstraintPtr aConstraint = PlaneGCSSolver_Tools::createConstraint(theConstraint);
if (!aConstraint)
return false;
aConstraint->process(myStorage, myIsEventsBlocked);
bool SketchSolver_Group::moveFeature(FeaturePtr theFeature)
{
- BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder();
-
// Create temporary Fixed constraint
- SolverConstraintPtr aConstraint = aBuilder->createMovementConstraint(theFeature);
+ SolverConstraintPtr aConstraint = PlaneGCSSolver_Tools::createMovementConstraint(theFeature);
if (!aConstraint)
return false;
aConstraint->process(myStorage, myIsEventsBlocked);
bool aResolved = false;
bool isGroupEmpty = isEmpty() && myStorage->isEmpty();
if (myStorage->isNeedToResolve() &&
- (!isGroupEmpty || !myConflictingConstraints.empty() || myPrevResult == STATUS_FAILED)) {
-//// if (!mySketchSolver)
-//// mySketchSolver = SketchSolver_Manager::instance()->builder()->createSolver();
-
-//// mySketchSolver->calculateFailedConstraints(false);
-//// myStorage->initializeSolver();
-//// mySketchSolver->prepare();
+ (!isGroupEmpty || !myConflictingConstraints.empty() ||
+ myPrevResult == PlaneGCSSolver_Solver::STATUS_FAILED)) {
- SketchSolver_SolveStatus aResult = STATUS_OK;
+ PlaneGCSSolver_Solver::SolveStatus aResult = PlaneGCSSolver_Solver::STATUS_OK;
try {
- if (!isGroupEmpty) {
- // To avoid overconstraint situation, we will remove temporary constraints one-by-one
- // and try to find the case without overconstraint
- bool isLastChance = false;
- while (true) {
- aResult = mySketchSolver->solve();
- if (aResult == STATUS_OK || aResult == STATUS_EMPTYSET || isLastChance)
- break;
-//// // try to update parameters and resolve once again
-//// ConstraintConstraintMap::iterator aConstrIt = myConstraints.begin();
-//// for (; aConstrIt != myConstraints.end(); ++aConstrIt)
-//// aConstrIt->second->update();
- isLastChance = true;
-
- removeTemporaryConstraints();
- mySketchSolver->calculateFailedConstraints(true); // something failed => need to find it
-//// myStorage->initializeSolver();
- }
- }
+ if (!isGroupEmpty)
+ aResult = mySketchSolver->solve();
} catch (...) {
-// Events_Error::send(SketchSolver_Error::SOLVESPACE_CRASH(), this);
getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())
->setValue(SketchSolver_Error::SOLVESPACE_CRASH());
- if (myPrevResult == STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
+ if (myPrevResult == PlaneGCSSolver_Solver::STATUS_OK ||
+ myPrevResult == PlaneGCSSolver_Solver::STATUS_UNKNOWN) {
// the error message should be changed before sending the message
sendMessage(EVENT_SOLVER_FAILED);
- myPrevResult = STATUS_FAILED;
+ myPrevResult = PlaneGCSSolver_Solver::STATUS_FAILED;
}
mySketchSolver->undo();
return false;
}
// solution succeeded, store results into correspondent attributes
- if (aResult == STATUS_OK || aResult == STATUS_EMPTYSET) {
+ if (aResult == PlaneGCSSolver_Solver::STATUS_OK ||
+ aResult == PlaneGCSSolver_Solver::STATUS_EMPTYSET) {
myStorage->setNeedToResolve(false);
myStorage->refresh();
//// updateMultiConstraints(myConstraints);
//// if (myStorage->isNeedToResolve())
//// resolveConstraints();
- if (myPrevResult != STATUS_OK || myPrevResult == STATUS_UNKNOWN) {
+ if (myPrevResult != PlaneGCSSolver_Solver::STATUS_OK ||
+ myPrevResult == PlaneGCSSolver_Solver::STATUS_UNKNOWN) {
getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())->setValue("");
std::set<ObjectPtr> aConflicting = myConflictingConstraints;
myConflictingConstraints.clear();
- myPrevResult = STATUS_OK;
+ myPrevResult = PlaneGCSSolver_Solver::STATUS_OK;
// the error message should be changed before sending the message
sendMessage(EVENT_SOLVER_REPAIRED, aConflicting);
}
getWorkplane()->string(SketchPlugin_Sketch::SOLVER_ERROR())
->setValue(SketchSolver_Error::CONSTRAINTS());
if (myPrevResult != aResult ||
- myPrevResult == STATUS_UNKNOWN ||
- myPrevResult == STATUS_FAILED) {
+ myPrevResult == PlaneGCSSolver_Solver::STATUS_UNKNOWN ||
+ myPrevResult == PlaneGCSSolver_Solver::STATUS_FAILED) {
// Obtain list of conflicting constraints
std::set<ObjectPtr> aConflicting = myStorage->getConflictingConstraints(mySketchSolver);
#include <SketchSolver_Constraint.h>
#include <SketchSolver_Storage.h>
-#include <SketchSolver_ISolver.h>
+
+#include <PlaneGCSSolver_Solver.h>
#include <SketchPlugin_Constraint.h>
SolverPtr mySketchSolver; ///< Solver for set of equations obtained by constraints
/// Result of previous solution of the set of constraints
- SketchSolver_SolveStatus myPrevResult;
+ PlaneGCSSolver_Solver::SolveStatus myPrevResult;
std::set<ObjectPtr> myConflictingConstraints; ///< List of conflicting constraints
bool myIsEventsBlocked; ///< shows the events are blocked for this group
/// \brief Return type of current entity
virtual SketchSolver_ConstraintType type() const = 0;
- /// \brief Assign list of constrained objects
- void setEntities(const std::list<EntityWrapperPtr>& theEntities)
- { myConstrained = theEntities; }
- /// \brief Return list of constrained objects
- const std::list<EntityWrapperPtr>& entities() const
- { return myConstrained; }
-
/// \brief Assign numeric parameter of constraint
virtual void setValue(const double& theValue) = 0;
/// \brief Return numeric parameter of constraint
virtual double value() const = 0;
- /// \brief Store a boolean flag for full value using
- void setIsFullValue(const bool& theFullValue)
- { myIsFullValue = theFullValue; }
- /// \brief Return a flag of a full value using
- const bool& isFullValue() const
- { return myIsFullValue; }
-
protected:
- ConstraintID myID;
- std::list<EntityWrapperPtr> myConstrained;
- bool myIsFullValue;
+ ConstraintID myID;
};
typedef std::shared_ptr<SketchSolver_IConstraintWrapper> ConstraintWrapperPtr;
+++ /dev/null
-// Copyright (C) 2014-20xx CEA/DEN, EDF R&D
-
-// File: SketchSolver_ISolver.h
-// Created: 30 Nov 2015
-// Author: Artem ZHIDKOV
-
-#ifndef SketchSolver_ISolver_H_
-#define SketchSolver_ISolver_H_
-
-#include <SketchSolver.h>
-
-#include <memory>
-
-/// The result of constraints solution
-enum SketchSolver_SolveStatus {
- STATUS_OK,
- STATUS_INCONSISTENT,
- STATUS_EMPTYSET,
- STATUS_FAILED, // set if no one other status is applicable
- STATUS_UNKNOWN // set for newly created groups
-};
-
-
-/**
- * Interface providing operations to solve sketches.
- */
-class SketchSolver_ISolver
-{
-public:
- virtual ~SketchSolver_ISolver() {}
-
- /// \brief Set or unset the flag which allows to find all failed constraints
- void calculateFailedConstraints(bool theSic)
- { myFindFaileds = theSic; }
-
- /// \brief Prepare for solving. Store initial values of parameters for undo
- virtual void prepare() = 0;
-
- /// \brief Solve the set of equations
- /// \return identifier whether solution succeeded
- virtual SketchSolver_SolveStatus solve() = 0;
-
- /// \brief Revert solution to initial values
- virtual void undo() = 0;
-
- /// \brief Check the constraint is conflicted with others
- virtual bool isConflicting(const ConstraintID& theConstraint) const = 0;
-
- /// \brief Degrees of freedom
- virtual int dof() = 0;
-
-protected:
- bool myFindFaileds; ///< flag to find conflicting or inappropriate constraints
-};
-
-typedef std::shared_ptr<SketchSolver_ISolver> SolverPtr;
-
-#endif
myGroups.clear();
}
-void SketchSolver_Manager::setBuilder(BuilderPtr theBuilder)
-{
- myBuilder = theBuilder;
-}
-
-BuilderPtr SketchSolver_Manager::builder()
-{
- return myBuilder;
-}
-
bool SketchSolver_Manager::groupMessages()
{
return true;
#include "SketchSolver.h"
#include <SketchSolver_Group.h>
-#include <SketchSolver_Builder.h>
#include <Events_Listener.h>
#include <SketchPlugin_Constraint.h>
*/
virtual bool groupMessages();
- /// \brief Initialize builder for solver's data structure entities
- /// \param theBuilder [in] solver's specific builder
- void setBuilder(BuilderPtr theBuilder);
- /// \brief Returns the builder specific for the solver
- BuilderPtr builder();
-
protected:
SketchSolver_Manager();
~SketchSolver_Manager();
private:
std::list<SketchGroupPtr> myGroups; ///< Groups of constraints
- BuilderPtr myBuilder; ///< Builder for solver's entities
/// true if computation is performed and all "updates" are generated by this algo
/// and needs no recomputation
bool myIsComputed;
#include <SketchSolver.h>
#include <SketchSolver_IConstraintWrapper.h>
#include <SketchSolver_IEntityWrapper.h>
-#include <SketchSolver_ISolver.h>
+#include <PlaneGCSSolver_Solver.h>
#include <PlaneGCSSolver_UpdateFeature.h>
#include <ModelAPI_Attribute.h>