X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Constraint.cpp;h=e4af2a0643970b1518b35cd344566ccaffdce20a;hb=51889d235a27d0ee4b3c3237d21d1ea621063580;hp=88f4572a17c05d7e8b20e352b0524cf32045a075;hpb=7bf19255421b34594c7b0a76d0ce28166d0ce895;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 88f4572a1..e4af2a064 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -13,11 +13,15 @@ #include #include #include +#include +#include #include #include #include #include #include +#include +#include #include #include @@ -197,6 +201,67 @@ const int& SketchSolver_Constraint::getType( return getType(); } + // Constraint for horizontal/vertical line + bool isHorizontal = (aConstraintKind.compare(SketchPlugin_ConstraintHorizontal::ID()) == 0); + bool isVertical = (aConstraintKind.compare(SketchPlugin_ConstraintVertical::ID()) == 0); + if (isHorizontal || isVertical) { + int aNbEntities = 2; // lines in SolveSpace constraints should start from SketchPlugin_Constraint::ENTITY_C() attribute + for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + if (typeOfAttribute(anAttr) == LINE) + myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + } + if (aNbEntities == 3) + myType = isHorizontal ? SLVS_C_HORIZONTAL : SLVS_C_VERTICAL; + return getType(); + } + + if (aConstraintKind.compare(SketchPlugin_ConstraintEqual::ID()) == 0) + { + static const int aConstrType[3] = { + SLVS_C_EQUAL_RADIUS, + SLVS_C_EQUAL_LINE_ARC_LEN, + SLVS_C_EQUAL_LENGTH_LINES + }; + int aNbLines = 0; + int aNbEntities = 2; // lines and circles in SolveSpace constraints should start from SketchPlugin_Constraint::ENTITY_C() attribute + for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + AttrType aType = typeOfAttribute(anAttr); + if (aType == LINE) { + myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + aNbLines++; + } + else if (aType == CIRCLE || aType == ARC) + myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + } + if (aNbEntities == 4) + myType = aConstrType[aNbLines]; + return getType(); + } + + if (aConstraintKind.compare(SketchPlugin_ConstraintTangent::ID()) == 0) + { + static const int anArcPosDefault = 2; + static const int aLinePosDefault = 3; + int anArcPos = anArcPosDefault; // arc in tangency constraint should be placed before line + int aLinePos = aLinePosDefault; + for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + AttrType aType = typeOfAttribute(anAttr); + if (aType == LINE && aLinePos < CONSTRAINT_ATTR_SIZE) + myAttributesList[aLinePos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + else if (aType == ARC) + myAttributesList[anArcPos++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + } + if (anArcPos - anArcPosDefault + aLinePos - aLinePosDefault == 2) + myType = aLinePos > 3 ? SLVS_C_ARC_LINE_TANGENT : SLVS_C_CURVE_CURVE_TANGENT; + return getType(); + } + /// \todo Implement other kind of constraints return getType(); @@ -229,11 +294,13 @@ AttrType typeOfAttribute(std::shared_ptr theAttribute) return ARC; } } else { - const std::string aType = anAttrRef->attr()->attributeType(); - if (aType == GeomDataAPI_Point2D::type()) - return POINT2D; - if (aType == GeomDataAPI_Point2D::type()) - return POINT2D; + if (anAttrRef->attr().get() != NULL) { + const std::string aType = anAttrRef->attr()->attributeType(); + if (aType == GeomDataAPI_Point2D::type()) + return POINT2D; + if (aType == GeomDataAPI_Point2D::type()) + return POINT2D; + } } return UNKNOWN;