+std::shared_ptr<GeomAPI_Circ2d> PlaneGCSSolver_Tools::circle(EntityWrapperPtr theEntity)
+{
+ if (theEntity->type() != ENTITY_CIRCLE && theEntity->type() != ENTITY_ARC)
+ return std::shared_ptr<GeomAPI_Circ2d>();
+
+ std::shared_ptr<PlaneGCSSolver_EdgeWrapper> anEntity =
+ std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(theEntity);
+ std::shared_ptr<GCS::Circle> aCirc = std::dynamic_pointer_cast<GCS::Circle>(anEntity->entity());
+ return std::shared_ptr<GeomAPI_Circ2d>(
+ new GeomAPI_Circ2d(*(aCirc->center.x), *(aCirc->center.y), *(aCirc->rad)));
+}
+
+std::shared_ptr<GeomAPI_Ellipse2d> PlaneGCSSolver_Tools::ellipse(EntityWrapperPtr theEntity)
+{
+ if (theEntity->type() != ENTITY_ELLIPSE && theEntity->type() != ENTITY_ELLIPTIC_ARC)
+ return std::shared_ptr<GeomAPI_Ellipse2d>();
+
+ std::shared_ptr<PlaneGCSSolver_EdgeWrapper> anEntity =
+ std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(theEntity);
+ std::shared_ptr<GCS::Ellipse> anEllipse =
+ std::dynamic_pointer_cast<GCS::Ellipse>(anEntity->entity());
+
+ std::shared_ptr<GeomAPI_Pnt2d> aCenter(
+ new GeomAPI_Pnt2d(*(anEllipse->center.x), *(anEllipse->center.y)));
+ std::shared_ptr<GeomAPI_Dir2d> anAxis(new GeomAPI_Dir2d(
+ *(anEllipse->focus1.x) - *(anEllipse->center.x),
+ *(anEllipse->focus1.y) - *(anEllipse->center.y)));
+
+ return std::shared_ptr<GeomAPI_Ellipse2d>(
+ new GeomAPI_Ellipse2d(aCenter, anAxis, anEllipse->getRadMaj(), *anEllipse->radmin));
+}
+
+std::shared_ptr<GeomAPI_BSpline2d> PlaneGCSSolver_Tools::bspline(EntityWrapperPtr theEntity)
+{
+ if (theEntity->type() != ENTITY_BSPLINE)
+ return std::shared_ptr<GeomAPI_BSpline2d>();
+
+ std::shared_ptr<PlaneGCSSolver_EdgeWrapper> anEntity =
+ std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(theEntity);
+ std::shared_ptr<GCS::BSpline> aSpline =
+ std::dynamic_pointer_cast<GCS::BSpline>(anEntity->entity());
+
+ std::list<GeomPnt2dPtr> aPoles;
+ for (GCS::VEC_P::iterator anIt = aSpline->poles.begin(); anIt != aSpline->poles.end(); ++anIt)
+ aPoles.push_back(GeomPnt2dPtr(new GeomAPI_Pnt2d(*anIt->x, *anIt->y)));
+
+ std::list<double> aWeights;
+ for (GCS::VEC_pD::iterator anIt = aSpline->weights.begin();
+ anIt != aSpline->weights.end(); ++anIt)
+ aWeights.push_back(**anIt);
+
+ std::list<double> aKnots;
+ for (GCS::VEC_pD::iterator anIt = aSpline->knots.begin(); anIt != aSpline->knots.end(); ++anIt)
+ aKnots.push_back(**anIt);
+
+ std::list<int> aMultiplicities;
+ aMultiplicities.assign(aSpline->mult.begin(), aSpline->mult.end());
+
+ return std::shared_ptr<GeomAPI_BSpline2d>(
+ new GeomAPI_BSpline2d(aSpline->degree, aPoles, aWeights,
+ aKnots, aMultiplicities, aSpline->periodic));
+}
+
+void PlaneGCSSolver_Tools::recalculateArcParameters(EntityWrapperPtr theArc)
+{
+ std::shared_ptr<PlaneGCSSolver_EdgeWrapper> anEdge =
+ std::dynamic_pointer_cast<PlaneGCSSolver_EdgeWrapper>(theArc);
+ if (!anEdge)
+ return;
+
+ if (anEdge->type() == ENTITY_ARC) {
+ std::shared_ptr<GCS::Arc> anArc = std::dynamic_pointer_cast<GCS::Arc>(anEdge->entity());
+
+ GCS::Point aCenter = anArc->center;
+ GCS::Point aStartPnt = anArc->start;
+ GCS::Point aEndPnt = anArc->end;
+
+ *anArc->rad = distance(aCenter, aStartPnt);
+
+ static GeomDir2dPtr OX(new GeomAPI_Dir2d(1.0, 0.0));
+
+ GeomDir2dPtr aDir(new GeomAPI_Dir2d(*aStartPnt.x - *aCenter.x, *aStartPnt.y - *aCenter.y));
+ *anArc->startAngle = OX->angle(aDir);
+
+ aDir.reset(new GeomAPI_Dir2d(*aEndPnt.x - *aCenter.x, *aEndPnt.y - *aCenter.y));
+ *anArc->endAngle = OX->angle(aDir);
+ }
+ else if (anEdge->type() == ENTITY_ELLIPTIC_ARC) {
+ std::shared_ptr<GCS::ArcOfEllipse> aEllArc =
+ std::dynamic_pointer_cast<GCS::ArcOfEllipse>(anEdge->entity());
+
+ GeomPnt2dPtr aCenter(new GeomAPI_Pnt2d(*aEllArc->center.x, *aEllArc->center.y));
+ GeomPnt2dPtr aStartPnt(new GeomAPI_Pnt2d(*aEllArc->start.x, *aEllArc->start.y));
+ GeomPnt2dPtr aEndPnt(new GeomAPI_Pnt2d(*aEllArc->end.x, *aEllArc->end.y));
+
+ GeomDir2dPtr anAxis(new GeomAPI_Dir2d(*aEllArc->focus1.x - aCenter->x(),
+ *aEllArc->focus1.y - aCenter->y()));
+ GeomAPI_Ellipse2d anEllipse(aCenter, anAxis, aEllArc->getRadMaj(), *aEllArc->radmin);
+ anEllipse.parameter(aStartPnt, 1.e-4, *aEllArc->startAngle);
+ anEllipse.parameter(aEndPnt, 1.e-4, *aEllArc->endAngle);
+ }
+}
+
+