+bool SketchSolver_Constraint::isInitialized(AttributePtr theAttribute)
+{
+ if (theAttribute->isInitialized())
+ return true;
+ myErrorMsg = SketchSolver_Error::NOT_INITIALIZED();
+ return false;
+}
+
+
+void SketchSolver_Constraint::calculateMiddlePoint(
+ const Slvs_Entity& theEntity, double theCoeff, double& theX, double& theY) const
+{
+ if (theEntity.type == SLVS_E_LINE_SEGMENT) {
+ double aStartEndXY[2][2];
+ Slvs_Entity aPoint;
+ for (int i = 0; i < 2; i++) {
+ aPoint = myStorage->getEntity(theEntity.point[i]);
+ for (int j = 0; j < 2; j++)
+ aStartEndXY[i][j] = myStorage->getParameter(aPoint.param[j]).val;
+ }
+ theX = (1.0 - theCoeff) * aStartEndXY[0][0] + theCoeff * aStartEndXY[1][0];
+ theY = (1.0 - theCoeff) * aStartEndXY[0][1] + theCoeff * aStartEndXY[1][1];
+ } else if (theEntity.type == SLVS_E_ARC_OF_CIRCLE) {
+ double anArcPoint[3][2];
+ Slvs_Entity aPoint;
+ for (int i = 0; i < 3; i++) {
+ aPoint = myStorage->getEntity(theEntity.point[i]);
+ for (int j = 0; j < 2; j++)
+ anArcPoint[i][j] = myStorage->getParameter(aPoint.param[j]).val;
+ }
+ // 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];
+ return;
+ } else if (1 - theCoeff < tolerance) {
+ theX = anArcPoint[0][0] + anArcPoint[2][0];
+ theY = anArcPoint[0][1] + anArcPoint[2][1];
+ return;
+ }
+
+ 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;
+ }
+}
+
+void SketchSolver_Constraint::makeTemporary() const
+{
+ std::vector<Slvs_hConstraint>::const_iterator anIt = mySlvsConstraints.begin();
+ for (; anIt != mySlvsConstraints.end(); anIt++)
+ myStorage->addTemporaryConstraint(*anIt);
+}
+