X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Constraint.cpp;h=88f4572a17c05d7e8b20e352b0524cf32045a075;hb=2d309adb3c465a840e8f5ceeba28ec145e5a45a2;hp=d5f1e6810f95dda81de2d48ff4b0a4ef31ec9c1a;hpb=cd9217d7e87997ec8bc150a6d8c389e742ca0f84;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index d5f1e6810..88f4572a1 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -1,3 +1,5 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + // File: SketchSolver_Constraint.cpp // Created: 27 May 2014 // Author: Artem ZHIDKOV @@ -15,6 +17,7 @@ #include #include #include +#include #include #include @@ -39,17 +42,17 @@ enum AttrType }; /// Calculate type of the attribute -static AttrType typeOfAttribute(boost::shared_ptr theAttribute); +static AttrType typeOfAttribute(std::shared_ptr theAttribute); SketchSolver_Constraint::SketchSolver_Constraint() - : myConstraint(boost::shared_ptr()), + : myConstraint(std::shared_ptr()), myType(SLVS_C_UNKNOWN), myAttributesList() { } SketchSolver_Constraint::SketchSolver_Constraint( - boost::shared_ptr theConstraint) + std::shared_ptr theConstraint) : myConstraint(theConstraint), myAttributesList() { @@ -57,12 +60,16 @@ SketchSolver_Constraint::SketchSolver_Constraint( } const int& SketchSolver_Constraint::getType( - boost::shared_ptr theConstraint) + std::shared_ptr theConstraint) { myType = SLVS_C_UNKNOWN; if (!theConstraint) return getType(); + DataPtr aConstrData = theConstraint->data(); + if (!aConstrData || !aConstrData->isValid()) + return getType(); + // Assign empty names of attributes myAttributesList.clear(); for (int i = 0; i < CONSTRAINT_ATTR_SIZE; i++) @@ -76,8 +83,8 @@ const int& SketchSolver_Constraint::getType( int aPt2d = 0; // bit-mapped field, each bit indicates whether the attribute is 2D point int aPt3d = 0; // bit-mapped field, the same information for 3D points for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { - boost::shared_ptr anAttr = theConstraint->data()->attribute( - SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); if (!anAttr) continue; switch (typeOfAttribute(anAttr)) { @@ -107,8 +114,8 @@ const int& SketchSolver_Constraint::getType( int aNbPoints = 0; int aNbEntities = 0; for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { - boost::shared_ptr anAttr = theConstraint->data()->attribute( - SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); switch (typeOfAttribute(anAttr)) { case POINT2D: case POINT3D: @@ -133,8 +140,8 @@ const int& SketchSolver_Constraint::getType( if (aConstraintKind.compare(SketchPlugin_ConstraintLength::ID()) == 0) { int aNbLines = 0; for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { - boost::shared_ptr anAttr = theConstraint->data()->attribute( - SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); if (typeOfAttribute(anAttr) == LINE) myAttributesList[aNbLines++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); } @@ -149,8 +156,8 @@ const int& SketchSolver_Constraint::getType( if (isParallel || isPerpendicular) { 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++) { - boost::shared_ptr anAttr = theConstraint->data()->attribute( - SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); if (typeOfAttribute(anAttr) == LINE) myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); } @@ -163,8 +170,8 @@ const int& SketchSolver_Constraint::getType( if (aConstraintKind.compare(SketchPlugin_ConstraintRadius::ID()) == 0) { int aNbEntities = 2; // lines in SolveSpace constraints should started from SketchPlugin_Constraint::ENTITY_C() attribute for (unsigned int indAttr = 0; indAttr < CONSTRAINT_ATTR_SIZE; indAttr++) { - boost::shared_ptr anAttr = theConstraint->data()->attribute( - SketchPlugin_Constraint::ATTRIBUTE(indAttr)); + std::shared_ptr anAttr = + aConstrData->attribute(SketchPlugin_Constraint::ATTRIBUTE(indAttr)); AttrType aType = typeOfAttribute(anAttr); if (aType == CIRCLE || aType == ARC) myAttributesList[aNbEntities++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); @@ -174,29 +181,45 @@ const int& SketchSolver_Constraint::getType( return getType(); } + // Constraint for fixed entity + if (aConstraintKind.compare(SketchPlugin_ConstraintRigid::ID()) == 0) { + // Verify that only one entity is filled + int aNbAttrs = 0; + 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 != UNKNOWN) + myAttributesList[aNbAttrs++] = SketchPlugin_Constraint::ATTRIBUTE(indAttr); + } + if (aNbAttrs == 1) + myType = SLVS_C_WHERE_DRAGGED; + return getType(); + } + /// \todo Implement other kind of constraints return getType(); } // ================= Auxiliary functions ============================== -AttrType typeOfAttribute(boost::shared_ptr theAttribute) +AttrType typeOfAttribute(std::shared_ptr theAttribute) { - boost::shared_ptr anAttrRef = boost::dynamic_pointer_cast< + std::shared_ptr anAttrRef = std::dynamic_pointer_cast< ModelAPI_AttributeRefAttr>(theAttribute); if (!anAttrRef) return UNKNOWN; if (anAttrRef->isObject()) { - ResultConstructionPtr aRC = boost::dynamic_pointer_cast( + ResultConstructionPtr aRC = std::dynamic_pointer_cast( anAttrRef->object()); - if (!aRC) + if (!aRC || !aRC->shape()) return UNKNOWN; if (aRC->shape()->isVertex()) return POINT3D; else if (aRC->shape()->isEdge()) { - boost::shared_ptr anEdge = boost::dynamic_pointer_cast( + std::shared_ptr anEdge = std::dynamic_pointer_cast( aRC->shape()); if (anEdge->isLine()) return LINE;