-
- //blockEvents(false);
-}
-
-EntityWrapperPtr PlaneGCSSolver_Storage::calculateMiddlePoint(
- EntityWrapperPtr theBase, double theCoeff)
-{
- std::shared_ptr<PlaneGCSSolver_Builder> aBuilder =
- std::dynamic_pointer_cast<PlaneGCSSolver_Builder>(PlaneGCSSolver_Builder::getInstance());
-
- std::shared_ptr<GeomAPI_XY> aMidPoint;
- if (theBase->type() == ENTITY_LINE) {
- std::shared_ptr<GeomAPI_Pnt2d> aPoints[2];
- const std::list<EntityWrapperPtr>& aSubs = theBase->subEntities();
- std::list<EntityWrapperPtr>::const_iterator anIt = aSubs.begin();
- for (int i = 0; i < 2; ++i, ++anIt)
- aPoints[i] = aBuilder->point(*anIt);
- aMidPoint = aPoints[0]->xy()->multiplied(1.0 - theCoeff)->added(
- aPoints[1]->xy()->multiplied(theCoeff));
- }
- else if (theBase->type() == ENTITY_ARC) {
- double theX, theY;
- double anArcPoint[3][2];
- const std::list<EntityWrapperPtr>& aSubs = theBase->subEntities();
- std::list<EntityWrapperPtr>::const_iterator anIt = aSubs.begin();
- for (int i = 0; i < 3; ++i, ++anIt) {
- std::shared_ptr<GeomAPI_Pnt2d> aPoint = aBuilder->point(*anIt);
- anArcPoint[i][0] = aPoint->x();
- anArcPoint[i][1] = aPoint->y();
- }
- // project last point of arc on the arc
- double x = anArcPoint[1][0] - anArcPoint[0][0];
- double y = anArcPoint[1][1] - anArcPoint[0][1];
- double aRad = sqrt(x*x + y*y);
- x = anArcPoint[2][0] - anArcPoint[0][0];
- y = anArcPoint[2][1] - anArcPoint[0][1];
- double aNorm = sqrt(x*x + y*y);
- if (aNorm >= tolerance) {
- anArcPoint[2][0] = x * aRad / aNorm;
- anArcPoint[2][1] = y * aRad / aNorm;
- }
- anArcPoint[1][0] -= anArcPoint[0][0];
- anArcPoint[1][1] -= anArcPoint[0][1];
- if (theCoeff < tolerance) {
- theX = anArcPoint[0][0] + anArcPoint[1][0];
- theY = anArcPoint[0][1] + anArcPoint[1][1];
- } else if (1 - theCoeff < tolerance) {
- theX = anArcPoint[0][0] + anArcPoint[2][0];
- theY = anArcPoint[0][1] + anArcPoint[2][1];
- } else {
- std::shared_ptr<GeomAPI_Dir2d> aStartDir(new GeomAPI_Dir2d(anArcPoint[1][0], anArcPoint[1][1]));
- std::shared_ptr<GeomAPI_Dir2d> aEndDir(new GeomAPI_Dir2d(anArcPoint[2][0], anArcPoint[2][1]));
- double anAngle = aStartDir->angle(aEndDir);
- if (anAngle < 0)
- anAngle += 2.0 * PI;
- anAngle *= theCoeff;
- double aCos = cos(anAngle);
- double aSin = sin(anAngle);
- theX = anArcPoint[0][0] + anArcPoint[1][0] * aCos - anArcPoint[1][1] * aSin;
- theY = anArcPoint[0][1] + anArcPoint[1][0] * aSin + anArcPoint[1][1] * aCos;
- }
- aMidPoint = std::shared_ptr<GeomAPI_XY>(new GeomAPI_XY(theX, theY));
- }
-
- if (!aMidPoint)
- return EntityWrapperPtr();
-
- std::list<ParameterWrapperPtr> aParameters;
- aParameters.push_back(aBuilder->createParameter(myGroupID, aMidPoint->x()));
- aParameters.push_back(aBuilder->createParameter(myGroupID, aMidPoint->y()));
- // Create entity (parameters are not filled)
- GCSPointPtr aPnt(new GCS::Point);
- aPnt->x = std::dynamic_pointer_cast<PlaneGCSSolver_ParameterWrapper>(aParameters.front())->parameter();
- aPnt->y = std::dynamic_pointer_cast<PlaneGCSSolver_ParameterWrapper>(aParameters.back())->parameter();
-
- EntityWrapperPtr aResult(new PlaneGCSSolver_PointWrapper(AttributePtr(), aPnt));
- aResult->setGroup(myGroupID);
- aResult->setParameters(aParameters);
-
- update(aResult);
- return aResult;