Update unit tests for code coverage.
assert (not refattrB.isInitialized())
aLineResult = aSketchLine.firstResult()
assert (aLineResult is not None)
+# the following line is necessary to check automatic calculation of a distance
+aConstraint.execute()
refattrA.setAttr(aSketchPointCoords)
refattrB.setAttr(aLineAStartPoint)
aSession.finishOperation()
aVecY = aLineStart.y() - aLineEnd.y()
return math.hypot(aVecX, aVecY)
+def arcLength(theArc):
+ aCenter = geomDataAPI_Point2D(theArc.attribute("ArcCenter"))
+ aStart = geomDataAPI_Point2D(theArc.attribute("ArcStartPoint"))
+ aEnd = geomDataAPI_Point2D(theArc.attribute("ArcEndPoint"))
+ # use the law of cosines to calculate angular length of arc
+ aRadius = math.hypot(aStart.x() - aCenter.x(), aStart.y() - aCenter.y())
+ aDist2 = (aEnd.x()-aStart.x())**2 + (aEnd.y()-aStart.y())**2
+ anAngle = math.acos(1. - aDist2 / (2. * aRadius**2))
+ return aRadius * anAngle
+
#=========================================================================
# Start of test
aLine2Len = lineLength(aSketchLine2)
assert (math.fabs(aLine1Len - anExtLineLen) < 1.e-10)
assert (math.fabs(aLine2Len - anExtLineLen) < 1.e-10)
+
+#=========================================================================
+# A constraint to make equal lengths of line and arc
+#=========================================================================
+# Third Line
+aSession.startOperation()
+aSketchLine3 = aSketchFeature.addFeature("SketchLine")
+aLine3StartPoint = geomDataAPI_Point2D(aSketchLine3.attribute("StartPoint"))
+aLine3EndPoint = geomDataAPI_Point2D(aSketchLine3.attribute("EndPoint"))
+aLine3StartPoint.setValue(20., 15.)
+aLine3EndPoint.setValue(20., 25.)
+aSession.finishOperation()
+aSession.startOperation()
+anEqArcLineLen = aSketchFeature.addFeature("SketchConstraintEqual")
+aRefObjectA = anEqArcLineLen.refattr("ConstraintEntityA")
+aRefObjectB = anEqArcLineLen.refattr("ConstraintEntityB")
+aRefObjectA.setObject(aSketchArc.lastResult())
+aRefObjectB.setObject(aSketchLine3.lastResult())
+aSession.finishOperation()
+aLine3Len = lineLength(aSketchLine3)
+anArcLen = arcLength(aSketchArc)
+assert (math.fabs(aLine3Len - anArcLen) < 1.e-7)
#=========================================================================
# End of test
#=========================================================================
anArcEndPoint = geomDataAPI_Point2D(aSketchArc.attribute("ArcEndPoint"))
anArcEndPoint.setValue(50., 0.)
aSession.finishOperation()
+# Test changing the arc start/end point
+aSession.startOperation()
+anArcStartPoint.setValue(anArcStartPoint.x(), 40.)
+anArcStartPoint.setValue(0., 50.)
+assert (math.hypot(anArcStartPoint.x() - 0., anArcStartPoint.y() - 50.) < 1.e-10)
+aSession.finishOperation()
+aSession.startOperation()
+anArcEndPoint.setValue(40., anArcEndPoint.y())
+anArcEndPoint.setValue(50., 0.)
+assert (math.hypot(anArcEndPoint.x() - 50., anArcEndPoint.y() - 0.) < 1.e-10)
+aSession.finishOperation()
# Circle
aSession.startOperation()
aSketchCircle = aSketchFeature.addFeature("SketchCircle")
static void adjustAngle(ConstraintWrapperPtr theConstraint);
/// \brief Update mirror points
static void adjustMirror(ConstraintWrapperPtr theConstraint);
-/// \brief Update positions of rotated features
-static void adjustMultiRotation(ConstraintWrapperPtr theConstraint);
-/// \brief Update positions of translated features
-static void adjustMultiTranslation(ConstraintWrapperPtr theConstraint);
/// \brief Transform points to be symmetric regarding to the mirror line
static void makeMirrorPoints(EntityWrapperPtr theOriginal,
// Update flags and parameters in constraints
if (aType == CONSTRAINT_ANGLE)
adjustAngle(theConstraint);
- //else if (aType == CONSTRAINT_SYMMETRIC)
- // adjustMirror(theConstraint);
- else if (aType == CONSTRAINT_MULTI_ROTATION)
- adjustMultiRotation(theConstraint);
- else if (aType == CONSTRAINT_MULTI_TRANSLATION)
- adjustMultiTranslation(theConstraint);
}
EntityWrapperPtr PlaneGCSSolver_Builder::createFeature(
}
}
-////void adjustMirror(ConstraintWrapperPtr theConstraint)
-////{
-//// std::vector<EntityWrapperPtr> aPoints;
-//// EntityWrapperPtr aMirrorLine;
-////
-//// const std::list<EntityWrapperPtr>& aSubs = theConstraint->entities();
-//// std::list<EntityWrapperPtr>::const_iterator anIt = aSubs.begin();
-//// for (; anIt != aSubs.end(); ++anIt) {
-//// if ((*anIt)->type() == ENTITY_POINT)
-//// aPoints.push_back(*anIt);
-//// else if ((*anIt)->type() == ENTITY_LINE)
-//// aMirrorLine = *anIt;
-//// }
-////
-//// makeMirrorPoints(aPoints[0], aPoints[1], aMirrorLine);
-////}
-
void makeMirrorPoints(EntityWrapperPtr theOriginal,
EntityWrapperPtr theMirrored,
EntityWrapperPtr theMirrorLine)
}
}
-static void rotate(EntityWrapperPtr theSource, EntityWrapperPtr theDest,
- std::shared_ptr<GeomAPI_Pnt2d> theCenter,
- double theSin, double theCos)
-{
- if (theSource->type() == ENTITY_POINT) {
- // Rotate single point
- std::shared_ptr<GeomDataAPI_Point2D> aSrcAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theSource->baseAttribute());
- std::shared_ptr<GeomDataAPI_Point2D> aDstAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theDest->baseAttribute());
- if (aSrcAttr && aDstAttr) {
- std::shared_ptr<GeomAPI_XY> aVec = aSrcAttr->pnt()->xy()->decreased(theCenter->xy());
- double aNewX = aVec->x() * theCos - aVec->y() * theSin;
- double aNewY = aVec->x() * theSin + aVec->y() * theCos;
- aDstAttr->setValue(theCenter->x() + aNewX, theCenter->y() + aNewY);
- // set also parameters of the solver
- double aCoord[2] = {aDstAttr->x(), aDstAttr->y()};
- std::list<ParameterWrapperPtr>::const_iterator aDIt = theDest->parameters().begin();
- for (int i = 0; aDIt != theDest->parameters().end(); ++aDIt, ++i)
- (*aDIt)->setValue(aCoord[i]);
- }
- return;
- }
-
- FeaturePtr aDestFeature = theDest->baseFeature();
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(true);
-
- // Rotate points of the feature
- const std::list<EntityWrapperPtr>& aSrcSubs = theSource->subEntities();
- const std::list<EntityWrapperPtr>& aDstSubs = theDest->subEntities();
- std::list<EntityWrapperPtr>::const_iterator aSrcIt, aDstIt;
- for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin();
- aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt)
- rotate(*aSrcIt, *aDstIt, theCenter, theSin, theCos);
-
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(false);
-}
-
-static void translate(EntityWrapperPtr theSource, EntityWrapperPtr theDest,
- std::shared_ptr<GeomAPI_XY> theDelta)
-{
- if (theSource->type() == ENTITY_POINT) {
- // Translate single point
- std::shared_ptr<GeomDataAPI_Point2D> aSrcAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theSource->baseAttribute());
- std::shared_ptr<GeomDataAPI_Point2D> aDstAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theDest->baseAttribute());
- if (aSrcAttr && aDstAttr)
- aDstAttr->setValue(aSrcAttr->x() + theDelta->x(), aSrcAttr->y() + theDelta->y());
- return;
- }
-
- FeaturePtr aDestFeature = theDest->baseFeature();
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(true);
-
- // Translate points of the feature
- const std::list<EntityWrapperPtr>& aSrcSubs = theSource->subEntities();
- const std::list<EntityWrapperPtr>& aDstSubs = theDest->subEntities();
- std::list<EntityWrapperPtr>::const_iterator aSrcIt, aDstIt;
- for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin();
- aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt)
- translate(*aSrcIt, *aDstIt, theDelta);
-
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(false);
-}
-
-void adjustMultiRotation(ConstraintWrapperPtr theConstraint)
-{
- BuilderPtr aBuilder = PlaneGCSSolver_Builder::getInstance();
-
- double anAngleRad = theConstraint->value() * PI / 180.0;
- double aSin = sin(anAngleRad);
- double aCos = cos(anAngleRad);
-
- const std::list<EntityWrapperPtr>& aSubs = theConstraint->entities();
- std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
-
- std::shared_ptr<GeomAPI_Pnt2d> aCenter = aBuilder->point(*aSIt++);
- std::list<EntityWrapperPtr>::const_iterator aPrevIt = aSIt++;
- for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt)
- rotate(*aPrevIt, *aSIt, aCenter, aSin, aCos);
-}
-
-void adjustMultiTranslation(ConstraintWrapperPtr theConstraint)
-{
- BuilderPtr aBuilder = PlaneGCSSolver_Builder::getInstance();
-
- const std::list<EntityWrapperPtr>& aSubs = theConstraint->entities();
- std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
-
- std::shared_ptr<GeomAPI_Pnt2d> aStartPnt = aBuilder->point(*aSIt++);
- std::shared_ptr<GeomAPI_Pnt2d> aEndPnt = aBuilder->point(*aSIt++);
- std::shared_ptr<GeomAPI_XY> aDelta = aEndPnt->xy()->decreased(aStartPnt->xy());
-
- std::list<EntityWrapperPtr>::const_iterator aPrevIt = aSIt++;
- for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt)
- translate(*aPrevIt, *aSIt, aDelta);
-}
myConstraints.erase(aCIter);
}
-// ============================================================================
-// Function: isComplexConstraint
-// Class: SketchSolver_Group
-// Purpose: verifies the constraint is complex, i.e. it needs another constraints to be created before
-// ============================================================================
-bool SketchSolver_Group::isComplexConstraint(FeaturePtr theConstraint)
-{
- return theConstraint->getKind() == SketchPlugin_ConstraintFillet::ID() ||
- theConstraint->getKind() == SketchPlugin_ConstraintMirror::ID() ||
- theConstraint->getKind() == SketchPlugin_ConstraintTangent::ID();
-}
-
// ============================================================================
// Function: setTemporary
// Class: SketchSolver_Group
return mySketch->data() && mySketch->data()->isValid();
}
- /// \brief Verifies the constraint is complex, i.e. it needs another constraints to be created before
- static bool isComplexConstraint(FeaturePtr theConstraint);
-
/** \brief Adds or updates a constraint in the group
* \param[in] theConstraint constraint to be changed
* \return \c true if the constraint added or updated successfully
static void adjustAngle(ConstraintWrapperPtr theConstraint);
/// \brief Update mirror points
static void adjustMirror(ConstraintWrapperPtr theConstraint);
-/// \brief Update positions of rotated features
-static void adjustMultiRotation(ConstraintWrapperPtr theConstraint);
-/// \brief Update positions of translated features
-static void adjustMultiTranslation(ConstraintWrapperPtr theConstraint);
/// \brief Transform points to be symmetric regarding to the mirror line
static void makeMirrorPoints(EntityWrapperPtr theOriginal,
SLVS_C_UNKNOWN, (Slvs_hGroup)theGroupID, aType, (Slvs_hEntity)theSketchID,
theValue, aSlvsEntities[0], aSlvsEntities[1], aSlvsEntities[2], aSlvsEntities[3]);
ConstraintWrapperPtr aResult(new SolveSpaceSolver_ConstraintWrapper(theConstraint, aConstraint));
+ aResult->setGroup(theGroupID);
aResult->setValue(theValue);
aResult->setEntities(aConstrAttrList);
adjustConstraint(aResult);
aConstrAttrList.push_front(thePoint1);
ConstraintWrapperPtr aResult(new SolveSpaceSolver_ConstraintWrapper(theConstraint, aConstraint));
+ aResult->setGroup(theGroupID);
aResult->setValue(theValue);
aResult->setIsFullValue(theFullValue);
aResult->setEntities(aConstrAttrList);
ConstraintWrapperPtr aWrapper(new SolveSpaceSolver_ConstraintWrapper(
theConstraint, aConstraint));
+ aWrapper->setGroup(theGroupID);
aWrapper->setEntities(aConstrAttrList);
aResult.push_back(aWrapper);
}
adjustAngle(theConstraint);
else if (aType == CONSTRAINT_SYMMETRIC)
adjustMirror(theConstraint);
- else if (aType == CONSTRAINT_MULTI_ROTATION)
- adjustMultiRotation(theConstraint);
- else if (aType == CONSTRAINT_MULTI_TRANSLATION)
- adjustMultiTranslation(theConstraint);
}
EntityWrapperPtr SolveSpaceSolver_Builder::createFeature(
aMirroredPnt->setValue(aCoord[0], aCoord[1]);
}
}
-
-static void rotate(EntityWrapperPtr theSource, EntityWrapperPtr theDest,
- std::shared_ptr<GeomAPI_Pnt2d> theCenter,
- double theSin, double theCos)
-{
- std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSource =
- std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theSource);
- std::shared_ptr<SolveSpaceSolver_EntityWrapper> aDest =
- std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theDest);
-
- if (theSource->type() == ENTITY_POINT) {
- // Rotate single point
- std::shared_ptr<GeomDataAPI_Point2D> aSrcAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSource->baseAttribute());
- std::shared_ptr<GeomDataAPI_Point2D> aDstAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aDest->baseAttribute());
- if (aSrcAttr && aDstAttr) {
- std::shared_ptr<GeomAPI_XY> aVec = aSrcAttr->pnt()->xy()->decreased(theCenter->xy());
- double aNewX = aVec->x() * theCos - aVec->y() * theSin;
- double aNewY = aVec->x() * theSin + aVec->y() * theCos;
- aDstAttr->setValue(theCenter->x() + aNewX, theCenter->y() + aNewY);
- }
- return;
- }
-
- FeaturePtr aDestFeature = aDest->baseFeature();
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(true);
-
- // Rotate points of the feature
- const std::list<EntityWrapperPtr>& aSrcSubs = theSource->subEntities();
- const std::list<EntityWrapperPtr>& aDstSubs = theDest->subEntities();
- std::list<EntityWrapperPtr>::const_iterator aSrcIt, aDstIt;
- for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin();
- aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt)
- rotate(*aSrcIt, *aDstIt, theCenter, theSin, theCos);
-
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(false);
-}
-
-static void translate(EntityWrapperPtr theSource, EntityWrapperPtr theDest,
- std::shared_ptr<GeomAPI_XY> theDelta)
-{
- std::shared_ptr<SolveSpaceSolver_EntityWrapper> aSource =
- std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theSource);
- std::shared_ptr<SolveSpaceSolver_EntityWrapper> aDest =
- std::dynamic_pointer_cast<SolveSpaceSolver_EntityWrapper>(theDest);
-
- if (theSource->type() == ENTITY_POINT) {
- // Translate single point
- std::shared_ptr<GeomDataAPI_Point2D> aSrcAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aSource->baseAttribute());
- std::shared_ptr<GeomDataAPI_Point2D> aDstAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aDest->baseAttribute());
- if (aSrcAttr && aDstAttr)
- aDstAttr->setValue(aSrcAttr->x() + theDelta->x(), aSrcAttr->y() + theDelta->y());
- return;
- }
-
- FeaturePtr aDestFeature = aDest->baseFeature();
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(true);
-
- // Translate points of the feature
- const std::list<EntityWrapperPtr>& aSrcSubs = theSource->subEntities();
- const std::list<EntityWrapperPtr>& aDstSubs = theDest->subEntities();
- std::list<EntityWrapperPtr>::const_iterator aSrcIt, aDstIt;
- for (aSrcIt = aSrcSubs.begin(), aDstIt = aDstSubs.begin();
- aSrcIt != aSrcSubs.end() && aDstIt != aDstSubs.end(); ++aSrcIt, ++aDstIt)
- translate(*aSrcIt, *aDstIt, theDelta);
-
- if (aDestFeature)
- aDestFeature->data()->blockSendAttributeUpdated(false);
-}
-
-void adjustMultiRotation(ConstraintWrapperPtr theConstraint)
-{
- BuilderPtr aBuilder = SolveSpaceSolver_Builder::getInstance();
-
- double anAngleValue = theConstraint->value();
- const std::list<EntityWrapperPtr>& aSubs = theConstraint->entities();
-
- bool isFullValue = theConstraint->isFullValue();
- int aNbObjects = aSubs.size()-2;
- if (isFullValue && aNbObjects > 0) {
- anAngleValue /= aNbObjects;
- }
-
- double anAngleRad = anAngleValue * PI / 180.0;
- double aSin = sin(anAngleRad);
- double aCos = cos(anAngleRad);
-
- std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
-
- std::shared_ptr<GeomAPI_Pnt2d> aCenter = aBuilder->point(*aSIt++);
- std::list<EntityWrapperPtr>::const_iterator aPrevIt = aSIt++;
- for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt)
- rotate(*aPrevIt, *aSIt, aCenter, aSin, aCos);
-}
-
-void adjustMultiTranslation(ConstraintWrapperPtr theConstraint)
-{
- BuilderPtr aBuilder = SolveSpaceSolver_Builder::getInstance();
-
- const std::list<EntityWrapperPtr>& aSubs = theConstraint->entities();
- std::list<EntityWrapperPtr>::const_iterator aSIt = aSubs.begin();
-
- std::shared_ptr<GeomAPI_Pnt2d> aStartPnt = aBuilder->point(*aSIt++);
- std::shared_ptr<GeomAPI_Pnt2d> aEndPnt = aBuilder->point(*aSIt++);
- std::shared_ptr<GeomAPI_XY> aDelta = aEndPnt->xy()->decreased(aStartPnt->xy());
-
- bool isFullValue = theConstraint->isFullValue();
- int aNbObjects = aSubs.size()-3;
- if (isFullValue && aNbObjects > 0) {
- aDelta->setX(aDelta->x()/aNbObjects);
- aDelta->setY(aDelta->y()/aNbObjects);
- }
-
- std::list<EntityWrapperPtr>::const_iterator aPrevIt = aSIt++;
- for (; aSIt != aSubs.end(); ++aPrevIt, ++aSIt)
- translate(*aPrevIt, *aSIt, aDelta);
-}
return aResult;
}
-void SolveSpaceSolver_Storage::removeUnusedEntities()
-{
- std::set<Slvs_hEntity> anUnusedEntities;
- std::vector<Slvs_Entity>::const_iterator aEIt = myEntities.begin();
- for (; aEIt != myEntities.end(); ++aEIt) {
- if (aEIt->h == aEIt->wrkpl) {
- // don't remove workplane
- anUnusedEntities.erase(aEIt->point[0]);
- anUnusedEntities.erase(aEIt->normal);
- continue;
- }
- anUnusedEntities.insert(aEIt->h);
- }
-
- std::vector<Slvs_Constraint>::const_iterator aCIt = myConstraints.begin();
- for (; aCIt != myConstraints.end(); ++aCIt) {
- Slvs_hEntity aSubs[6] = {
- aCIt->entityA, aCIt->entityB,
- aCIt->entityC, aCIt->entityD,
- aCIt->ptA, aCIt->ptB};
- for (int i = 0; i < 6; i++) {
- if (aSubs[i] != SLVS_E_UNKNOWN) {
- anUnusedEntities.erase(aSubs[i]);
- int aPos = Search(aSubs[i], myEntities);
- if (aPos >= 0 && aPos < (int)myEntities.size()) {
- for (int j = 0; j < 4; j++)
- if (myEntities[aPos].point[j] != SLVS_E_UNKNOWN)
- anUnusedEntities.erase(myEntities[aPos].point[j]);
- if (myEntities[aPos].distance != SLVS_E_UNKNOWN)
- anUnusedEntities.erase(myEntities[aPos].distance);
- }
- }
- }
- }
-
- std::set<Slvs_hEntity>::const_iterator anEntIt = anUnusedEntities.begin();
- while (anEntIt != anUnusedEntities.end()) {
- int aPos = Search(*anEntIt, myEntities);
- if (aPos < 0 && aPos >= (int)myEntities.size())
- continue;
- Slvs_Entity anEntity = myEntities[aPos];
- // Remove entity if and only if all its parameters unused
- bool isUsed = false;
- if (anEntity.distance != SLVS_E_UNKNOWN &&
- anUnusedEntities.find(anEntity.distance) == anUnusedEntities.end())
- isUsed = true;
- for (int i = 0; i < 4 && !isUsed; i++)
- if (anEntity.point[i] != SLVS_E_UNKNOWN &&
- anUnusedEntities.find(anEntity.point[i]) == anUnusedEntities.end())
- isUsed = true;
- if (isUsed) {
- anUnusedEntities.erase(anEntity.distance);
- for (int i = 0; i < 4; i++)
- if (anEntity.point[i] != SLVS_E_UNKNOWN)
- anUnusedEntities.erase(anEntity.point[i]);
- std::set<Slvs_hEntity>::iterator aRemoveIt = anEntIt++;
- anUnusedEntities.erase(aRemoveIt);
- continue;
- }
- ++anEntIt;
- }
-
- for (anEntIt = anUnusedEntities.begin(); anEntIt != anUnusedEntities.end(); ++anEntIt) {
- int aPos = Search(*anEntIt, myEntities);
- if (aPos >= 0 && aPos < (int)myEntities.size()) {
- // Remove entity and its parameters
- Slvs_Entity anEntity = myEntities[aPos];
- myEntities.erase(myEntities.begin() + aPos);
- myEntityMaxID = myEntities.empty() ? SLVS_E_UNKNOWN : myEntities.back().h;
- if (anEntity.distance != SLVS_E_UNKNOWN)
- removeParameter(anEntity.distance);
- for (int i = 0; i < 4; i++)
- if (anEntity.param[i] != SLVS_E_UNKNOWN)
- removeParameter(anEntity.param[i]);
- for (int i = 0; i < 4; i++)
- if (anEntity.point[i] != SLVS_E_UNKNOWN)
- removeEntity(anEntity.point[i]);
- }
- }
-
- if (!anUnusedEntities.empty())
- myNeedToResolve = true;
-}
-
-bool SolveSpaceSolver_Storage::isUsedByConstraints(const Slvs_hEntity& theEntityID) const
-{
- std::vector<Slvs_Constraint>::const_iterator aCIt = myConstraints.begin();
- for (; aCIt != myConstraints.end(); ++aCIt) {
- Slvs_hEntity aSubs[6] = {
- aCIt->entityA, aCIt->entityB,
- aCIt->entityC, aCIt->entityD,
- aCIt->ptA, aCIt->ptB};
- for (int i = 0; i < 6; i++)
- if (aSubs[i] != SLVS_E_UNKNOWN && aSubs[i] == theEntityID)
- return true;
- }
- return false;
-}
-
const Slvs_Entity& SolveSpaceSolver_Storage::getEntity(const Slvs_hEntity& theEntityID) const
{
int aPos = Search(theEntityID, myEntities);
return aDummy;
}
-Slvs_hEntity SolveSpaceSolver_Storage::copyEntity(const Slvs_hEntity& theCopied)
-{
- int aPos = Search(theCopied, myEntities);
- if (aPos < 0 || aPos >= (int)myEntities.size())
- return SLVS_E_UNKNOWN;
-
- Slvs_Entity aCopy = myEntities[aPos];
- aCopy.h = SLVS_E_UNKNOWN;
- int i = 0;
- while (aCopy.point[i] != SLVS_E_UNKNOWN) {
- aCopy.point[i] = copyEntity(aCopy.point[i]);
- i++;
- }
- if (aCopy.param[0] != SLVS_E_UNKNOWN) {
- aPos = Search(aCopy.param[0], myParameters);
- i = 0;
- while (aCopy.param[i] != SLVS_E_UNKNOWN) {
- Slvs_Param aNewParam = myParameters[aPos];
- aNewParam.h = SLVS_E_UNKNOWN;
- aCopy.param[i] = addParameter(aNewParam);
- i++;
- aPos++;
- }
- }
- return addEntity(aCopy);
-}
-
-void SolveSpaceSolver_Storage::copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo)
-{
- int aPosFrom = Search(theFrom, myEntities);
- int aPosTo = Search(theTo, myEntities);
- if (aPosFrom < 0 || aPosFrom >= (int)myEntities.size() ||
- aPosTo < 0 || aPosTo >= (int)myEntities.size())
- return;
-
- Slvs_Entity aEntFrom = myEntities[aPosFrom];
- Slvs_Entity aEntTo = myEntities[aPosTo];
- int i = 0;
- while (aEntFrom.point[i] != SLVS_E_UNKNOWN) {
- copyEntity(aEntFrom.point[i], aEntTo.point[i]);
- i++;
- }
- if (aEntFrom.param[0] != SLVS_E_UNKNOWN) {
- aPosFrom = Search(aEntFrom.param[0], myParameters);
- aPosTo = Search(aEntTo.param[0], myParameters);
- i = 0;
- while (aEntFrom.param[i] != SLVS_E_UNKNOWN) {
- myParameters[aPosTo++].val = myParameters[aPosFrom++].val;
- i++;
- }
- }
-}
-
Slvs_hConstraint SolveSpaceSolver_Storage::addConstraint(const Slvs_Constraint& theConstraint)
{
* \return \c true if the entity was successfully removed
*/
bool removeEntity(const Slvs_hEntity& theEntityID);
- /** \brief Remove all entities, which are not used in constraints
- */
- void removeUnusedEntities();
/// \brief Returns the entity by its ID
const Slvs_Entity& getEntity(const Slvs_hEntity& theEntityID) const;
- /// \brief Makes a full copy of the given entity
- Slvs_hEntity copyEntity(const Slvs_hEntity& theCopied);
- /// \brief Copy one entity to another
- void copyEntity(const Slvs_hEntity& theFrom, const Slvs_hEntity& theTo);
- /// \brief Check the entity is used in constraints
- bool isUsedByConstraints(const Slvs_hEntity& theEntityID) const;
/// \brief Returns maximal ID of entities in this storage
const Slvs_hEntity& entityMaxID() const
{ return myEntityMaxID; }