+void PlaneGCSSolver_Storage::makeExternal(const EntityWrapperPtr& theEntity)
+{
+ if (theEntity->isExternal())
+ return;
+
+ removeArcConstraints(theEntity);
+
+ GCS::SET_pD aParameters = PlaneGCSSolver_Tools::parameters(theEntity);
+ mySketchSolver->removeParameters(aParameters);
+ theEntity->setExternal(true);
+ myNeedToResolve = true;
+}
+
+void PlaneGCSSolver_Storage::makeNonExternal(const EntityWrapperPtr& theEntity)
+{
+ if (!theEntity->isExternal())
+ return;
+
+ GCS::SET_pD aParameters = PlaneGCSSolver_Tools::parameters(theEntity);
+ mySketchSolver->addParameters(aParameters);
+ theEntity->setExternal(false);
+
+ createArcConstraints(theEntity);
+
+ myNeedToResolve = true;
+}
+
+
+void PlaneGCSSolver_Storage::createArcConstraints(const EntityWrapperPtr& theArc)
+{
+ if (theArc->type() != ENTITY_ARC || theArc->isExternal())
+ return;
+
+ EdgeWrapperPtr anEdge = std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(theArc);
+ std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(anEdge->entity());
+
+ // Additional constaints to fix arc's extra DoF (if the arc is not external):
+ std::list<GCSConstraintPtr> anArcConstraints;
+ // 1. distances from center till start and end points are equal to radius
+ anArcConstraints.push_back(GCSConstraintPtr(new GCS::ConstraintP2PDistance(
+ anArc->center, anArc->start, anArc->rad)));
+ anArcConstraints.push_back(GCSConstraintPtr(new GCS::ConstraintP2PDistance(
+ anArc->center, anArc->end, anArc->rad)));
+ // 2. angles of start and end points should be equal to the arc angles
+ anArcConstraints.push_back(GCSConstraintPtr(new GCS::ConstraintP2PAngle(
+ anArc->center, anArc->start, anArc->startAngle)));
+ anArcConstraints.push_back(GCSConstraintPtr(new GCS::ConstraintP2PAngle(
+ anArc->center, anArc->end, anArc->endAngle)));
+
+ ConstraintWrapperPtr aWrapper(
+ new PlaneGCSSolver_ConstraintWrapper(anArcConstraints, CONSTRAINT_UNKNOWN));
+ aWrapper->setId(++myConstraintLastID);
+ constraintsToSolver(aWrapper, mySketchSolver);
+
+ myArcConstraintMap[theArc] = aWrapper;
+}
+
+void PlaneGCSSolver_Storage::removeArcConstraints(const EntityWrapperPtr& theArc)
+{
+ std::map<EntityWrapperPtr, ConstraintWrapperPtr>::iterator
+ aFound = myArcConstraintMap.find(theArc);
+ if (aFound != myArcConstraintMap.end()) {
+ mySketchSolver->removeConstraint(aFound->second->id());
+ myArcConstraintMap.erase(aFound);
+ }
+}