X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_ConstraintRigid.cpp;h=ff52e577437e5f8db91ae8a17077de087fa94395;hb=d3883990177d27a12b8a2278cdbb82250ff19b79;hp=d13285362b5ced69a2ee013d56a4f4c512f85d98;hpb=0e8b1e9bddca0d41e27e812e4c4c9fa58a48629f;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_ConstraintRigid.cpp b/src/SketchSolver/SketchSolver_ConstraintRigid.cpp index d13285362..ff52e5774 100644 --- a/src/SketchSolver/SketchSolver_ConstraintRigid.cpp +++ b/src/SketchSolver/SketchSolver_ConstraintRigid.cpp @@ -13,6 +13,8 @@ #include #include +#include + SketchSolver_ConstraintRigid::SketchSolver_ConstraintRigid(FeaturePtr theFeature) : SketchSolver_Constraint(), myBaseFeature(theFeature) @@ -33,28 +35,42 @@ void SketchSolver_ConstraintRigid::process() double aValue; std::vector anEntities; getAttributes(aValue, anEntities); - if (!myErrorMsg.empty() || myFeatureMap.empty()) + if (!myErrorMsg.empty() || (myFeatureMap.empty() && myAttributeMap.empty())) return; + fixFeature(); +} - Slvs_hEntity anEntID = myFeatureMap.begin()->second; +void SketchSolver_ConstraintRigid::fixFeature() +{ + Slvs_hEntity anEntID; + if (!myFeatureMap.empty()) + anEntID = myFeatureMap.begin()->second; + else + anEntID = myAttributeMap.begin()->second; if (myStorage->isEntityFixed(anEntID, true)) { myErrorMsg = SketchSolver_Error::ALREADY_FIXED(); return; } - if (myFeatureMap.begin()->first->getKind() == SketchPlugin_Line::ID()) { + std::string aKind; + if (!myFeatureMap.empty()) + aKind = myFeatureMap.begin()->first->getKind(); + else + aKind = myAttributeMap.begin()->first->attributeType(); + + if (aKind == SketchPlugin_Line::ID()) { Slvs_Entity aLine = myStorage->getEntity(anEntID); fixLine(aLine); } - else if (myFeatureMap.begin()->first->getKind() == SketchPlugin_Arc::ID()) { + else if (aKind == SketchPlugin_Arc::ID()) { Slvs_Entity anArc = myStorage->getEntity(anEntID); fixArc(anArc); } - else if (myFeatureMap.begin()->first->getKind() == SketchPlugin_Circle::ID()) { + else if (aKind == SketchPlugin_Circle::ID()) { Slvs_Entity aCirc = myStorage->getEntity(anEntID); fixCircle(aCirc); } - else if (myFeatureMap.begin()->first->getKind() == SketchPlugin_Point::ID()) { + else if (aKind == SketchPlugin_Point::ID() || aKind == GeomDataAPI_Point2D::typeId()) { fixPoint(anEntID); } } @@ -184,7 +200,41 @@ void SketchSolver_ConstraintRigid::fixPoint(const Slvs_hEntity& thePointID) void SketchSolver_ConstraintRigid::fixLine(const Slvs_Entity& theLine) { Slvs_Constraint anEqual; - if (isUsedInEqual(theLine, anEqual)) { + if (isAxisParallel(theLine)) { + // Fix one point and a line length + Slvs_hConstraint aFixed; + if (!myStorage->isPointFixed(theLine.point[0], aFixed, true) && + !myStorage->isPointFixed(theLine.point[1], aFixed, true)) + fixPoint(theLine.point[0]); + if (!isUsedInEqual(theLine, anEqual)) { + // Check the distance is not set yet + std::list aDistConstr = myStorage->getConstraintsByType(SLVS_C_PT_PT_DISTANCE); + std::list::const_iterator aDIt = aDistConstr.begin(); + for (; aDIt != aDistConstr.end(); aDIt++) + if ((aDIt->ptA == theLine.point[0] && aDIt->ptB == theLine.point[1]) || + (aDIt->ptA == theLine.point[1] && aDIt->ptB == theLine.point[0])) + return; + // Calculate distance between points on the line + double aCoords[4]; + for (int i = 0; i < 2; i++) { + Slvs_Entity aPnt = myStorage->getEntity(theLine.point[i]); + for (int j = 0; j < 2; j++) { + Slvs_Param aParam = myStorage->getParameter(aPnt.param[j]); + aCoords[2*i+j] = aParam.val; + } + } + double aLength = sqrt((aCoords[2] - aCoords[0]) * (aCoords[2] - aCoords[0]) + + (aCoords[3] - aCoords[1]) * (aCoords[3] - aCoords[1])); + // fix line length + Slvs_Constraint aDistance = Slvs_MakeConstraint(SLVS_E_UNKNOWN, myGroup->getId(), + SLVS_C_PT_PT_DISTANCE, myGroup->getWorkplaneId(), aLength, + theLine.point[0], theLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); + aDistance.h = myStorage->addConstraint(aDistance); + mySlvsConstraints.push_back(aDistance.h); + } + return; + } + else if (isUsedInEqual(theLine, anEqual)) { // Check another entity of Equal is already fixed Slvs_hEntity anOtherEntID = anEqual.entityA == theLine.h ? anEqual.entityB : anEqual.entityA; if (myStorage->isEntityFixed(anOtherEntID, true)) { @@ -352,3 +402,15 @@ bool SketchSolver_ConstraintRigid::isUsedInEqual( return false; } +bool SketchSolver_ConstraintRigid::isAxisParallel(const Slvs_Entity& theEntity) const +{ + std::list aConstr = myStorage->getConstraintsByType(SLVS_C_HORIZONTAL); + std::list aVert = myStorage->getConstraintsByType(SLVS_C_VERTICAL); + aConstr.insert(aConstr.end(), aVert.begin(), aVert.end()); + + std::list::const_iterator anIter = aConstr.begin(); + for (; anIter != aConstr.end(); anIter++) + if (anIter->entityA == theEntity.h) + return true; + return false; +}