X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchSolver%2FSketchSolver_Constraint.cpp;h=1a4a594849be4b01941bc3d333eee3ed13fb5bb3;hb=884210338f7a0d6ea5442328609c841028503334;hp=2cdd24eb796e3840682658844ca98449624b604f;hpb=9ea97108f0859c83264c469256f065e7e5b36512;p=modules%2Fshaper.git diff --git a/src/SketchSolver/SketchSolver_Constraint.cpp b/src/SketchSolver/SketchSolver_Constraint.cpp index 2cdd24eb7..1a4a59484 100644 --- a/src/SketchSolver/SketchSolver_Constraint.cpp +++ b/src/SketchSolver/SketchSolver_Constraint.cpp @@ -1,225 +1,198 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + #include -#include #include +#include +#include + #include #include #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include #include #include #include #include +#include SketchSolver_Constraint::SketchSolver_Constraint( ConstraintPtr theConstraint) : myBaseConstraint(theConstraint), - myGroup(0) -{ -} - -SketchSolver_Constraint::~SketchSolver_Constraint() + myType(CONSTRAINT_UNKNOWN) { - std::map::const_iterator anIt1 = myValueMap.begin(); - for (; anIt1 != myValueMap.end(); anIt1++) - myStorage->removeParameter(anIt1->second); - myValueMap.clear(); - - std::map::const_iterator anIt2 = myAttributeMap.begin(); - for (; anIt2 != myAttributeMap.end(); anIt2++) - myStorage->removeEntity(anIt2->second); - myAttributeMap.clear(); - - std::map::const_iterator anIt3 = myFeatureMap.begin(); - for (; anIt3 != myFeatureMap.end(); anIt3++) - myStorage->removeEntity(anIt3->second); - myFeatureMap.clear(); - - std::vector::const_iterator anIt4 = mySlvsConstraints.begin(); - for (; anIt4 != mySlvsConstraints.end(); anIt4++) - myStorage->removeConstraint(*anIt4); - mySlvsConstraints.clear(); } -void SketchSolver_Constraint::setStorage(StoragePtr theStorage) +void SketchSolver_Constraint::process(StoragePtr theStorage, bool theEvensBlocked) { myStorage = theStorage; + blockEvents(theEvensBlocked); + // Process constraint according to its type process(); } -void SketchSolver_Constraint::setGroup(SketchSolver_Group* theGroup) -{ - myGroup = theGroup; - process(); +void SketchSolver_Constraint::blockEvents(bool isBlocked) +{ + myBaseConstraint->data()->blockSendAttributeUpdated(isBlocked); +} + + +SketchSolver_ConstraintType SketchSolver_Constraint::TYPE(ConstraintPtr theConstraint) +{ + const std::string& aType = theConstraint->getKind(); + if (aType == SketchPlugin_ConstraintCoincidence::ID()) + return CONSTRAINT_COINCIDENCE; + else if (aType == SketchPlugin_ConstraintRigid::ID()) + return CONSTRAINT_FIXED; + else if (aType == SketchPlugin_ConstraintHorizontal::ID()) + return CONSTRAINT_HORIZONTAL; + else if (aType == SketchPlugin_ConstraintVertical::ID()) + return CONSTRAINT_VERTICAL; + else if (aType == SketchPlugin_ConstraintAngle::ID()) + return CONSTRAINT_ANGLE; + else if (aType == SketchPlugin_ConstraintDistance::ID()) + return CONSTRAINT_DISTANCE; + else if (aType == SketchPlugin_ConstraintEqual::ID()) + return CONSTRAINT_EQUAL; + else if (aType == SketchPlugin_ConstraintLength::ID()) + return CONSTRAINT_PT_PT_DISTANCE; + else if (aType == SketchPlugin_ConstraintMirror::ID()) + return CONSTRAINT_SYMMETRIC; + else if (aType == SketchPlugin_ConstraintParallel::ID()) + return CONSTRAINT_PARALLEL; + else if (aType == SketchPlugin_ConstraintPerpendicular::ID()) + return CONSTRAINT_PERPENDICULAR; + else if (aType == SketchPlugin_ConstraintRadius::ID()) + return CONSTRAINT_RADIUS; + else if (aType == SketchPlugin_ConstraintTangent::ID()) + return CONSTRAINT_TANGENT; + else if (aType == SketchPlugin_ConstraintCollinear::ID()) + return CONSTRAINT_COLLINEAR; + else if (aType == SketchPlugin_ConstraintMiddle::ID()) + return CONSTRAINT_MIDDLE_POINT; + return CONSTRAINT_UNKNOWN; } - void SketchSolver_Constraint::process() { cleanErrorMsg(); - if (!myBaseConstraint || !myStorage || myGroup == 0) { - /// TODO: Put error message here + if (!myBaseConstraint || !myStorage) { + // Not enough parameters are assigned return; } - if (!mySlvsConstraints.empty()) // some data is changed, update constraint - update(myBaseConstraint); - int aConstrType = getType(); - double aValue = 0.0; - std::vector anAttributes; + SketchSolver_ConstraintType aConstrType = getType(); + EntityWrapperPtr aValue; + std::vector anAttributes; getAttributes(aValue, anAttributes); if (!myErrorMsg.empty()) return; - - Slvs_hGroup aGroupID = myGroup->getId(); - Slvs_hEntity aWorkplaneID = myGroup->getWorkplaneId(); - Slvs_Constraint aConstraint; - if (mySlvsConstraints.empty()) - aConstraint = Slvs_MakeConstraint(SLVS_C_UNKNOWN, aGroupID, aConstrType, aWorkplaneID, - aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]); - else { - aConstraint = myStorage->getConstraint(mySlvsConstraints[0]); - aConstraint.valA = aValue; - static const int aNbAttrs = 6; - Slvs_hEntity* aConstrAttrs[aNbAttrs] = { - &aConstraint.ptA, &aConstraint.ptB, - &aConstraint.entityA, &aConstraint.entityB, - &aConstraint.entityC, &aConstraint.entityD}; - std::vector::const_iterator anIter = anAttributes.begin(); - for (int i = 0; i < aNbAttrs && anIter != anAttributes.end(); i++, anIter++) - *(aConstrAttrs[i]) = *anIter; + if (anAttributes.empty()) { + myErrorMsg = SketchSolver_Error::INCORRECT_ATTRIBUTE(); + return; } + if (aConstrType == CONSTRAINT_UNKNOWN) + aConstrType = getType(); + + ConstraintWrapperPtr aNewConstraint = PlaneGCSSolver_Tools::createConstraint( + myBaseConstraint, aConstrType, + aValue, anAttributes[0], anAttributes[1], anAttributes[2], anAttributes[3]); + myStorage->addConstraint(myBaseConstraint, aNewConstraint); - Slvs_hConstraint anID = myStorage->addConstraint(aConstraint); - if (mySlvsConstraints.empty()) - mySlvsConstraints.push_back(anID); - else - mySlvsConstraints[0] = anID; adjustConstraint(); } -void SketchSolver_Constraint::update(ConstraintPtr theConstraint) +void SketchSolver_Constraint::update() { cleanErrorMsg(); - if (theConstraint && theConstraint != myBaseConstraint) { - if (theConstraint->getKind() != myBaseConstraint->getKind()) - return; - remove(myBaseConstraint); - myBaseConstraint = theConstraint; - process(); - } - // Update all attributes - int aType; - std::map aRelocationMap; - std::map::iterator aFeatIter = myFeatureMap.begin(); - for (; aFeatIter != myFeatureMap.end(); aFeatIter++) { - Slvs_hEntity aPrevID = aFeatIter->second; - aFeatIter->second = changeEntity(aFeatIter->first, aType); - if (aFeatIter->second != aPrevID) - aRelocationMap[aPrevID] = aFeatIter->second; - } - std::map::iterator anAttrIter = myAttributeMap.begin(); - for (; anAttrIter != myAttributeMap.end(); anAttrIter++) { - Slvs_hEntity aPrevID = anAttrIter->second; - anAttrIter->second = changeEntity(anAttrIter->first, aType); - if (anAttrIter->second != aPrevID) - aRelocationMap[aPrevID] = anAttrIter->second; + // Get list of attributes of the constraint and compare it with previously stored. + // If the lists are different, fully rebuild constraint + std::set anAttributes; + for (int anEntIndex = 0; anEntIndex < 4; ++anEntIndex) { + AttributePtr anAttr = + myBaseConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(anEntIndex)); + if (!anAttr) + continue; + + if (myBaseConstraint->getKind() == SketchPlugin_ConstraintLength::ID()) { + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(anAttr); + FeaturePtr aFeat = ModelAPI_Feature::feature(aRefAttr->object()); + if (aFeat) { + // Workaround for the Length constraint: add points of line, not line itself + anAttributes.insert(myStorage->entity(aFeat->attribute(SketchPlugin_Line::START_ID()))); + anAttributes.insert(myStorage->entity(aFeat->attribute(SketchPlugin_Line::END_ID()))); + } + } else + anAttributes.insert(myStorage->entity(anAttr)); } - // Value if exists - AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast( - myBaseConstraint->data()->attribute(SketchPlugin_Constraint::VALUE())); - double aValue = aValueAttr ? aValueAttr->value() : 0.0; + std::set::iterator aFound; + std::list::const_iterator anAttrIt = myAttributes.begin(); + for (; anAttrIt != myAttributes.end() && !anAttributes.empty(); ++anAttrIt) + anAttributes.erase(*anAttrIt); - // Update constraint - std::vector::iterator aCIter = mySlvsConstraints.begin(); - for (; aCIter != mySlvsConstraints.end(); aCIter++) { - Slvs_Constraint aConstraint = myStorage->getConstraint(*aCIter); - aConstraint.valA = aValue; - Slvs_hEntity* aCoeffs[6] = { - &aConstraint.ptA, &aConstraint.ptB, - &aConstraint.entityA, &aConstraint.entityB, - &aConstraint.entityC, &aConstraint.entityD}; - for (int i = 0; i < 6; i++) { - if (*(aCoeffs[i]) == SLVS_E_UNKNOWN) - continue; - std::map::iterator aFound = aRelocationMap.find(*(aCoeffs[i])); - if (aFound != aRelocationMap.end()) - *(aCoeffs[i]) = aFound->second; - } - *aCIter = myStorage->addConstraint(aConstraint); + if (!anAttributes.empty()) { + remove(); + process(); + return; } + + AttributePtr aValueAttr = myBaseConstraint->attribute(SketchPlugin_Constraint::VALUE()); + if (aValueAttr) + myStorage->update(aValueAttr); + adjustConstraint(); } -bool SketchSolver_Constraint::remove(ConstraintPtr theConstraint) +bool SketchSolver_Constraint::remove() { cleanErrorMsg(); - if (theConstraint && theConstraint != myBaseConstraint) - return false; - bool isFullyRemoved = myStorage->removeConstraint(mySlvsConstraints.front()); - if (isFullyRemoved) { - myFeatureMap.clear(); - myAttributeMap.clear(); - myValueMap.clear(); - } else - cleanRemovedEntities(); - return true; -} - -void SketchSolver_Constraint::cleanRemovedEntities() -{ - std::set aRemovedParams; - std::set aRemovedEntities; - std::set aRemovedConstraints; - myStorage->getRemoved(aRemovedParams, aRemovedEntities, aRemovedConstraints); - std::map::iterator aFeatIt = myFeatureMap.begin(); - while (aFeatIt != myFeatureMap.end()) { - if (aRemovedEntities.find(aFeatIt->second) == aRemovedEntities.end()) { - aFeatIt++; - continue; - } - std::map::iterator aTmpIter = aFeatIt++; - myFeatureMap.erase(aTmpIter); - } - std::map::iterator anAttrIt = myAttributeMap.begin(); - while (anAttrIt != myAttributeMap.end()) { - if (aRemovedEntities.find(anAttrIt->second) == aRemovedEntities.end()) { - anAttrIt++; - continue; - } - std::map::iterator aTmpIter = anAttrIt++; - myAttributeMap.erase(aTmpIter); - } - std::map::iterator aValIt = myValueMap.begin(); - while (aValIt != myValueMap.end()) { - if (aRemovedParams.find(aValIt->second) == aRemovedParams.end()) { - aValIt++; - continue; - } - std::map::iterator aTmpIter = aValIt++; - myValueMap.erase(aTmpIter); - } + myType = CONSTRAINT_UNKNOWN; + myStorage->unsubscribeUpdates(this); + return myStorage->removeConstraint(myBaseConstraint); } void SketchSolver_Constraint::getAttributes( - double& theValue, - std::vector& theAttributes) + EntityWrapperPtr& theValue, + std::vector& theAttributes) { static const int anInitNbOfAttr = 4; - theAttributes.assign(anInitNbOfAttr, SLVS_E_UNKNOWN); + theAttributes.assign(anInitNbOfAttr, EntityWrapperPtr()); + myAttributes.clear(); DataPtr aData = myBaseConstraint->data(); - AttributeDoublePtr aValueAttr = std::dynamic_pointer_cast( - aData->attribute(SketchPlugin_Constraint::VALUE())); - theValue = aValueAttr ? aValueAttr->value() : 0.0; + myType = TYPE(myBaseConstraint); + + AttributePtr aValueAttr = aData->attribute(SketchPlugin_Constraint::VALUE()); + if (aValueAttr) { + PlaneGCSSolver_AttributeBuilder aValueBuilder; + theValue = aValueBuilder.createAttribute(aValueAttr); + myStorage->addEntity(aValueAttr, theValue); + } int aPtInd = 0; // index of first point in the list of attributes - int aEntInd = 2; // index of first antity in the list of attributes + int aEntInd = 2; // index of first entity in the list of attributes std::list aConstrAttrs = aData->attributes(ModelAPI_AttributeRefAttr::typeId()); std::list::iterator anIter = aConstrAttrs.begin(); for (; anIter != aConstrAttrs.end(); anIter++) { @@ -230,18 +203,14 @@ void SketchSolver_Constraint::getAttributes( return; } - int aType = SLVS_E_UNKNOWN; // type of created entity - Slvs_hEntity anEntity = myGroup->getAttributeId(aRefAttr); - if (anEntity == SLVS_E_UNKNOWN) - anEntity = changeEntity(aRefAttr, aType); - else { - Slvs_Entity anEnt = myStorage->getEntity(anEntity); - aType = anEnt.type; - } + myStorage->update(*anIter, true); + EntityWrapperPtr anEntity = myStorage->entity(*anIter); + myAttributes.push_back(anEntity); - if (aType == SLVS_E_UNKNOWN) + SketchSolver_EntityType aType = anEntity->type(); + if (aType == ENTITY_UNKNOWN) continue; - else if (aType == SLVS_E_POINT_IN_2D || aType == SLVS_E_POINT_IN_3D) + else if (aType == ENTITY_POINT) theAttributes[aPtInd++] = anEntity; // the point is created else { // another entity (not a point) is created if (aEntInd < anInitNbOfAttr) @@ -252,303 +221,3 @@ void SketchSolver_Constraint::getAttributes( } } } - -Slvs_hEntity SketchSolver_Constraint::changeEntity(AttributeRefAttrPtr theAttribute, int& theType) -{ - // Convert the object of the attribute to the feature - FeaturePtr aFeature; - if (theAttribute->isObject() && theAttribute->object()) { - ResultConstructionPtr aRC = std::dynamic_pointer_cast( - theAttribute->object()); - if (!aRC) { - myErrorMsg = SketchSolver_Error::NOT_INITIALIZED(); - return SLVS_E_UNKNOWN; - } - std::shared_ptr aDoc = aRC->document(); - aFeature = aDoc->feature(aRC); - - return changeEntity(aFeature, theType); - } - - return changeEntity(theAttribute->attr(), theType); -} - -Slvs_hEntity SketchSolver_Constraint::changeEntity(AttributePtr theEntity, int& theType) -{ - Slvs_hEntity aResult = SLVS_E_UNKNOWN; - if (!theEntity->isInitialized()) - return SLVS_E_UNKNOWN; - - // If the entity is already in the group, try to find it - std::map, Slvs_hEntity>::const_iterator anEntIter = - myAttributeMap.find(theEntity); - Slvs_Entity aCurrentEntity; - aCurrentEntity.h = SLVS_E_UNKNOWN; - if (anEntIter != myAttributeMap.end()) - aCurrentEntity = myStorage->getEntity(anEntIter->second); - else { - aResult = myGroup->getAttributeId(theEntity); - if (aResult != SLVS_E_UNKNOWN) { - Slvs_Entity anEnt = myStorage->getEntity(aResult); - theType = anEnt.type; - return aResult; - } - } - - Slvs_hGroup aGroupID = myGroup->getId(); - // Point in 3D - std::shared_ptr aPoint = - std::dynamic_pointer_cast(theEntity); - if (aPoint) { - double aXYZ[3] = {aPoint->x(), aPoint->y(), aPoint->z()}; - Slvs_hParam aParams[3]; - for (int i = 0; i < 3; i++) { - Slvs_Param aPar = aCurrentEntity.h != SLVS_E_UNKNOWN ? - myStorage->getParameter(aCurrentEntity.param[i]) : - Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0); - aPar.val = aXYZ[i]; - aParams[i] = myStorage->addParameter(aPar); - } - - if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity - aCurrentEntity = Slvs_MakePoint3d(SLVS_E_UNKNOWN, aGroupID, aParams[0], aParams[1], aParams[2]); - else { // update entity data - for (int i = 0; i < 3; i++) - aCurrentEntity.param[i] = aParams[i]; - } - aResult = myStorage->addEntity(aCurrentEntity); - } else { - // All entities except 3D points are created on workplane. So, if there is no workplane yet, then error - Slvs_hEntity aWorkplaneID = myGroup->getWorkplaneId(); - if (aWorkplaneID == SLVS_E_UNKNOWN) - return SLVS_E_UNKNOWN; - - // Point in 2D - std::shared_ptr aPoint2D = - std::dynamic_pointer_cast(theEntity); - if (aPoint2D) { - double aXY[2] = {aPoint2D->x(), aPoint2D->y()}; - Slvs_hParam aParams[2]; - for (int i = 0; i < 2; i++) { - Slvs_Param aPar = aCurrentEntity.h != SLVS_E_UNKNOWN ? - myStorage->getParameter(aCurrentEntity.param[i]) : - Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0); - aPar.val = aXY[i]; - aParams[i] = myStorage->addParameter(aPar); - } - - if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity - aCurrentEntity = Slvs_MakePoint2d(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aParams[0], aParams[1]); - else { // update entity data - for (int i = 0; i < 2; i++) - aCurrentEntity.param[i] = aParams[i]; - } - aResult = myStorage->addEntity(aCurrentEntity); - } else { - // Scalar value (used for the distance entities) - AttributeDoublePtr aScalar = std::dynamic_pointer_cast(theEntity); - if (aScalar) { - Slvs_Param aParam = aCurrentEntity.h != SLVS_E_UNKNOWN ? - myStorage->getParameter(aCurrentEntity.param[0]) : - Slvs_MakeParam(SLVS_E_UNKNOWN, aGroupID, 0.0); - aParam.val = aScalar->value(); - Slvs_hParam aValue = myStorage->addParameter(aParam); - - if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity - aCurrentEntity = Slvs_MakeDistance(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aValue); - else - aCurrentEntity.param[0] = aValue; - aResult = myStorage->addEntity(aCurrentEntity); - } - } - } - - myAttributeMap[theEntity] = aResult; - theType = aCurrentEntity.type; - return aResult; -} - -Slvs_hEntity SketchSolver_Constraint::changeEntity(FeaturePtr theEntity, int& theType) -{ - Slvs_hEntity aResult = SLVS_E_UNKNOWN; - if (!theEntity->data()->isValid()) - return SLVS_E_UNKNOWN; - // If the entity is already in the group, try to find it - std::map::const_iterator anEntIter = myFeatureMap.find(theEntity); - Slvs_Entity aCurrentEntity; - aCurrentEntity.h = SLVS_E_UNKNOWN; - if (anEntIter != myFeatureMap.end()) - aCurrentEntity = myStorage->getEntity(anEntIter->second); - else { - aResult = myGroup->getFeatureId(theEntity); - if (aResult != SLVS_E_UNKNOWN) { - Slvs_Entity anEnt = myStorage->getEntity(aResult); - theType = anEnt.type; - return aResult; - } - } - - Slvs_hGroup aGroupID = myGroup->getId(); - Slvs_hEntity aWorkplaneID = myGroup->getWorkplaneId(); - // SketchPlugin features - std::shared_ptr aFeature = std::dynamic_pointer_cast< - SketchPlugin_Feature>(theEntity); - if (aFeature) { // Verify the feature by its kind - const std::string& aFeatureKind = aFeature->getKind(); - AttributePtr anAttribute; - int anAttrType; - - // Line - if (aFeatureKind == SketchPlugin_Line::ID()) { - anAttribute = aFeature->data()->attribute(SketchPlugin_Line::START_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - Slvs_hEntity aStart = changeEntity(anAttribute, anAttrType); - - anAttribute = aFeature->data()->attribute(SketchPlugin_Line::END_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType); - - if (aCurrentEntity.h == SLVS_E_UNKNOWN) // New entity - aCurrentEntity = Slvs_MakeLineSegment(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, aStart, aEnd); - else { - aCurrentEntity.point[0] = aStart; - aCurrentEntity.point[1] = aEnd; - } - aResult = myStorage->addEntity(aCurrentEntity); - } - // Circle - else if (aFeatureKind == SketchPlugin_Circle::ID()) { - anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::CENTER_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType); - - anAttribute = aFeature->data()->attribute(SketchPlugin_Circle::RADIUS_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - Slvs_hEntity aRadius = changeEntity(anAttribute, anAttrType); - - if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity - Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID); - aCurrentEntity = Slvs_MakeCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, - aCenter, aWorkplane.normal, aRadius); - } else { - aCurrentEntity.point[0] = aCenter; - aCurrentEntity.distance = aRadius; - } - aResult = myStorage->addEntity(aCurrentEntity); - } - // Arc - else if (aFeatureKind == SketchPlugin_Arc::ID()) { - anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::CENTER_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - Slvs_hEntity aCenter = changeEntity(anAttribute, anAttrType); - - anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::START_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - Slvs_hEntity aStart = changeEntity(anAttribute, anAttrType); - - anAttribute = aFeature->data()->attribute(SketchPlugin_Arc::END_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - Slvs_hEntity aEnd = changeEntity(anAttribute, anAttrType); - - if (aCurrentEntity.h == SLVS_E_UNKNOWN) { // New entity - Slvs_Entity aWorkplane = myStorage->getEntity(aWorkplaneID); - aCurrentEntity = Slvs_MakeArcOfCircle(SLVS_E_UNKNOWN, aGroupID, aWorkplaneID, - aWorkplane.normal, aCenter, aStart, aEnd); - } else { - aCurrentEntity.point[0] = aCenter; - aCurrentEntity.point[1] = aStart; - aCurrentEntity.point[2] = aEnd; - } - aResult = myStorage->addEntity(aCurrentEntity); - } - // Point (it has low probability to be an attribute of constraint, so it is checked at the end) - else if (aFeatureKind == SketchPlugin_Point::ID()) { - anAttribute = aFeature->data()->attribute(SketchPlugin_Point::COORD_ID()); - if (!anAttribute->isInitialized()) return SLVS_E_UNKNOWN; - // Both the sketch point and its attribute (coordinates) link to the same SolveSpace point identifier - aResult = changeEntity(anAttribute, anAttrType); - aCurrentEntity.type = SLVS_E_POINT_IN_3D; - } - } - - if (aResult != SLVS_E_UNKNOWN) { - myFeatureMap[theEntity] = aResult; - theType = aCurrentEntity.type; - } - return aResult; -} - -std::list SketchSolver_Constraint::constraints() const -{ - std::list aConstraints; - aConstraints.push_back(myBaseConstraint); - return aConstraints; -} - -void SketchSolver_Constraint::refresh() -{ - cleanErrorMsg(); - std::map::iterator anAttrIter = myAttributeMap.begin(); - for (; anAttrIter != myAttributeMap.end(); anAttrIter++) { - std::shared_ptr aPoint = - std::dynamic_pointer_cast(anAttrIter->first); - if (aPoint) { - Slvs_Entity anEntity = myStorage->getEntity(anAttrIter->second); - double aXYZ[3]; - for (int i = 0; i < 3; i++) { - Slvs_Param aPar = myStorage->getParameter(anEntity.param[i]); - aXYZ[i] = aPar.val; - } - aPoint->setValue(aXYZ[0], aXYZ[1], aXYZ[2]); - } else { - // Point in 2D - std::shared_ptr aPoint2D = - std::dynamic_pointer_cast(anAttrIter->first); - if (aPoint2D) { - Slvs_Entity anEntity = myStorage->getEntity(anAttrIter->second); - double aXYZ[2]; - for (int i = 0; i < 2; i++) { - Slvs_Param aPar = myStorage->getParameter(anEntity.param[i]); - aXYZ[i] = aPar.val; - } - aPoint2D->setValue(aXYZ[0], aXYZ[1]); - } else { - // Scalar value (used for the distance entities) - AttributeDoublePtr aScalar = - std::dynamic_pointer_cast(anAttrIter->first); - if (aScalar) { - Slvs_Entity anEntity = myStorage->getEntity(anAttrIter->second); - Slvs_Param aPar = myStorage->getParameter(anEntity.param[0]); - aScalar->setValue(aPar.val); - } - } - } - } - - std::map::iterator aValIter = myValueMap.begin(); - for (; aValIter != myValueMap.end(); aValIter++) { - AttributeDoublePtr aScalar = - std::dynamic_pointer_cast(anAttrIter->first); - if (aScalar) { - Slvs_Param aPar = myStorage->getParameter(anAttrIter->second); - aScalar->setValue(aPar.val); - } - } -} - -Slvs_hEntity SketchSolver_Constraint::getId(FeaturePtr theFeature) const -{ - std::map::const_iterator aFIter = myFeatureMap.find(theFeature); - if (aFIter == myFeatureMap.end()) - return SLVS_E_UNKNOWN; - return aFIter->second; -} - -Slvs_hEntity SketchSolver_Constraint::getId(AttributePtr theAttribute) const -{ - std::map::const_iterator anAttrIter = myAttributeMap.find(theAttribute); - if (anAttrIter == myAttributeMap.end()) - return SLVS_E_UNKNOWN; - return anAttrIter->second; -} -