]> SALOME platform Git repositories - modules/shaper.git/commitdiff
Salome HOME
Simplify sketcher model. Remove obsolete files and classes.
authorazv <azv@opencascade.com>
Wed, 1 Mar 2017 06:54:40 +0000 (09:54 +0300)
committerazv <azv@opencascade.com>
Wed, 1 Mar 2017 06:54:40 +0000 (09:54 +0300)
23 files changed:
src/SketchSolver/CMakeLists.txt
src/SketchSolver/PlaneGCSSolver/CMakeLists.txt
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp [deleted file]
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h [deleted file]
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.cpp [new file with mode: 0644]
src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h [new file with mode: 0644]
src/SketchSolver/SketchSolver_Builder.cpp [deleted file]
src/SketchSolver/SketchSolver_Builder.h [deleted file]
src/SketchSolver/SketchSolver_Constraint.cpp
src/SketchSolver/SketchSolver_ConstraintCoincidence.cpp
src/SketchSolver/SketchSolver_ConstraintMirror.cpp
src/SketchSolver/SketchSolver_ConstraintTangent.cpp
src/SketchSolver/SketchSolver_Group.cpp
src/SketchSolver/SketchSolver_Group.h
src/SketchSolver/SketchSolver_IConstraintWrapper.h
src/SketchSolver/SketchSolver_ISolver.h [deleted file]
src/SketchSolver/SketchSolver_Manager.cpp
src/SketchSolver/SketchSolver_Manager.h
src/SketchSolver/SketchSolver_Storage.h

index 60fa8f05ab9731d7bf59b83e3db7cdc99d9a1556..d6b370d7935baebed08ec5c1c91ac5286b913329 100644 (file)
@@ -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
 )
index 4866a5b363ef3f08deec43023232e9d3c10cea55..91bc90b795f7f0eb9c985a61605a203f588f31a1 100644 (file)
@@ -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 (file)
index fb81a64..0000000
+++ /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 <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));
-}
diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h
deleted file mode 100644 (file)
index caf81eb..0000000
+++ /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 <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
index 1193ad3573218d9577ca04df2035b156ce31c82b..3e77208aa756a42efb354a0389efb733083a2ea7 100644 (file)
@@ -4,7 +4,7 @@
 // Created: 14 Dec 2014
 // Author:  Artem ZHIDKOV
 
-#include "PlaneGCSSolver_Solver.h"
+#include <PlaneGCSSolver_Solver.h>
 #include <Events_LongOp.h>
 
 
@@ -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)
index 9c25caf722e06ee3300856f8edef641f6cec9bdb..0465924cb01987fe0b15e508156b25618302557b 100644 (file)
@@ -7,16 +7,24 @@
 #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();
 
@@ -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<PlaneGCSSolver_Solver> SolverPtr;
+
 #endif
index 67ada87702e88c6bc449b636a7b1a6777bb2af48..62451f130256de7505785c56be1e466df49943b3 100644 (file)
@@ -5,7 +5,6 @@
 // Author:  Artem ZHIDKOV
 
 #include <PlaneGCSSolver_Storage.h>
-#include <PlaneGCSSolver_Builder.h>
 #include <PlaneGCSSolver_Solver.h>
 #include <PlaneGCSSolver_ConstraintWrapper.h>
 #include <PlaneGCSSolver_EntityWrapper.h>
@@ -19,6 +18,7 @@
 #include <GeomAPI_Pnt2d.h>
 #include <GeomAPI_XY.h>
 #include <GeomDataAPI_Point2D.h>
+#include <ModelAPI_AttributeRefAttr.h>
 #include <SketchPlugin_Projection.h>
 
 #include <cmath>
@@ -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<PlaneGCSSolver_Solver> aSolver =
-        std::dynamic_pointer_cast<PlaneGCSSolver_Solver>(mySketchSolver);
-    aSolver->removeConstraint(anID);
+    mySketchSolver->removeConstraint(anID);
     // Remove constraint
     myConstraintMap.erase(aFound);
 
@@ -305,8 +303,7 @@ void PlaneGCSSolver_Storage::removeInvalidEntities()
       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);
       }
     }
@@ -338,66 +335,12 @@ void PlaneGCSSolver_Storage::removeInvalidEntities()
 
 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
index ca8fa22212ae247acadaed0fbbeae88068075669..752651d3319895e25c989d5995011b4441c205a9 100644 (file)
@@ -11,7 +11,6 @@
 
 #include <SketchSolver.h>
 #include <SketchSolver_Storage.h>
-#include <SketchSolver_ISolver.h>
 
 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<std::set<double*> >& 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 (file)
index 0000000..5f10b68
--- /dev/null
@@ -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 <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));
+}
diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Tools.h
new file mode 100644 (file)
index 0000000..56dfbbd
--- /dev/null
@@ -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 <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
diff --git a/src/SketchSolver/SketchSolver_Builder.cpp b/src/SketchSolver/SketchSolver_Builder.cpp
deleted file mode 100644 (file)
index d5bf71d..0000000
+++ /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 <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));
-}
diff --git a/src/SketchSolver/SketchSolver_Builder.h b/src/SketchSolver/SketchSolver_Builder.h
deleted file mode 100644 (file)
index 10677a7..0000000
+++ /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 <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
index 38519051451fb490757040353fcf4f9818541b07..1a4a594849be4b01941bc3d333eee3ed13fb5bb3 100644 (file)
@@ -1,11 +1,10 @@
 // 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>
@@ -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);
 
index c2f35d24e110b11bbc780c03abaa9b756642e7c6..a2c3357b6ca82576b782079ea852563290bcaef7 100644 (file)
@@ -2,7 +2,7 @@
 
 #include <SketchSolver_ConstraintCoincidence.h>
 #include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
+#include <PlaneGCSSolver_Tools.h>
 #include <PlaneGCSSolver_UpdateCoincidence.h>
 
 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]);
 
index 6381b2bd3dc8f85750cab74f798213a6d37bfb40..7dd34c528d7f71aa8372846621b8bfe34e8b55a2 100644 (file)
@@ -2,8 +2,8 @@
 
 #include <SketchSolver_ConstraintMirror.h>
 #include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
 
+#include <PlaneGCSSolver_Tools.h>
 #include <PlaneGCSSolver_UpdateFeature.h>
 
 #include <GeomAPI_XY.h>
@@ -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<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());
index 0df752a29c4d614fc1e437f69630ef1f5c99058d..ab4a27ea793b8e15da0c0dbd54cbaefa7086f07c 100644 (file)
@@ -2,7 +2,8 @@
 
 #include <SketchSolver_ConstraintTangent.h>
 #include <SketchSolver_Error.h>
-#include <SketchSolver_Manager.h>
+
+#include <PlaneGCSSolver_Tools.h>
 
 #include <GeomAPI_Pnt2d.h>
 #include <SketchPlugin_Circle.h>
@@ -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<EntityWrapperPtr>& 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();
index c5418065bc13ad9cb93e92aff9c14719cd3921ac..ce576cdbfc0ac501616432858e1957c974efbc98 100644 (file)
@@ -9,6 +9,8 @@
 #include <SketchSolver_Manager.h>
 
 #include <PlaneGCSSolver_Solver.h>
+#include <PlaneGCSSolver_Storage.h>
+#include <PlaneGCSSolver_Tools.h>
 
 #include <Events_InfoMessage.h>
 #include <ModelAPI_AttributeString.h>
@@ -40,12 +42,11 @@ static void sendMessage(const char* theMessageName, const std::set<ObjectPtr>& 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<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);
       }
@@ -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<ObjectPtr> aConflicting = myStorage->getConflictingConstraints(mySketchSolver);
 
index c795c5e9f80168c6a27a144f8f2c095fb26c8079..7e8c9424f1f55e91119f53c2c8fb17d491aa95d6 100644 (file)
@@ -9,7 +9,8 @@
 
 #include <SketchSolver_Constraint.h>
 #include <SketchSolver_Storage.h>
-#include <SketchSolver_ISolver.h>
+
+#include <PlaneGCSSolver_Solver.h>
 
 #include <SketchPlugin_Constraint.h>
 
@@ -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<ObjectPtr>      myConflictingConstraints; ///< List of conflicting constraints
 
   bool myIsEventsBlocked; ///< shows the events are blocked for this group
index 04b7e917f05fa03c5314311f4c9e869e1803ab9b..3fa42f14d5a1b7055248369b1b4d2660cdd4eabf 100644 (file)
@@ -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<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;
diff --git a/src/SketchSolver/SketchSolver_ISolver.h b/src/SketchSolver/SketchSolver_ISolver.h
deleted file mode 100644 (file)
index da9c504..0000000
+++ /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 <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
index 0d20365a4d8243ed11af416daa8579fb9a11cd87..5571e29276bbe8a1dc4ab5f6fe47935280de1d49 100644 (file)
@@ -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;
index 89a9b7acc77aa4d9edd2960c15ce33df67af22e2..7d227dee456c044ce79e803b12c37b098ff7ffd9 100644 (file)
@@ -9,7 +9,6 @@
 
 #include "SketchSolver.h"
 #include <SketchSolver_Group.h>
-#include <SketchSolver_Builder.h>
 
 #include <Events_Listener.h>
 #include <SketchPlugin_Constraint.h>
@@ -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<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;
index 332bd39af63f5aef76972a56671cb652c0ea2447..50d30987c21812edb0d2750c1fd40e41b94688c8 100644 (file)
@@ -10,8 +10,8 @@
 #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>