From: azv Date: Wed, 1 Mar 2017 06:54:40 +0000 (+0300) Subject: Simplify sketcher model. Remove obsolete files and classes. X-Git-Tag: V_2.7.0~260 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=2982303b80faa9bed2a7715d2778fd10d8cd0465;p=modules%2Fshaper.git Simplify sketcher model. Remove obsolete files and classes. --- diff --git a/src/SketchSolver/CMakeLists.txt b/src/SketchSolver/CMakeLists.txt index 60fa8f05a..d6b370d79 100644 --- a/src/SketchSolver/CMakeLists.txt +++ b/src/SketchSolver/CMakeLists.txt @@ -19,10 +19,8 @@ SET(SKETCHSOLVER_HEADERS 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 ) @@ -46,7 +44,6 @@ SET(SKETCHSOLVER_CONSTRAINT_HEADERS SET(SKETCHSOLVER_SOURCES SketchSolver_Group.cpp - SketchSolver_Builder.cpp SketchSolver_Manager.cpp SketchSolver_Storage.cpp ) diff --git a/src/SketchSolver/PlaneGCSSolver/CMakeLists.txt b/src/SketchSolver/PlaneGCSSolver/CMakeLists.txt index 4866a5b36..91bc90b79 100644 --- a/src/SketchSolver/PlaneGCSSolver/CMakeLists.txt +++ b/src/SketchSolver/PlaneGCSSolver/CMakeLists.txt @@ -5,24 +5,24 @@ FIND_PACKAGE(PlaneGCS REQUIRED) 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 diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp deleted file mode 100644 index fb81a64a2..000000000 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp +++ /dev/null @@ -1,532 +0,0 @@ -// Copyright (C) 2014-20xx CEA/DEN, EDF R&D - -// File: PlaneGCSSolver_Builder.cpp -// Created: 14 Dec 2015 -// Author: Artem ZHIDKOV - -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include - -#include - - -#define GCS_ENTITY_WRAPPER(x) std::dynamic_pointer_cast(x) -#define GCS_POINT_WRAPPER(x) std::dynamic_pointer_cast(x) -#define GCS_SCALAR_WRAPPER(x) std::dynamic_pointer_cast(x) - - - -static ConstraintWrapperPtr - createConstraintCoincidence(std::shared_ptr thePoint1, - std::shared_ptr thePoint2); -static ConstraintWrapperPtr - createConstraintPointOnEntity(const SketchSolver_ConstraintType& theType, - std::shared_ptr thePoint, - std::shared_ptr theEntity); -static ConstraintWrapperPtr - createConstraintDistancePointPoint(std::shared_ptr theValue, - std::shared_ptr thePoint1, - std::shared_ptr thePoint2); -static ConstraintWrapperPtr - createConstraintDistancePointLine(std::shared_ptr theValue, - std::shared_ptr thePoint, - std::shared_ptr theEntity); -static ConstraintWrapperPtr - createConstraintRadius(std::shared_ptr theValue, - std::shared_ptr theEntity); -static ConstraintWrapperPtr - createConstraintAngle(ConstraintPtr theConstraint, - std::shared_ptr theValue, - std::shared_ptr theEntity1, - std::shared_ptr theEntity2); -static ConstraintWrapperPtr - createConstraintHorizVert(const SketchSolver_ConstraintType& theType, - std::shared_ptr theEntity); -static ConstraintWrapperPtr - createConstraintParallel(std::shared_ptr theEntity1, - std::shared_ptr theEntity2); -static ConstraintWrapperPtr - createConstraintPerpendicular(std::shared_ptr theEntity1, - std::shared_ptr theEntity2); -static ConstraintWrapperPtr - createConstraintEqual(const SketchSolver_ConstraintType& theType, - std::shared_ptr theEntity1, - std::shared_ptr theEntity2, - std::shared_ptr theIntermed); -static ConstraintWrapperPtr - createConstraintTangent(const SketchSolver_ConstraintType& theType, - std::shared_ptr theEntity1, - std::shared_ptr theEntity2); -static ConstraintWrapperPtr - createConstraintCollinear(ConstraintPtr theConstraint, - std::shared_ptr theEntity1, - std::shared_ptr theEntity2); -static ConstraintWrapperPtr - createConstraintMiddlePoint(std::shared_ptr thePoint, - std::shared_ptr 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 aPoint1 = GCS_POINT_WRAPPER(thePoint1); - std::shared_ptr 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& theTrsfEnt) const -{ - if (theType != CONSTRAINT_MULTI_ROTATION && theType != CONSTRAINT_MULTI_TRANSLATION) - return ConstraintWrapperPtr(); - - std::list aConstrAttrList = theTrsfEnt; - if (thePoint2) - aConstrAttrList.push_front(thePoint2); - aConstrAttrList.push_front(thePoint1); - - ScalarWrapperPtr aValue = GCS_SCALAR_WRAPPER(theValue); - - std::shared_ptr aResult( - new PlaneGCSSolver_ConstraintWrapper(std::list(), theType)); - aResult->setEntities(aConstrAttrList); - if (aValue) - aResult->setValueParameter(aValue); - aResult->setIsFullValue(theFullValue); - return aResult; -} - -std::shared_ptr PlaneGCSSolver_Builder::point(EntityWrapperPtr theEntity) const -{ - if (theEntity->type() != ENTITY_POINT) - return std::shared_ptr(); - - std::shared_ptr aPointWrapper = - std::dynamic_pointer_cast(theEntity); - const GCSPointPtr& aPoint = aPointWrapper->point(); - return std::shared_ptr(new GeomAPI_Pnt2d(*aPoint->x, *aPoint->y)); -} - -std::shared_ptr PlaneGCSSolver_Builder::line(EntityWrapperPtr theEntity) const -{ - if (theEntity->type() != ENTITY_LINE) - return std::shared_ptr(); - - std::shared_ptr anEntity = - std::dynamic_pointer_cast(theEntity); - std::shared_ptr aLine = std::dynamic_pointer_cast(anEntity->entity()); - return std::shared_ptr( - new GeomAPI_Lin2d(*(aLine->p1.x), *(aLine->p1.y), *(aLine->p2.x), *(aLine->p2.y))); -} - -std::shared_ptr PlaneGCSSolver_Builder::line(FeaturePtr theFeature) const -{ - if (theFeature->getKind() != SketchPlugin_Line::ID()) - return std::shared_ptr(); - - AttributePoint2DPtr aStart = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Line::START_ID())); - AttributePoint2DPtr aEnd = std::dynamic_pointer_cast( - theFeature->attribute(SketchPlugin_Line::END_ID())); - - return std::shared_ptr(new GeomAPI_Lin2d(aStart->pnt(), aEnd->pnt())); -} - - - - - -// ================ Auxiliary functions ========================== -ConstraintWrapperPtr createConstraintCoincidence( - std::shared_ptr thePoint1, - std::shared_ptr thePoint2) -{ - GCSPointPtr aPoint1 = thePoint1->point(); - GCSPointPtr aPoint2 = thePoint2->point(); - - // Create equality constraint for corresponding attributes of the points - std::list 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 thePoint, - std::shared_ptr theEntity) -{ - GCSConstraintPtr aNewConstr; - - switch (theEntity->type()) { - case ENTITY_LINE: { - std::shared_ptr aLine = std::dynamic_pointer_cast(theEntity->entity()); - aNewConstr = GCSConstraintPtr(new GCS::ConstraintPointOnLine(*(thePoint->point()), *aLine)); - break; - } - case ENTITY_ARC: - case ENTITY_CIRCLE: { - std::shared_ptr aCirc = - std::dynamic_pointer_cast(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 thePoint, - std::shared_ptr theEntity) -{ - GCSPointPtr aPoint = thePoint->point(); - std::shared_ptr aLine = std::dynamic_pointer_cast(theEntity->entity()); - if (!aLine) - return ConstraintWrapperPtr(); - - std::list 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 theValue, - std::shared_ptr thePoint1, - std::shared_ptr thePoint2) -{ - GCSConstraintPtr aNewConstr(new GCS::ConstraintP2PDistance( - *(thePoint1->point()), *(thePoint2->point()), theValue->scalar())); - std::shared_ptr aResult( - new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_PT_DISTANCE)); - aResult->setValueParameter(theValue); - return aResult; -} - -ConstraintWrapperPtr createConstraintDistancePointLine( - std::shared_ptr theValue, - std::shared_ptr thePoint, - std::shared_ptr theEntity) -{ - std::shared_ptr aLine = std::dynamic_pointer_cast(theEntity->entity()); - GCSConstraintPtr aNewConstr(new GCS::ConstraintP2LDistance( - *(thePoint->point()), *(aLine), theValue->scalar())); - std::shared_ptr aResult( - new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_LINE_DISTANCE)); - aResult->setValueParameter(theValue); - return aResult; -} - -ConstraintWrapperPtr createConstraintRadius( - std::shared_ptr theValue, - std::shared_ptr theEntity) -{ - std::shared_ptr aCircle = - std::dynamic_pointer_cast(theEntity->entity()); - GCSConstraintPtr aNewConstr(new GCS::ConstraintEqual(aCircle->rad, theValue->scalar())); - std::shared_ptr aResult( - new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_RADIUS)); - aResult->setValueParameter(theValue); - return aResult; -} - -ConstraintWrapperPtr createConstraintAngle( - ConstraintPtr theConstraint, - std::shared_ptr theValue, - std::shared_ptr theEntity1, - std::shared_ptr theEntity2) -{ - std::shared_ptr aLine1 = std::dynamic_pointer_cast(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 aLine2 = std::dynamic_pointer_cast(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 aResult( - new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_ANGLE)); - aResult->setValueParameter(theValue); - return aResult; -} - -ConstraintWrapperPtr createConstraintHorizVert( - const SketchSolver_ConstraintType& theType, - std::shared_ptr theEntity) -{ - std::shared_ptr aLine = std::dynamic_pointer_cast(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 theEntity1, - std::shared_ptr theEntity2) -{ - std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); - std::shared_ptr aLine2 = std::dynamic_pointer_cast(theEntity2->entity()); - - // create two point-on-line constraints - std::list 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 theEntity1, - std::shared_ptr theEntity2) -{ - std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); - std::shared_ptr aLine2 = std::dynamic_pointer_cast(theEntity2->entity()); - GCSConstraintPtr aNewConstr(new GCS::ConstraintParallel(*(aLine1), *(aLine2))); - - return ConstraintWrapperPtr( - new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PARALLEL)); -} - -ConstraintWrapperPtr createConstraintPerpendicular( - std::shared_ptr theEntity1, - std::shared_ptr theEntity2) -{ - std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); - std::shared_ptr aLine2 = std::dynamic_pointer_cast(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 theEntity1, - std::shared_ptr theEntity2, - std::shared_ptr theIntermed) -{ - if (theType == CONSTRAINT_EQUAL_LINE_ARC) - return ConstraintWrapperPtr(); // line-arc equivalence is not supported yet - - std::list aConstrList; - if (theType == CONSTRAINT_EQUAL_LINES) { - std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); - std::shared_ptr aLine2 = std::dynamic_pointer_cast(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 aCirc1 = - std::dynamic_pointer_cast(theEntity1->entity()); - std::shared_ptr aCirc2 = - std::dynamic_pointer_cast(theEntity2->entity()); - - aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintEqual(aCirc1->rad, aCirc2->rad))); - } - - std::shared_ptr aResult( - new PlaneGCSSolver_ConstraintWrapper(aConstrList, theType)); - if (theIntermed) - aResult->setValueParameter(theIntermed); - return aResult; -} - -ConstraintWrapperPtr createConstraintTangent( - const SketchSolver_ConstraintType& theType, - std::shared_ptr theEntity1, - std::shared_ptr theEntity2) -{ - GCSConstraintPtr aNewConstr; - if (theType == CONSTRAINT_TANGENT_ARC_LINE || theType == CONSTRAINT_TANGENT_CIRCLE_LINE) { - std::shared_ptr aCirc = - std::dynamic_pointer_cast(theEntity1->entity()); - std::shared_ptr aLine = - std::dynamic_pointer_cast(theEntity2->entity()); - - aNewConstr = - GCSConstraintPtr(new GCS::ConstraintP2LDistance(aCirc->center, *aLine, aCirc->rad)); - } else { - std::shared_ptr aCirc1 = - std::dynamic_pointer_cast(theEntity1->entity()); - std::shared_ptr aCirc2 = - std::dynamic_pointer_cast(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 aCirc1 = std::dynamic_pointer_cast( - GCS_ENTITY_WRAPPER(theArc1)->entity()); - std::shared_ptr aCirc2 = std::dynamic_pointer_cast( - 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)); -} diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h deleted file mode 100644 index caf81eb21..000000000 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h +++ /dev/null @@ -1,92 +0,0 @@ -// 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 - -#include -#include - -#include - -#include - -/** \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& theTrsfEnt) const; - - /// \brief Convert entity to point - /// \return empty pointer if the entity is not a point - virtual std::shared_ptr point(EntityWrapperPtr theEntity) const; - /// \brief Convert entity to line - /// \return empty pointer if the entity is not a line - virtual std::shared_ptr line(EntityWrapperPtr theEntity) const; - - /// \brief Convert entity to line - /// \return empty pointer if the entity is not a line - virtual std::shared_ptr 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 diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index 1193ad357..3e77208aa 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -4,7 +4,7 @@ // Created: 14 Dec 2014 // Author: Artem ZHIDKOV -#include "PlaneGCSSolver_Solver.h" +#include #include @@ -66,7 +66,7 @@ void PlaneGCSSolver_Solver::removeParameters(const GCS::SET_pD& theParams) } } -SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve() +PlaneGCSSolver_Solver::SolveStatus PlaneGCSSolver_Solver::solve() { // clear list of conflicting constraints if (myConfCollected) { @@ -82,7 +82,7 @@ SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve() 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) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index 9c25caf72..0465924cb 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -7,16 +7,24 @@ #ifndef PlaneGCSSolver_Solver_H_ #define PlaneGCSSolver_Solver_H_ -#include #include #include #include /// \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(); @@ -36,20 +44,16 @@ public: /// \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(); @@ -70,4 +74,6 @@ private: int myDOF; ///< degrees of freedom }; +typedef std::shared_ptr SolverPtr; + #endif diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index 67ada8770..62451f130 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -5,7 +5,6 @@ // Author: Artem ZHIDKOV #include -#include #include #include #include @@ -19,6 +18,7 @@ #include #include #include +#include #include #include @@ -266,9 +266,7 @@ bool PlaneGCSSolver_Storage::removeConstraint(ConstraintPtr theConstraint) if (aFound != myConstraintMap.end()) { ConstraintID anID = aFound->second->id(); // Remove solver's constraints - std::shared_ptr aSolver = - std::dynamic_pointer_cast(mySketchSolver); - aSolver->removeConstraint(anID); + mySketchSolver->removeConstraint(anID); // Remove constraint myConstraintMap.erase(aFound); @@ -305,8 +303,7 @@ void PlaneGCSSolver_Storage::removeInvalidEntities() std::map::iterator aFound = myArcConstraintMap.find(aFIter->second); if (aFound != myArcConstraintMap.end()) { - std::dynamic_pointer_cast( - mySketchSolver)->removeConstraint(aFound->second->id()); + mySketchSolver->removeConstraint(aFound->second->id()); myArcConstraintMap.erase(aFound); } } @@ -338,66 +335,12 @@ void PlaneGCSSolver_Storage::removeInvalidEntities() double* PlaneGCSSolver_Storage::createParameter() { - return std::dynamic_pointer_cast(mySketchSolver)->createParameter(); + return mySketchSolver->createParameter(); } void PlaneGCSSolver_Storage::removeParameters(const GCS::SET_pD& theParams) { - std::dynamic_pointer_cast(mySketchSolver)->removeParameters(theParams); -} - - -bool PlaneGCSSolver_Storage::isRedundant( - GCSConstraintPtr theCheckedConstraint, - ConstraintWrapperPtr theParentConstraint, - std::list >& 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 aSubs = theParentConstraint->entities(); - std::shared_ptr aPoint = aBuilder->point(aSubs.front()); - std::shared_ptr 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 >::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 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 diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h index ca8fa2221..752651d33 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h @@ -11,7 +11,6 @@ #include #include -#include class PlaneGCSSolver_EntityBuilder; @@ -68,14 +67,6 @@ public: 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 >& theCoincidentPoints) const; - /// \brief Convert feature using specified builder. EntityWrapperPtr createFeature(const FeaturePtr& theFeature, PlaneGCSSolver_EntityBuilder* theBuilder); diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp new file mode 100644 index 000000000..5f10b68e1 --- /dev/null +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp @@ -0,0 +1,541 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: SketchSolver_Builder.cpp +// Created: 25 Mar 2015 +// Author: Artem ZHIDKOV + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#define GCS_ENTITY_WRAPPER(x) std::dynamic_pointer_cast(x) +#define GCS_POINT_WRAPPER(x) std::dynamic_pointer_cast(x) +#define GCS_SCALAR_WRAPPER(x) std::dynamic_pointer_cast(x) + + + +static ConstraintWrapperPtr + createConstraintCoincidence(std::shared_ptr thePoint1, + std::shared_ptr thePoint2); +static ConstraintWrapperPtr + createConstraintPointOnEntity(const SketchSolver_ConstraintType& theType, + std::shared_ptr thePoint, + std::shared_ptr theEntity); +static ConstraintWrapperPtr + createConstraintDistancePointPoint(std::shared_ptr theValue, + std::shared_ptr thePoint1, + std::shared_ptr thePoint2); +static ConstraintWrapperPtr + createConstraintDistancePointLine(std::shared_ptr theValue, + std::shared_ptr thePoint, + std::shared_ptr theEntity); +static ConstraintWrapperPtr + createConstraintRadius(std::shared_ptr theValue, + std::shared_ptr theEntity); +static ConstraintWrapperPtr + createConstraintAngle(ConstraintPtr theConstraint, + std::shared_ptr theValue, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2); +static ConstraintWrapperPtr + createConstraintHorizVert(const SketchSolver_ConstraintType& theType, + std::shared_ptr theEntity); +static ConstraintWrapperPtr + createConstraintParallel(std::shared_ptr theEntity1, + std::shared_ptr theEntity2); +static ConstraintWrapperPtr + createConstraintPerpendicular(std::shared_ptr theEntity1, + std::shared_ptr theEntity2); +static ConstraintWrapperPtr + createConstraintEqual(const SketchSolver_ConstraintType& theType, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2, + std::shared_ptr theIntermed); +static ConstraintWrapperPtr + createConstraintTangent(const SketchSolver_ConstraintType& theType, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2); +static ConstraintWrapperPtr + createConstraintCollinear(ConstraintPtr theConstraint, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2); +static ConstraintWrapperPtr + createConstraintMiddlePoint(std::shared_ptr thePoint, + std::shared_ptr 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 aPoint1 = GCS_POINT_WRAPPER(thePoint1); + std::shared_ptr 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 PlaneGCSSolver_Tools::point(EntityWrapperPtr theEntity) +{ + if (theEntity->type() != ENTITY_POINT) + return std::shared_ptr(); + + std::shared_ptr aPointWrapper = + std::dynamic_pointer_cast(theEntity); + const GCSPointPtr& aPoint = aPointWrapper->point(); + return std::shared_ptr(new GeomAPI_Pnt2d(*aPoint->x, *aPoint->y)); +} + +std::shared_ptr PlaneGCSSolver_Tools::line(EntityWrapperPtr theEntity) +{ + if (theEntity->type() != ENTITY_LINE) + return std::shared_ptr(); + + std::shared_ptr anEntity = + std::dynamic_pointer_cast(theEntity); + std::shared_ptr aLine = std::dynamic_pointer_cast(anEntity->entity()); + return std::shared_ptr( + new GeomAPI_Lin2d(*(aLine->p1.x), *(aLine->p1.y), *(aLine->p2.x), *(aLine->p2.y))); +} + +std::shared_ptr PlaneGCSSolver_Tools::line(FeaturePtr theFeature) +{ + if (theFeature->getKind() != SketchPlugin_Line::ID()) + return std::shared_ptr(); + + AttributePoint2DPtr aStart = std::dynamic_pointer_cast( + theFeature->attribute(SketchPlugin_Line::START_ID())); + AttributePoint2DPtr aEnd = std::dynamic_pointer_cast( + theFeature->attribute(SketchPlugin_Line::END_ID())); + + return std::shared_ptr(new GeomAPI_Lin2d(aStart->pnt(), aEnd->pnt())); +} + + + + + +// ================ Auxiliary functions ========================== +ConstraintWrapperPtr createConstraintCoincidence( + std::shared_ptr thePoint1, + std::shared_ptr thePoint2) +{ + GCSPointPtr aPoint1 = thePoint1->point(); + GCSPointPtr aPoint2 = thePoint2->point(); + + // Create equality constraint for corresponding attributes of the points + std::list 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 thePoint, + std::shared_ptr theEntity) +{ + GCSConstraintPtr aNewConstr; + + switch (theEntity->type()) { + case ENTITY_LINE: { + std::shared_ptr aLine = std::dynamic_pointer_cast(theEntity->entity()); + aNewConstr = GCSConstraintPtr(new GCS::ConstraintPointOnLine(*(thePoint->point()), *aLine)); + break; + } + case ENTITY_ARC: + case ENTITY_CIRCLE: { + std::shared_ptr aCirc = + std::dynamic_pointer_cast(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 thePoint, + std::shared_ptr theEntity) +{ + GCSPointPtr aPoint = thePoint->point(); + std::shared_ptr aLine = std::dynamic_pointer_cast(theEntity->entity()); + if (!aLine) + return ConstraintWrapperPtr(); + + std::list 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 theValue, + std::shared_ptr thePoint1, + std::shared_ptr thePoint2) +{ + GCSConstraintPtr aNewConstr(new GCS::ConstraintP2PDistance( + *(thePoint1->point()), *(thePoint2->point()), theValue->scalar())); + std::shared_ptr aResult( + new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_PT_DISTANCE)); + aResult->setValueParameter(theValue); + return aResult; +} + +ConstraintWrapperPtr createConstraintDistancePointLine( + std::shared_ptr theValue, + std::shared_ptr thePoint, + std::shared_ptr theEntity) +{ + std::shared_ptr aLine = std::dynamic_pointer_cast(theEntity->entity()); + GCSConstraintPtr aNewConstr(new GCS::ConstraintP2LDistance( + *(thePoint->point()), *(aLine), theValue->scalar())); + std::shared_ptr aResult( + new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PT_LINE_DISTANCE)); + aResult->setValueParameter(theValue); + return aResult; +} + +ConstraintWrapperPtr createConstraintRadius( + std::shared_ptr theValue, + std::shared_ptr theEntity) +{ + std::shared_ptr aCircle = + std::dynamic_pointer_cast(theEntity->entity()); + GCSConstraintPtr aNewConstr(new GCS::ConstraintEqual(aCircle->rad, theValue->scalar())); + std::shared_ptr aResult( + new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_RADIUS)); + aResult->setValueParameter(theValue); + return aResult; +} + +ConstraintWrapperPtr createConstraintAngle( + ConstraintPtr theConstraint, + std::shared_ptr theValue, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2) +{ + std::shared_ptr aLine1 = std::dynamic_pointer_cast(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 aLine2 = std::dynamic_pointer_cast(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 aResult( + new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_ANGLE)); + aResult->setValueParameter(theValue); + return aResult; +} + +ConstraintWrapperPtr createConstraintHorizVert( + const SketchSolver_ConstraintType& theType, + std::shared_ptr theEntity) +{ + std::shared_ptr aLine = std::dynamic_pointer_cast(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 theEntity1, + std::shared_ptr theEntity2) +{ + std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); + std::shared_ptr aLine2 = std::dynamic_pointer_cast(theEntity2->entity()); + + // create two point-on-line constraints + std::list 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 theEntity1, + std::shared_ptr theEntity2) +{ + std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); + std::shared_ptr aLine2 = std::dynamic_pointer_cast(theEntity2->entity()); + GCSConstraintPtr aNewConstr(new GCS::ConstraintParallel(*(aLine1), *(aLine2))); + + return ConstraintWrapperPtr( + new PlaneGCSSolver_ConstraintWrapper(aNewConstr, CONSTRAINT_PARALLEL)); +} + +ConstraintWrapperPtr createConstraintPerpendicular( + std::shared_ptr theEntity1, + std::shared_ptr theEntity2) +{ + std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); + std::shared_ptr aLine2 = std::dynamic_pointer_cast(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 theEntity1, + std::shared_ptr theEntity2, + std::shared_ptr theIntermed) +{ + if (theType == CONSTRAINT_EQUAL_LINE_ARC) + return ConstraintWrapperPtr(); // line-arc equivalence is not supported yet + + std::list aConstrList; + if (theType == CONSTRAINT_EQUAL_LINES) { + std::shared_ptr aLine1 = std::dynamic_pointer_cast(theEntity1->entity()); + std::shared_ptr aLine2 = std::dynamic_pointer_cast(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 aCirc1 = + std::dynamic_pointer_cast(theEntity1->entity()); + std::shared_ptr aCirc2 = + std::dynamic_pointer_cast(theEntity2->entity()); + + aConstrList.push_back(GCSConstraintPtr(new GCS::ConstraintEqual(aCirc1->rad, aCirc2->rad))); + } + + std::shared_ptr aResult( + new PlaneGCSSolver_ConstraintWrapper(aConstrList, theType)); + if (theIntermed) + aResult->setValueParameter(theIntermed); + return aResult; +} + +ConstraintWrapperPtr createConstraintTangent( + const SketchSolver_ConstraintType& theType, + std::shared_ptr theEntity1, + std::shared_ptr theEntity2) +{ + GCSConstraintPtr aNewConstr; + if (theType == CONSTRAINT_TANGENT_ARC_LINE || theType == CONSTRAINT_TANGENT_CIRCLE_LINE) { + std::shared_ptr aCirc = + std::dynamic_pointer_cast(theEntity1->entity()); + std::shared_ptr aLine = + std::dynamic_pointer_cast(theEntity2->entity()); + + aNewConstr = + GCSConstraintPtr(new GCS::ConstraintP2LDistance(aCirc->center, *aLine, aCirc->rad)); + } else { + std::shared_ptr aCirc1 = + std::dynamic_pointer_cast(theEntity1->entity()); + std::shared_ptr aCirc2 = + std::dynamic_pointer_cast(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 aCirc1 = std::dynamic_pointer_cast( + GCS_ENTITY_WRAPPER(theArc1)->entity()); + std::shared_ptr aCirc2 = std::dynamic_pointer_cast( + 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)); +} diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h new file mode 100644 index 000000000..56dfbbdbb --- /dev/null +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h @@ -0,0 +1,64 @@ +// 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 +#include + +#include +#include + +/** \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 point(EntityWrapperPtr theEntity); + /// \brief Convert entity to line + /// \return empty pointer if the entity is not a line + std::shared_ptr line(EntityWrapperPtr theEntity); + + /// \brief Convert entity to line + /// \return empty pointer if the entity is not a line + std::shared_ptr 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 diff --git a/src/SketchSolver/SketchSolver_Builder.cpp b/src/SketchSolver/SketchSolver_Builder.cpp deleted file mode 100644 index d5bf71dc9..000000000 --- a/src/SketchSolver/SketchSolver_Builder.cpp +++ /dev/null @@ -1,112 +0,0 @@ -// 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef _DEBUG -#include -#include -#include -#include -#endif - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -SolverConstraintPtr SketchSolver_Builder::createConstraint(ConstraintPtr theConstraint) const -{ - SolverConstraintPtr aResult; - DataPtr aData = theConstraint->data(); - -#ifdef _DEBUG - // Verify attributes of constraint and generate errors - std::list anAttrList = aData->attributes(std::string()); - std::list::iterator anIter = anAttrList.begin(); - for (; anIter != anAttrList.end(); anIter++) { - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(*anIter); - if (aRefAttr) { - if (aRefAttr->isObject() && aRefAttr->object()) { - ResultConstructionPtr aRC = - std::dynamic_pointer_cast(aRefAttr->object()); - if (!aRC) - Events_InfoMessage("SketchSolver_Builder", - SketchSolver_Error::NEED_OBJECT_NOT_FEATURE(), this).send(); - } - continue; - } - AttributeRefListPtr aRefList = std::dynamic_pointer_cast(*anIter); - if (aRefList) { - std::list aList = aRefList->list(); - std::list::iterator aListIter = aList.begin(); - for (; aListIter != aList.end(); aListIter++) { - ResultConstructionPtr aRC = - std::dynamic_pointer_cast(*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)); -} diff --git a/src/SketchSolver/SketchSolver_Builder.h b/src/SketchSolver/SketchSolver_Builder.h deleted file mode 100644 index 10677a712..000000000 --- a/src/SketchSolver/SketchSolver_Builder.h +++ /dev/null @@ -1,93 +0,0 @@ -// 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 -#include - -#include -#include - -/** \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& theTrsfEnt) const = 0; - - - /// \brief Convert entity to point - /// \return empty pointer if the entity is not a point - virtual std::shared_ptr point(EntityWrapperPtr theEntity) const = 0; - /// \brief Convert entity to line - /// \return empty pointer if the entity is not a line - virtual std::shared_ptr line(EntityWrapperPtr theEntity) const = 0; - - /// \brief Convert entity to line - /// \return empty pointer if the entity is not a line - virtual std::shared_ptr 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 BuilderPtr; - -#endif diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 385190514..1a4a59484 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -1,11 +1,10 @@ // Copyright (C) 2014-20xx CEA/DEN, EDF R&D #include -#include #include -#include #include +#include #include #include @@ -114,8 +113,7 @@ void SketchSolver_Constraint::process() 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); @@ -183,7 +181,6 @@ void SketchSolver_Constraint::getAttributes( myAttributes.clear(); DataPtr aData = myBaseConstraint->data(); - BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); myType = TYPE(myBaseConstraint); diff --git a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp index c2f35d24e..a2c3357b6 100644 --- a/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp @@ -2,7 +2,7 @@ #include #include -#include +#include #include void SketchSolver_ConstraintCoincidence::process() @@ -23,8 +23,7 @@ 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]); diff --git a/src/SketchSolver/SketchSolver_ConstraintMirror.cpp b/src/SketchSolver/SketchSolver_ConstraintMirror.cpp index 6381b2bd3..7dd34c528 100644 --- a/src/SketchSolver/SketchSolver_ConstraintMirror.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintMirror.cpp @@ -2,8 +2,8 @@ #include #include -#include +#include #include #include @@ -99,12 +99,10 @@ void SketchSolver_ConstraintMirror::update() void SketchSolver_ConstraintMirror::adjustConstraint() { - BuilderPtr aBuilder = SketchSolver_Manager::instance()->builder(); - AttributeRefAttrPtr aMirrLineRefAttr = myBaseConstraint->refattr(SketchPlugin_Constraint::ENTITY_A()); std::shared_ptr aMirrorLine = - aBuilder->line(ModelAPI_Feature::feature(aMirrLineRefAttr->object())); + PlaneGCSSolver_Tools::line(ModelAPI_Feature::feature(aMirrLineRefAttr->object())); AttributeRefListPtr aBaseRefList = myBaseConstraint->reflist(SketchPlugin_Constraint::ENTITY_B()); diff --git a/src/SketchSolver/SketchSolver_ConstraintTangent.cpp b/src/SketchSolver/SketchSolver_ConstraintTangent.cpp index 0df752a29..ab4a27ea7 100644 --- a/src/SketchSolver/SketchSolver_ConstraintTangent.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintTangent.cpp @@ -2,7 +2,8 @@ #include #include -#include + +#include #include #include @@ -34,15 +35,6 @@ static bool hasSingleCoincidence(FeaturePtr theFeature1, FeaturePtr theFeature2) 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& theAttributes) @@ -84,7 +76,8 @@ void SketchSolver_ConstraintTangent::getAttributes( } 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(); @@ -116,7 +109,7 @@ void SketchSolver_ConstraintTangent::adjustConstraint() 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(); diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index c5418065b..ce576cdbf 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -9,6 +9,8 @@ #include #include +#include +#include #include #include @@ -40,12 +42,11 @@ static void sendMessage(const char* theMessageName, const std::set& t 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() @@ -68,9 +69,8 @@ bool SketchSolver_Group::changeConstraint( { 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); @@ -93,10 +93,8 @@ bool SketchSolver_Group::updateFeature(FeaturePtr theFeature) 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); @@ -118,49 +116,28 @@ bool SketchSolver_Group::resolveConstraints() 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); @@ -168,11 +145,12 @@ bool SketchSolver_Group::resolveConstraints() //// 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 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); } @@ -186,8 +164,8 @@ bool SketchSolver_Group::resolveConstraints() 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 aConflicting = myStorage->getConflictingConstraints(mySketchSolver); diff --git a/src/SketchSolver/SketchSolver_Group.h b/src/SketchSolver/SketchSolver_Group.h index c795c5e9f..7e8c9424f 100644 --- a/src/SketchSolver/SketchSolver_Group.h +++ b/src/SketchSolver/SketchSolver_Group.h @@ -9,7 +9,8 @@ #include #include -#include + +#include #include @@ -106,7 +107,7 @@ private: 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 myConflictingConstraints; ///< List of conflicting constraints bool myIsEventsBlocked; ///< shows the events are blocked for this group diff --git a/src/SketchSolver/SketchSolver_IConstraintWrapper.h b/src/SketchSolver/SketchSolver_IConstraintWrapper.h index 04b7e917f..3fa42f14d 100644 --- a/src/SketchSolver/SketchSolver_IConstraintWrapper.h +++ b/src/SketchSolver/SketchSolver_IConstraintWrapper.h @@ -63,29 +63,13 @@ public: /// \brief Return type of current entity virtual SketchSolver_ConstraintType type() const = 0; - /// \brief Assign list of constrained objects - void setEntities(const std::list& theEntities) - { myConstrained = theEntities; } - /// \brief Return list of constrained objects - const std::list& 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 myConstrained; - bool myIsFullValue; + ConstraintID myID; }; typedef std::shared_ptr ConstraintWrapperPtr; diff --git a/src/SketchSolver/SketchSolver_ISolver.h b/src/SketchSolver/SketchSolver_ISolver.h deleted file mode 100644 index da9c5041e..000000000 --- a/src/SketchSolver/SketchSolver_ISolver.h +++ /dev/null @@ -1,58 +0,0 @@ -// 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 - -#include - -/// 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 SolverPtr; - -#endif diff --git a/src/SketchSolver/SketchSolver_Manager.cpp b/src/SketchSolver/SketchSolver_Manager.cpp index 0d20365a4..5571e2927 100644 --- a/src/SketchSolver/SketchSolver_Manager.cpp +++ b/src/SketchSolver/SketchSolver_Manager.cpp @@ -62,16 +62,6 @@ SketchSolver_Manager::~SketchSolver_Manager() myGroups.clear(); } -void SketchSolver_Manager::setBuilder(BuilderPtr theBuilder) -{ - myBuilder = theBuilder; -} - -BuilderPtr SketchSolver_Manager::builder() -{ - return myBuilder; -} - bool SketchSolver_Manager::groupMessages() { return true; diff --git a/src/SketchSolver/SketchSolver_Manager.h b/src/SketchSolver/SketchSolver_Manager.h index 89a9b7acc..7d227dee4 100644 --- a/src/SketchSolver/SketchSolver_Manager.h +++ b/src/SketchSolver/SketchSolver_Manager.h @@ -9,7 +9,6 @@ #include "SketchSolver.h" #include -#include #include #include @@ -43,12 +42,6 @@ public: */ 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(); @@ -87,7 +80,6 @@ private: private: std::list 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; diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 332bd39af..50d30987c 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -10,8 +10,8 @@ #include #include #include -#include +#include #include #include