From: azv Date: Thu, 24 Dec 2015 06:44:49 +0000 (+0300) Subject: Code cleanup X-Git-Tag: V_2.1.0~76 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=719b770fde138197ba898273892044ae35541365;p=modules%2Fshaper.git Code cleanup --- diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp index 7d9911b91..2267b067c 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.cpp @@ -443,8 +443,8 @@ void PlaneGCSSolver_Builder::adjustConstraint(ConstraintWrapperPtr theConstraint // Update flags and parameters in constraints if (aType == CONSTRAINT_ANGLE) adjustAngle(theConstraint); -//// else if (aType == CONSTRAINT_SYMMETRIC) -//// adjustMirror(theConstraint); + //else if (aType == CONSTRAINT_SYMMETRIC) + // adjustMirror(theConstraint); else if (aType == CONSTRAINT_MULTI_ROTATION) adjustMultiRotation(theConstraint); else if (aType == CONSTRAINT_MULTI_TRANSLATION) @@ -582,41 +582,6 @@ EntityWrapperPtr PlaneGCSSolver_Builder::createSketchEntity( -////EntityWrapperPtr PlaneGCSSolver_Builder::createNormal( -//// AttributePtr theNormal, -//// AttributePtr theDirX, -//// const GroupID& theGroupID) const -////{ -//// std::shared_ptr aNorm = std::dynamic_pointer_cast(theNormal); -//// std::shared_ptr aDirX = std::dynamic_pointer_cast(theDirX); -//// if (!aDirX || !aNorm || -//// (fabs(aDirX->x()) + fabs(aDirX->y()) + fabs(aDirX->z()) < tolerance) || -//// !aNorm->isInitialized()) -//// return EntityWrapperPtr(); -//// // calculate Y direction -//// std::shared_ptr aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aDirX->dir()))); -//// -//// // quaternion parameters of normal vector -//// double qw, qx, qy, qz; -//// Slvs_MakeQuaternion(aDirX->x(), aDirX->y(), aDirX->z(), aDirY->x(), aDirY->y(), aDirY->z(), &qw, -//// &qx, &qy, &qz); -//// double aNormCoord[4] = { qw, qx, qy, qz }; -//// -//// // Create parameters of the normal -//// std::list aParameters; -//// for (int i = 0; i < 4; i++) -//// aParameters.push_back(createParameter(theGroupID, aNormCoord[i])); -//// -//// // Create a normal with empty parameters -//// Slvs_Entity aNormalEnt = Slvs_MakeNormal3d(SLVS_E_UNKNOWN, (Slvs_hGroup)theGroupID, -//// SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); -//// EntityWrapperPtr aNormal(new SolveSpaceSolver_EntityWrapper(theNormal, aNormalEnt)); -//// aNormal->setParameters(aParameters); -//// return aNormal; -////} - - - // ================ Auxiliary functions ========================== diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h index fe959858b..ae534dafa 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Builder.h @@ -125,15 +125,6 @@ private: EntityWrapperPtr createSketchEntity(CompositeFeaturePtr theSketch, const GroupID& theGroupID) const; -//// /// \brief Converts two axes of sketch's trihedron to the normal entity -//// /// \param theNormal [in] direction of the normal of the sketch -//// /// \param theDirX [in] direction of the X axis of the sketch -//// /// \param theGroupID [in] group, the normal belongs to -//// /// \return Created entity or empty pointer, if there are incorrect attributes -//// EntityWrapperPtr createNormal(AttributePtr theNormal, -//// AttributePtr theDirX, -//// const GroupID& theGroupID) const; - private: static BuilderPtr mySelf; }; diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.cpp index db932e8b0..75242febf 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.cpp @@ -75,22 +75,6 @@ bool PlaneGCSSolver_ConstraintWrapper::isEqual(const ConstraintWrapperPtr& theOt { if (type() != theOther->type()) return false; -//// const Slvs_Constraint anOtherConstraint = -//// std::dynamic_pointer_cast(theOther)->constraint(); -//// if (mySlvsConstraint.type != anOtherConstraint.type) -//// return false; -//// -//// // Verify SolveSpace entities. If they are equal, no need additional checking of parameters. -//// if (mySlvsConstraint.group == anOtherConstraint.group && -//// mySlvsConstraint.ptA == anOtherConstraint.ptA && -//// mySlvsConstraint.ptB == anOtherConstraint.ptB && -//// mySlvsConstraint.entityA == anOtherConstraint.entityA && -//// mySlvsConstraint.entityB == anOtherConstraint.entityB && -//// mySlvsConstraint.entityC == anOtherConstraint.entityC && -//// mySlvsConstraint.entityD == anOtherConstraint.entityD && -//// fabs(mySlvsConstraint.valA - anOtherConstraint.valA) < tolerance) { -//// return true; -//// } // Verify equality of values if (fabs(myValue - theOther->value()) > tolerance) diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.h index 74341b589..12466118f 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_ConstraintWrapper.h @@ -28,9 +28,6 @@ public: /// \brief Return list of constraints const std::list& constraints() const { return myGCSConstraints; } -//// /// \brief Return SolveSpace constraint to change -//// GCSConstraintPtr& changeConstraint() -//// { return myGCSConstraint; } /// \brief Return ID of current entity virtual ConstraintID id() const diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp index 2d95d783d..e66fd13b0 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.cpp @@ -49,7 +49,7 @@ SketchSolver_SolveStatus PlaneGCSSolver_Solver::solve() if (myParameters.empty()) return STATUS_INCONSISTENT; -//// myEquationSystem.calculateFaileds = myFindFaileds ? 1 : 0; + //myEquationSystem.calculateFaileds = myFindFaileds ? 1 : 0; Events_LongOp::start(this); GCS::SolveStatus aResult = (GCS::SolveStatus)myEquationSystem.solve(myParameters); diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h index ea31e1443..791cc648a 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Solver.h @@ -10,17 +10,8 @@ #include #include -////// Need to be defined before including SolveSpace to avoid additional dependences on Windows platform -////#if defined(WIN32) && !defined(HAVE_C99_INTEGER_TYPES) -////typedef unsigned int UINT32; -////#else -////#include -////#endif -////#include #include -////#include - /** * The main class that performs the high-level operations for connection to the PlaneGCS. */ diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp index 5d40a3c2c..8cd461a23 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.cpp @@ -18,38 +18,10 @@ #include #include #include -////#include -////#include -////#include - #include -////#include -////#include -////#include -//// -////#ifndef OBSOLETE -////#include -////#endif #include -////#ifdef OBSOLETE -/////** \brief Search the entity/parameter with specified ID in the list of elements -//// * \param[in] theEntityID unique ID of the element -//// * \param[in] theEntities list of elements -//// * \return position of the found element or -1 if the element is not found -//// */ -////template -////static int Search(const uint32_t& theEntityID, const std::vector& theEntities); -//// -/////// \brief Compare two parameters to be different -////static bool IsNotEqual(const Slvs_Param& theParam1, const Slvs_Param& theParam2); -/////// \brief Compare two entities to be different -////static bool IsNotEqual(const Slvs_Entity& theEntity1, const Slvs_Entity& theEntity2); -/////// \brief Compare two constriants to be different -////static bool IsNotEqual(const Slvs_Constraint& theConstraint1, const Slvs_Constraint& theConstraint2); -////#endif - PlaneGCSSolver_Storage::PlaneGCSSolver_Storage(const GroupID& theGroup) : SketchSolver_Storage(theGroup), @@ -331,538 +303,14 @@ void PlaneGCSSolver_Storage::changeGroup(EntityWrapperPtr theEntity, const Group void PlaneGCSSolver_Storage::changeGroup(ParameterWrapperPtr theParam, const GroupID& theGroup) { -//// // TODO + // TODO } void PlaneGCSSolver_Storage::verifyFixed() { -//// // TODO + // TODO } - -#ifndef OBSOLETE -//// -////void PlaneGCSSolver_Storage::changeConstraint( -//// const ConstraintPtr& theConstraint, -//// const std::vector& theGCSConstraints) -////{ -//// myConstraintsMap[theConstraint] = theGCSConstraints; -////} - -////void PlaneGCSSolver_Storage::addConstraint(GCSConstraintPtr theConstraint) -////{ -//// std::map >::iterator -//// aFound = myConstraintsMap.find(ConstraintPtr()); -//// if (aFound != myConstraintsMap.end()) -//// aFound->second.push_back(theConstraint); -//// else { -//// std::vector aConstrVec(1, theConstraint); -//// myConstraintsMap[ConstraintPtr()] = aConstrVec; -//// } -////} - -////EntityID PlaneGCSSolver_Storage::changeEntity(const FeaturePtr& theEntity) -////{ -//// if (!theEntity || !theEntity->data() || !theEntity->data()->isValid()) -//// return ENTITY_UNKNOWN; -//// -//// // Firstly, try to find entity -//// std::map::const_iterator aFound = myFeatureEntityMap.find(theEntity); -//// -//// EntityID aNewEntID; -//// if (aFound != myFeatureEntityMap.end()) -//// aNewEntID = aFound->second; -//// -//// const std::string& aFeatureKind = theEntity->getKind(); -//// // SketchPlugin features -//// if (aFeatureKind == SketchPlugin_Line::ID()) -//// updateLine(theEntity, aNewEntID); -//// // Circle -//// else if (aFeatureKind == SketchPlugin_Circle::ID()) -//// updateCircle(theEntity, aNewEntID); -//// // Arc -//// else if (aFeatureKind == SketchPlugin_Arc::ID()) -//// updateArc(theEntity, aNewEntID); -//// // Point (it has low probability to be an attribute of constraint, so it is checked at the end) -//// else if (aFeatureKind == SketchPlugin_Point::ID()) { -//// AttributePtr anAttribute = theEntity->attribute(SketchPlugin_Point::COORD_ID()); -//// if (!anAttribute->isInitialized()) -//// return ENTITY_UNKNOWN; -//// // Both the sketch point and its attribute (coordinates) link to the same SolveSpace point identifier -//// aNewEntID = changeEntity(anAttribute); -//// } -//// else // NOTE: Other types of entities are unsupported -//// aNewEntID = ENTITY_UNKNOWN; -//// -//// if (aNewEntID != ENTITY_UNKNOWN) -//// myFeatureEntityMap[theEntity] = aNewEntID; -//// return aNewEntID; -////} -//// -////EntityID PlaneGCSSolver_Storage::changeEntity(const AttributePtr& theEntity) -////{ -//// if (!theEntity) -//// return ENTITY_UNKNOWN; -//// -//// AttributeRefAttrPtr aRefAttr = -//// std::dynamic_pointer_cast(theEntity); -//// if (aRefAttr) { -//// if (aRefAttr->isObject()) { -//// ResultConstructionPtr aRC = -//// std::dynamic_pointer_cast(aRefAttr->object()); -//// if (!aRC) -//// return ENTITY_UNKNOWN; -//// return changeEntity(ModelAPI_Feature::feature(aRC)); -//// } -//// else -//// return changeEntity(aRefAttr->attr()); -//// } -//// -//// EntityID aNewEntID = ENTITY_UNKNOWN; -//// -//// // Firstly, try to find entity -//// std::map::const_iterator aFound = myAttributeEntityMap.find(theEntity); -//// // Check type of attribute and create corresponding entity -//// std::shared_ptr aPoint2D = -//// std::dynamic_pointer_cast(theEntity); -//// if (aPoint2D) { -//// if (aFound != myAttributeEntityMap.end()) -//// aNewEntID = aFound->second; -//// updatePoint(aPoint2D, aNewEntID); -//// } else { -//// AttributeDoublePtr aScalar = std::dynamic_pointer_cast(theEntity); -//// if (aScalar) { -//// // Check the scalar represents an angular value -//// bool isAngular = false; -//// FeaturePtr anOwner = ModelAPI_Feature::feature(aScalar->owner()); -//// if (anOwner && anOwner->getKind() == SketchPlugin_ConstraintAngle::ID()) -//// isAngular = true; -//// -//// if (aFound != myAttributeEntityMap.end()) -//// aNewEntID = aFound->second; -//// if (isAngular) -//// updateAngle(aScalar, aNewEntID); -//// else -//// updateScalar(aScalar, aNewEntID); -//// } -//// } -//// // NOTE: Other types of attributes are not supported -//// -//// // Map attribute and new entity ID -//// if (aFound == myAttributeEntityMap.end() && aNewEntID != ENTITY_UNKNOWN) -//// myAttributeEntityMap[theEntity] = aNewEntID; -//// return aNewEntID; -////} - - -////bool PlaneGCSSolver_Storage::removeConstraint(const ConstraintPtr& theConstraint) -////{ -//// std::map >::iterator -//// aFound = myConstraintsMap.find(theConstraint); -//// if (aFound == myConstraintsMap.end()) -//// return true; // no constraint - nothing to remove -//// -//// std::vector aConstrList = aFound->second; -//// myConstraintsMap.erase(aFound); -//// bool isFullyRemoved = removeEntity(theConstraint->attribute(SketchPlugin_Constraint::VALUE())); -//// for (int ind = 0; ind < CONSTRAINT_ATTR_SIZE; ++ind) -//// isFullyRemoved = removeEntity(theConstraint->attribute(SketchPlugin_Constraint::ATTRIBUTE(ind))) -//// && isFullyRemoved; -//// -//// myRemovedConstraints.insert(myRemovedConstraints.end(), aConstrList.begin(), aConstrList.end()); -//// -//// return isFullyRemoved; -////} - -////bool PlaneGCSSolver_Storage::removeConstraint(GCSConstraintPtr theConstraint) -////{ -//// std::map >::iterator -//// aFound = myConstraintsMap.find(ConstraintPtr()); -//// if (aFound != myConstraintsMap.end()) { -//// std::vector::iterator anIt = aFound->second.begin(); -//// for (; anIt != aFound->second.end(); ++anIt) -//// if (*anIt == theConstraint) { -//// aFound->second.erase(anIt); -//// break; -//// } -//// } -//// -//// myRemovedConstraints.push_back(theConstraint); -//// return true; -////} -//// -////bool PlaneGCSSolver_Storage::removeEntity(const FeaturePtr& theFeature) -////{ -//// if (!theFeature) -//// return true; -//// if (isUsed(theFeature)) -//// return false; -//// -//// // remove feature and corresponding entity -//// std::map::iterator aFound = myFeatureEntityMap.find(theFeature); -//// if (aFound != myFeatureEntityMap.end()) { -//// if (aFound->second.type == ARC) { -//// // remove additional arc constraints -//// std::map >::iterator aFoundArc = -//// myArcConstraintMap.find(aFound->second); -//// if (aFoundArc != myArcConstraintMap.end()) { -//// myRemovedConstraints.insert(myRemovedConstraints.end(), -//// aFoundArc->second.begin(), aFoundArc->second.end()); -//// myArcConstraintMap.erase(aFoundArc); -//// } -//// } -//// myGCSEntities.erase(aFound->second); -//// myFeatureEntityMap.erase(aFound); -//// } -//// -//// // remove feature's attributes -//// bool isFullyRemoved = true; -//// std::list anAttributes = theFeature->data()->attributes(std::string()); -//// std::list::iterator anAttrIt = anAttributes.begin(); -//// for (; anAttrIt != anAttributes.end(); ++anAttrIt) -//// isFullyRemoved = removeEntity(*anAttrIt) && isFullyRemoved; -//// return isFullyRemoved; -////} -//// -////bool PlaneGCSSolver_Storage::removeEntity(const AttributePtr& theAttribute) -////{ -//// if (!theAttribute) -//// return true; -//// if (isUsed(theAttribute)) -//// return false; -//// -//// AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); -//// if (aRefAttr) { -//// if (aRefAttr->isObject()) { -//// FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); -//// return removeEntity(aFeature); -//// } else -//// return removeEntity(aRefAttr->attr()); -//// } -//// -//// // remove attribute and corresponding entity -//// std::map::iterator aFound = myAttributeEntityMap.find(theAttribute); -//// if (aFound == myAttributeEntityMap.end()) -//// return true; // no attribute, nothing to remove -//// -//// if (aFound->second.type == SCALAR || aFound->second.type == ANGLE) { -//// std::map::iterator aFoundScalar = myGCSScalars.find(aFound->second); -//// if (aFoundScalar != myGCSScalars.end()) { -//// removeParameters(aFoundScalar->second); -//// myGCSScalars.erase(aFoundScalar); -//// } -//// } -//// else if (aFound->second.type == POINT) { -//// std::map::iterator aFoundPoint = myGCSPoints.find(aFound->second); -//// if (aFoundPoint != myGCSPoints.end()) { -//// removeParameters(aFoundPoint->second->x, aFoundPoint->second->y); -//// myGCSPoints.erase(aFoundPoint); -//// } -//// } -//// -//// myAttributeEntityMap.erase(aFound); -//// return true; -////} - -////void PlaneGCSSolver_Storage::removeParameters(double* theParam1, double* theParam2) -////{ -//// int aNbRemoved = 2; -//// for (int ind = 0; ind < 2 && aNbRemoved > 0; ++ind) { -//// GCS::VEC_pD& aList = ind ==0 ? myParameters : myConst; -//// -//// GCS::VEC_pD::iterator aParIt = aList.begin(); -//// while (aNbRemoved > 0 && aParIt != aList.end()) { -//// if (*aParIt != theParam1 && *aParIt != theParam2) { -//// ++aParIt; -//// continue; -//// } -//// -//// myRemovedParameters.push_back(*aParIt); -//// int aShift = aParIt - aList.begin(); -//// aList.erase(aParIt); -//// aParIt = aList.begin() + aShift; -//// --aNbRemoved; -//// } -//// } -////} - - -////double* PlaneGCSSolver_Storage::createScalar(const AttributeDoublePtr& theScalar) -////{ -//// double* aResult = new double; -//// if (theScalar) -//// *aResult = theScalar->value(); -//// myParameters.push_back(aResult); -//// myNeedToResolve = true; -//// return aResult; -////} -//// -////void PlaneGCSSolver_Storage::updateScalar(const AttributeDoublePtr& theScalar, EntityID& theID) -////{ -//// std::map::const_iterator aFound = myGCSScalars.find(theID); -//// if (aFound == myGCSScalars.end()) { -//// // new scalar -//// theID = ++myEntityLastID; -//// theID.type = SCALAR; -//// myGCSScalars[theID] = createScalar(theScalar); -//// } -//// else if (fabs(*(myGCSScalars[theID]) - theScalar->value()) > tolerance) { -//// *(myGCSScalars[theID]) = theScalar->value(); -//// myNeedToResolve = true; -//// } -////} -//// -////void PlaneGCSSolver_Storage::updateAngle(const AttributeDoublePtr& theAngle, EntityID& theID) -////{ -//// std::map::const_iterator aFound = myGCSScalars.find(theID); -//// if (aFound == myGCSScalars.end()) { -//// // new scalar -//// theID = ++myEntityLastID; -//// theID.type = ANGLE; -//// myGCSScalars[theID] = createScalar(theAngle); -//// } -//// else if (fabs(*(myGCSScalars[theID]) - theAngle->value()) > tolerance) { -//// *(myGCSScalars[theID]) = theAngle->value(); -//// myNeedToResolve = true; -//// } -//// // Convert degrees to radians -//// *(myGCSScalars[theID]) *= M_PI / 180.0; -////} -//// -////GCS::Point PlaneGCSSolver_Storage::createPoint(const std::shared_ptr& thePoint) -////{ -//// GCS::Point aResult; -//// aResult.x = new double(thePoint->x()); -//// aResult.y = new double(thePoint->y()); -//// -//// myParameters.push_back(aResult.x); -//// myParameters.push_back(aResult.y); -//// -//// myNeedToResolve = true; -//// return aResult; -////} -//// -////void PlaneGCSSolver_Storage::updatePoint(const std::shared_ptr& thePoint, -//// EntityID& theID) -////{ -//// std::map::iterator aFound = myGCSPoints.find(theID); -//// if (aFound == myGCSPoints.end()) { -//// // new point -//// theID = ++myEntityLastID; -//// theID.type = POINT; -//// myGCSPoints[theID] = GCSPointPtr(new GCS::Point(createPoint(thePoint))); -//// } -//// else if (fabs(*(aFound->second->x) - thePoint->x()) > tolerance || -//// fabs(*(aFound->second->y) - thePoint->y()) > tolerance) { -//// // update point -//// *(aFound->second->x) = thePoint->x(); -//// *(aFound->second->y) = thePoint->y(); -//// myNeedToResolve = true; -//// } -////} -//// -////void PlaneGCSSolver_Storage::updateLine(const FeaturePtr& theLine, EntityID& theID) -////{ -//// std::shared_ptr aStartAttr = -//// std::dynamic_pointer_cast( -//// theLine->attribute(SketchPlugin_Line::START_ID())); -//// std::shared_ptr aEndAttr = -//// std::dynamic_pointer_cast( -//// theLine->attribute(SketchPlugin_Line::END_ID())); -//// if (!aStartAttr->isInitialized() || !aEndAttr->isInitialized()) { -//// theID = ENTITY_UNKNOWN; -//// return; -//// } -//// -//// std::map::iterator aFound = myGCSEntities.find(theID); -//// if (aFound == myGCSEntities.end()) { -//////// // new line -//////// theID = ++myEntityLastID; -//////// theID.type = LINE; -//////// -//////// EntityID aStartID = changeEntity(aStartAttr); -//////// EntityID aEndID = changeEntity(aEndAttr); -//////// GCS::Point* aStart = getPoint(aStartID); -//////// GCS::Point* aEnd = getPoint(aEndID); -//////// -//////// std::shared_ptr aLine(new GCS::Line); -//////// aLine->p1 = *aStart; -//////// aLine->p2 = *aEnd; -//////// myGCSEntities[theID] = aLine; -//// } -//// else { -//// // update line parameters -//// std::map::iterator aFoundAttr = myAttributeEntityMap.find(aStartAttr); -//// if (aFoundAttr != myAttributeEntityMap.end()) -//// updatePoint(aStartAttr, aFoundAttr->second); -//// aFoundAttr = myAttributeEntityMap.find(aEndAttr); -//// if (aFoundAttr != myAttributeEntityMap.end()) -//// updatePoint(aEndAttr, aFoundAttr->second); -//// } -////} -//// -////void PlaneGCSSolver_Storage::updateCircle(const FeaturePtr& theCircle, EntityID& theID) -////{ -//// std::shared_ptr aCenterAttr = -//// std::dynamic_pointer_cast( -//// theCircle->attribute(SketchPlugin_Circle::CENTER_ID())); -//// AttributeDoublePtr aRadiusAttr = std::dynamic_pointer_cast( -//// theCircle->attribute(SketchPlugin_Circle::RADIUS_ID())); -//// if (!aCenterAttr->isInitialized() || !aRadiusAttr->isInitialized()) { -//// theID = ENTITY_UNKNOWN; -//// return; -//// } -//// -//// std::map::iterator aFound = myGCSEntities.find(theID); -//// if (aFound == myGCSEntities.end()) { -//////// // new circle -//////// theID = ++myEntityLastID; -//////// theID.type = CIRCLE; -//////// -//////// EntityID aCenterID = changeEntity(aCenterAttr); -//////// EntityID aRadiusID = changeEntity(aRadiusAttr); -//////// GCS::Point* aCenter = getPoint(aCenterID); -//////// double* aRadius = getScalar(aRadiusID); -//////// -//////// std::shared_ptr aCircle(new GCS::Circle); -//////// aCircle->center = *aCenter; -//////// aCircle->rad = aRadius; -//////// myGCSEntities[theID] = aCircle; -//// } -//// else { -//// // update circle parameters -//// std::map::iterator aFoundAttr = myAttributeEntityMap.find(aCenterAttr); -//// if (aFoundAttr != myAttributeEntityMap.end()) -//// updatePoint(aCenterAttr, aFoundAttr->second); -//// aFoundAttr = myAttributeEntityMap.find(aRadiusAttr); -//// if (aFoundAttr != myAttributeEntityMap.end()) -//// updateScalar(aRadiusAttr, aFoundAttr->second); -//// } -////} -//// -////void PlaneGCSSolver_Storage::updateArc(const FeaturePtr& theArc, EntityID& theID) -////{ -//// std::shared_ptr aCenterAttr = -//// std::dynamic_pointer_cast( -//// theArc->attribute(SketchPlugin_Arc::CENTER_ID())); -//// std::shared_ptr aStartAttr = -//// std::dynamic_pointer_cast( -//// theArc->attribute(SketchPlugin_Arc::START_ID())); -//// std::shared_ptr aEndAttr = -//// std::dynamic_pointer_cast( -//// theArc->attribute(SketchPlugin_Arc::END_ID())); -//// if (!aCenterAttr->isInitialized() || -//// !aStartAttr->isInitialized() || -//// !aEndAttr->isInitialized()) { -//// theID = ENTITY_UNKNOWN; -//// return; -//// } -//// -//// std::shared_ptr anArc; -//// std::map::iterator aFound = myGCSEntities.find(theID); -//// if (aFound == myGCSEntities.end()) { -//// // new arc -//// theID = ++myEntityLastID; -//// theID.type = ARC; -//// -//// EntityID aCenterID = changeEntity(aCenterAttr); -//// EntityID aStartID = changeEntity(aStartAttr); -//// EntityID aEndID = changeEntity(aEndAttr); -//// GCS::Point* aCenter = getPoint(aCenterID); -//// GCS::Point* aStart = getPoint(aStartID); -//// GCS::Point* aEnd = getPoint(aEndID); -//// -//// anArc = std::shared_ptr(new GCS::Arc); -//// anArc->center = *aCenter; -//// anArc->start = *aStart; -//// anArc->end = *aEnd; -//// anArc->startAngle = createScalar(); -//// anArc->endAngle = createScalar(); -//// anArc->rad = createScalar(); -//// myGCSEntities[theID] = anArc; -//// -//// // Additional constraints for new arc -//// processArc(theID); -//// } -//// else { -//// // update arc parameters -//// anArc = std::dynamic_pointer_cast(aFound->second); -//// std::map::iterator aFoundAttr = myAttributeEntityMap.find(aCenterAttr); -//// if (aFoundAttr != myAttributeEntityMap.end()) -//// updatePoint(aCenterAttr, aFoundAttr->second); -//// aFoundAttr = myAttributeEntityMap.find(aStartAttr); -//// if (aFoundAttr != myAttributeEntityMap.end()) -//// updatePoint(aStartAttr, aFoundAttr->second); -//// aFoundAttr = myAttributeEntityMap.find(aEndAttr); -//// if (aFoundAttr != myAttributeEntityMap.end()) -//// updatePoint(aEndAttr, aFoundAttr->second); -//// } -//// -//// // Calculate additional parameters necessary for FreeGCS -//// std::shared_ptr aCenterPnt = aCenterAttr->pnt(); -//// std::shared_ptr aStartPnt = aStartAttr->pnt(); -//// std::shared_ptr aEndPnt = aEndAttr->pnt(); -//// -//// *(anArc->rad) = aCenterPnt->distance(aStartPnt); -//// std::shared_ptr anArcEdge = -//// std::dynamic_pointer_cast(theArc->lastResult()->shape()); -//// if (!anArcEdge) { -//// theID = ENTITY_UNKNOWN; -//// return; -//// } -//// anArcEdge->getRange(*(anArc->startAngle), *(anArc->endAngle)); -////} - - -////double* PlaneGCSSolver_Storage::getScalar(const EntityID& theID) const -////{ -//// std::map::const_iterator aFound = myGCSScalars.find(theID); -//// if (aFound == myGCSScalars.end()) -//// return 0; -//// return aFound->second; -////} -//// -////GCS::Point* PlaneGCSSolver_Storage::getPoint(const EntityID& theID) const -////{ -//// std::map::const_iterator aFound = myGCSPoints.find(theID); -//// if (aFound == myGCSPoints.end()) -//// return 0; -//// return aFound->second.get(); -////} -//// -////GCS::Line* PlaneGCSSolver_Storage::getLine(const EntityID& theID) const -////{ -//// std::map::const_iterator aFound = myGCSEntities.find(theID); -//// if (aFound == myGCSEntities.end()) -//// return 0; -//// std::shared_ptr aLine = std::dynamic_pointer_cast(aFound->second); -//// if (!aLine) -//// return 0; -//// return aLine.get(); -////} -//// -////GCS::Circle* PlaneGCSSolver_Storage::getCircle(const EntityID& theID) const -////{ -//// std::map::const_iterator aFound = myGCSEntities.find(theID); -//// if (aFound == myGCSEntities.end()) -//// return 0; -//// std::shared_ptr aCircle = std::dynamic_pointer_cast(aFound->second); -//// if (!aCircle) -//// return 0; -//// return aCircle.get(); -////} -//// -////GCS::Arc* PlaneGCSSolver_Storage::getArc(const EntityID& theID) const -////{ -//// std::map::const_iterator aFound = myGCSEntities.find(theID); -//// if (aFound == myGCSEntities.end()) -//// return 0; -//// std::shared_ptr anArc = std::dynamic_pointer_cast(aFound->second); -//// if (!anArc) -//// return 0; -//// return anArc.get(); -////} - void PlaneGCSSolver_Storage::processArc(const EntityWrapperPtr& theArc) { // Calculate additional parameters necessary for PlaneGCS @@ -919,18 +367,6 @@ void PlaneGCSSolver_Storage::processArc(const EntityWrapperPtr& theArc) myArcConstraintMap[theArc] = anArcConstraints; } -////const std::vector& PlaneGCSSolver_Storage::getConstraint( -//// const ConstraintPtr& theConstraint) const -////{ -//// static const std::vector aDummy; -//// -//// std::map >::const_iterator -//// aFound = myConstraintsMap.find(theConstraint); -//// if (aFound == myConstraintsMap.end()) -//// return aDummy; -//// return aFound->second; -////} - void PlaneGCSSolver_Storage::makeConstant(const EntityWrapperPtr& theEntity) { @@ -1013,11 +449,6 @@ void PlaneGCSSolver_Storage::initializeSolver(SolverPtr theSolver) for (; aRemIt != myRemovedConstraints.end(); ++aRemIt) aSolver->removeConstraint(*aRemIt); myRemovedConstraints.clear(); -//// // remove waste parameters -//// std::list::const_iterator aRemParIt = myRemovedParameters.begin(); -//// for (; aRemParIt != myRemovedParameters.end(); ++aRemParIt) -//// delete *aRemParIt; -//// myRemovedParameters.clear(); // initialize unknowns aSolver->setParameters(myParameters); } @@ -1173,113 +604,3 @@ EntityWrapperPtr PlaneGCSSolver_Storage::calculateMiddlePoint( update(aResult); return aResult; } - -////bool PlaneGCSSolver_Storage::isInteract(AttributePtr theAttribute) const -////{ -//// std::map::const_iterator aFound = myAttributeEntityMap.find(theAttribute); -//// if (aFound != myAttributeEntityMap.end()) -//// return true; -//// -//// AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); -//// if (!aRefAttr) -//// return false; -//// if (aRefAttr->isObject()) { -//// FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); -//// if (!aFeature) -//// return false; -//// return isInteract(aFeature); -//// } -//// -//// return isInteract(aRefAttr->attr()); -////} -//// -////bool PlaneGCSSolver_Storage::isInteract(FeaturePtr theFeature) const -////{ -//// if (myFeatureEntityMap.find(theFeature) != myFeatureEntityMap.end()) -//// return true; -//// std::list anAttributes = theFeature->data()->attributes(std::string()); -//// std::list::iterator anIt = anAttributes.begin(); -//// for (; anIt != anAttributes.end(); ++anIt) -//// if (isInteract(*anIt)) -//// return true; -//// return false; -////} - - -////bool PlaneGCSSolver_Storage::isUsed(const FeaturePtr& theFeature) const -////{ -//// // There is checked only the feature itself, not its attributes. -//// // The attributes should be checked separately. -//// -//// std::map >::const_iterator -//// aCIt = myConstraintsMap.begin(); -//// for (; aCIt != myConstraintsMap.end(); ++aCIt) { -//// if (!aCIt->first) -//// continue; -//// for (int ind = 0; ind < CONSTRAINT_ATTR_SIZE; ++ind) { -//// AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast( -//// aCIt->first->attribute(SketchPlugin_Constraint::ATTRIBUTE(ind))); -//// if (aRefAttr && aRefAttr->isObject()) { -//// FeaturePtr aFeat = ModelAPI_Feature::feature(aRefAttr->object()); -//// if (aFeat == theFeature) -//// return true; -//// } -//// } -//// } -//// return false; -////} -//// -////bool PlaneGCSSolver_Storage::isUsed(const AttributePtr& theAttribute) const -////{ -//// // Check whether the attribute is used by constraints -//// std::map >::const_iterator -//// aCIt = myConstraintsMap.begin(); -//// for (; aCIt != myConstraintsMap.end(); ++aCIt) { -//// if (!aCIt->first) -//// continue; -//// if (aCIt->first->attribute(SketchPlugin_Constraint::VALUE()) == theAttribute) -//// return true; -//// for (int ind = 0; ind < CONSTRAINT_ATTR_SIZE; ++ind) { -//// AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast( -//// aCIt->first->attribute(SketchPlugin_Constraint::ATTRIBUTE(ind))); -//// if (!aRefAttr) -//// continue; -//// if (aRefAttr == theAttribute || -//// (!aRefAttr->isObject() && aRefAttr->attr() == theAttribute)) -//// return true; -//// } -//// } -//// -//// // Check whether the attribute is used by features -//// std::map::const_iterator aFIt = myFeatureEntityMap.begin(); -//// for (; aFIt != myFeatureEntityMap.end(); ++aFIt) { -//// std::list anAttrs = -//// aFIt->first->data()->attributes(GeomDataAPI_Point2D::typeId()); -//// std::list::const_iterator anIt = anAttrs.begin(); -//// for (; anIt != anAttrs.end(); ++anIt) -//// if (*anIt == theAttribute) -//// return true; -//// } -//// -//// return false; -////} - - -////void PlaneGCSSolver_Storage::blockEvents(bool isBlocked) -////{ -//// std::map::iterator aFIt = myFeatureEntityMap.begin(); -//// for (; aFIt != myFeatureEntityMap.end(); ++aFIt) -//// if (aFIt->first->data() && aFIt->first->data()->isValid()) -//// aFIt->first->data()->blockSendAttributeUpdated(isBlocked); -//// -//// std::map::iterator anAIt = myAttributeEntityMap.begin(); -//// for (; anAIt != myAttributeEntityMap.end(); ++anAIt) -//// if (anAIt->first->owner() && anAIt->first->owner()->data() && -//// anAIt->first->owner()->data()->isValid()) -//// anAIt->first->owner()->data()->blockSendAttributeUpdated(isBlocked); -////} - - -#else - -#endif diff --git a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h index 5cb437094..e82e1d6e4 100644 --- a/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h +++ b/src/SketchSolver/PlaneGCSSolver/PlaneGCSSolver_Storage.h @@ -13,28 +13,6 @@ #include #include -////#include -////#include -////#include -////#include -////#include -//// -////#include -////#include -//// -////#include -////#include -////#include -////#include - -////#ifndef OBSOLETE -////#include -//// -////typedef std::shared_ptr GCSPointPtr; -////typedef std::shared_ptr GCSCurvePtr; -////typedef GCS::Constraint* GCSConstraintPtr; -////#endif - /** \class PlaneGCSSolver_Storage * \ingroup Plugins * \brief Contains all necessary data in PlaneGCS format to solve a single group of constraints @@ -105,133 +83,12 @@ protected: // ============= Own methods ============= - - -#ifndef OBSOLETE - -//// /** \brief Add or change constraint and corresponding GCS constraints to the storage -//// * \param theConstraint [in] base SketchPlugin constraint -//// * \param theGCSConstraints [in] list of GCS constraints created by SketchSolver constraint -//// */ -//// void changeConstraint(const ConstraintPtr& theConstraint, -//// const std::vector& theGCSConstraints); - -//// /** \brief Add GCS constraint not related to any SketchPlugin constraint. -//// * For example, it may be related to the moved feature. -//// * \param theConstraint [in] GCS constraint -//// */ -//// void addConstraint(GCSConstraintPtr theConstraint); - -//// /** \brief Convert SketchPlugin_Feature to the corresponding entity in FreeGCS -//// * \param theEntity [in] feature to convert -//// * \return ID of created or updated entity -//// */ -//// EntityID changeEntity(const FeaturePtr& theEntity); -//// /** \brief Convert ModelAPI_Attribute to the corresponding entity in FreeGCS -//// * \param theEntity [in] attribute to convert -//// * \return ID of created or updated entity -//// */ -//// EntityID changeEntity(const AttributePtr& theEntity); - -//// /** \brief Remove constraint and corresponding GCS constraints -//// * \param theConstraint [in] constraint to remove -//// * \return \c true, if the constraint is fully removed, -//// * \c false, if there are available entities used by other constraints -//// */ -//// bool removeConstraint(const ConstraintPtr& theConstraint); -//// /** \brief Remove GCS constraint -//// * \param theConstraint [in] constraint to remove -//// * \return \c true, if the constraint is fully removed -//// */ -//// bool removeConstraint(GCSConstraintPtr theConstraint); -//// /** \brief Remove feature and corresponding GCS entities -//// * \param theFeature [in] feature to remove -//// * \return \c true, if the feature is fully removed, -//// * \c false, if there are available entities used by other constraints or features -//// */ -//// bool removeEntity(const FeaturePtr& theFeature); -//// /** \brief Remove attribute and corresponding GCS entities -//// * \param theAttribute [in] attribute to remove -//// * \return \c true, if the attribute is removed, -//// * \c false, if it is used by existent features or constraints -//// */ -//// bool removeEntity(const AttributePtr& theAttribute); - /// \brief Move parameters of the entity to the constants void makeConstant(const EntityWrapperPtr& theEntity); /// \brief Move parameters of the entity to the variables void makeVariable(const EntityWrapperPtr& theEntity); -//// /// \brief Return scalar by its ID or null pointer -//// double* getScalar(const EntityID& theID) const; -//// /// \brief Return point by its ID or null pointer -//// GCS::Point* getPoint(const EntityID& theID) const; -//// /// \brief Return line by its ID or null pointer -//// GCS::Line* getLine(const EntityID& theID) const; -//// /// \brief Return circle by its ID or null pointer -//// GCS::Circle* getCircle(const EntityID& theID) const; -//// /// \brief Return arc by its ID or null pointer -//// GCS::Arc* getArc(const EntityID& theID) const; -//// -//// /// \brief Return list of GCS constraints corresponding to the given -//// const std::vector& getConstraint(const ConstraintPtr& theConstraint) const; - -//// /// \brief Verifies, the attribute is available in current storage -//// bool isInteract(AttributePtr theAttribute) const; -//// /// \brief Verifies, the feature is available in current storage -//// bool isInteract(FeaturePtr theFeature) const; - private: -//// /** \brief Creates scalar parameter in the list of parameters -//// * \param theScalar [in] value to be converted -//// * \return pointer to new scalar -//// */ -//// double* createScalar(const AttributeDoublePtr& theScalar = AttributeDoublePtr()); -//// /** \brief Creates two parameters in the list of parameters to store point coordinates -//// * \param thePoint [in] point to be converted -//// * \return FreeGCS point -//// */ -//// GCS::Point createPoint(const std::shared_ptr& thePoint); -//// /** \brief Creates or updates a scalar value -//// * \param theScalar [in] attribute to update scalar value -//// * \param theID [in] ID of scalar to be updated -//// */ -//// void updateScalar(const AttributeDoublePtr& theScalar, EntityID& theID); -//// /** \brief Creates or updates an angular value -//// * \param theAngle [in] attribute to update scalar value -//// * \param theID [in] ID of scalar to be updated -//// */ -//// void updateAngle(const AttributeDoublePtr& theAngle, EntityID& theID); -//// /** \brief Creates or updates parameters of the point -//// * \param thePoint [in] point used to update parameters -//// * \param theID [in] ID of FreeGCS entity to be updated -//// */ -//// void updatePoint(const std::shared_ptr& thePoint, -//// EntityID& theID); -//// /** \brief Creates or updates parameters of the line -//// * \param theLine [in] line used to update parameters -//// * \param theID [in/out] ID of FreeGCS entity to be updated (cleared if problems) -//// */ -//// void updateLine(const FeaturePtr& theLine, EntityID& theID); -//// /** \brief Creates or updates parameters of the circle -//// * \param theLine [in] circle used to update parameters -//// * \param theID [in/out] ID of FreeGCS entity to be updated (cleared if problems) -//// */ -//// void updateCircle(const FeaturePtr& theCircle, EntityID& theID); -//// /** \brief Creates or updates parameters of the arc -//// * \param theLine [in] arc used to update parameters -//// * \param theID [in/out] ID of FreeGCS entity to be updated (cleared if problems) -//// */ -//// void updateArc(const FeaturePtr& theArc, EntityID& theID); - -//// /// \brief Check the feature is used by constraints -//// bool isUsed(const FeaturePtr& theFeature) const; -//// /// \brief Check the attribute is used by constraints or features -//// bool isUsed(const AttributePtr& theAttribute) const; - -//// /// \brief Remove given parameter from the lists of parameters and constants -//// void removeParameters(double* theParam1, double* theParam2 = 0); - /// \brief Move parameters of the entity from the list of variables to the list of constants /// and vice versa /// \param theEntity [in] entity to be changed @@ -248,213 +105,10 @@ private: GCS::VEC_pD myConst; ///< list of constants EntityID myEntityLastID; ///< identifier of last added entity -//// std::map > -//// myConstraintsMap; ///< map SketchPlugin constraints to corresponding GCS constraints -//// -//// std::map myAttributeEntityMap; ///< map attributes to corresponding entities -//// std::map myFeatureEntityMap; ///< map features to corresponding entities -//// -//// std::map myGCSScalars; ///< list of scalar values and their IDs -//// std::map myGCSPoints; ///< list of points and their IDs -//// std::map myGCSEntities; ///< list of lines, circles and arcs and their IDs - std::map > myArcConstraintMap; ///< additional constraints for correct processing of the arcs -//// std::list myRemovedParameters; ///< list of removed parameters std::list myRemovedConstraints; ///< list of removed constraints to notify solver - -#else - -// ================================================================================================ -// =================== OBSOLETE =========================================================== -public: - PlaneGCSSolver_Storage(); - - /** \brief Add new parameter to the current group - * \param[in] theParam SolveSpace parameter - * \return the ID of added parameter - */ - Slvs_hParam addParameter(const Slvs_Param& theParam); - /** \brief Updates parameter in the current group. If the ID of parameter is zero, the new item will be added - * \param[in] theParam SolveSpace parameter - * \return the ID of updated/added parameter - */ - Slvs_hParam updateParameter(const Slvs_Param& theParam); - /** \brief Removes the parameter by its ID - * \param[in] theParamID index of parameter to be removed - * \return \c true if the parameter was successfully removed - */ - bool removeParameter(const Slvs_hParam& theParamID); - /// \brief Returns the parameter by its ID - const Slvs_Param& getParameter(const Slvs_hParam& theParamID) const; - - /** \brief Add new entity to the current group - * \param[in] theEntity SolveSpace entity - * \return the ID of added entity - */ - Slvs_hEntity addEntity(const Slvs_Entity& theEntity); - /** \brief Updates entity in the current group. If the ID of entity is zero, the new item will be added - * \param[in] theEntity SolveSpace entity - * \return the ID of updated/added entity - */ - Slvs_hEntity updateEntity(const Slvs_Entity& theEntity); - /** \brief Removes the entity by its ID. All parameters used in this entity, - * and not used in other constraints, will be removed too. - * \param[in] theEntityID index of entity to be removed - * \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 Verifies the current point or another coincident one is fixed - /// \param[in] thePointID entity to be checked fixed - /// \param[out] theFixed ID of constraint - /// \param[in] theAccurate if \c true, the calculation will be made for all type of constraints, - /// if \c false, only the point is verified - /// \return \c true if the point is fixed - bool isPointFixed(const Slvs_hEntity& thePointID, Slvs_hConstraint& theFixed, bool theAccurate = false) const; - /// \brief Verifies the current entity is fully fixed (may not be changed by constraints) - /// \param[in] theEntityID entity to be checked fixed - /// \param[in] theAccurate if \c true, the calculation will be made for all type of constraints, - /// if \c false, only points are verified - /// \return \c true if the entity is fixed - bool isEntityFixed(const Slvs_hEntity& theEntityID, bool theAccurate = false) const; - - /** \brief Add new constraint to the current group - * \param[in] theConstraint SolveSpace's constraint - * \return the ID of added constraint - */ - Slvs_hConstraint addConstraint(const Slvs_Constraint& theConstraint); - /** \brief Updates constraint in the current group. - * If the ID of constraint is zero, the new item will be added - * \param[in] theConstraint SolveSpace constraint - * \return the ID of updated/added constraint - */ - Slvs_hConstraint updateConstraint(const Slvs_Constraint& theConstraint); - /** \brief Removes the constraint by its ID. All entities and parameters depending on this - * constraint, which are not used in other constraints, will be removed too. - * \param[in] theConstraintID index of constraint to be removed - * \return \c true if the constraint was successfully removed - */ - bool removeConstraint(const Slvs_hConstraint& theConstraintID); - /// \brief Returns the constraint by its ID - const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const; - /// \brief Returns list of constraints of specified type - std::list getConstraintsByType(int theConstraintType) const; - - /// \brief Attach constraint SLVS_C_WHERE_DRAGGED to this storage. It need to make precise calculations - void addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID); - - /// \brief Add transient constraint - void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID); - /// \brief Remove all transient constraints - void removeTemporaryConstraints(); - /// \brief Remove one temporary constraint. Preferable to remove the points under Point-on-Line constraint - /// \return Number of remaining temporary constraints - int deleteTemporaryConstraint(); - /// \brief Checks the constraint is temporary - bool isTemporary(const Slvs_hConstraint& theConstraintID) const; - /// \brief Number of temporary constraints - int numberTemporary() const - { return (int)myTemporaryConstraints.size(); } - - /// \brief Shows the sketch should be resolved - bool isNeedToResolve(); - - /// \brief Shows the storage has the same constraint twice - bool hasDuplicatedConstraint() const - { return myDuplicatedConstraint; } - - /// \brief Changes the flag of group to be resolved - void setNeedToResolve(bool theFlag) - { myNeedToResolve = theFlag; } - - /// \brief Returns lists of removed elements - void getRemoved(std::set& theParameters, - std::set& theEntities, - std::set& theConstraints); - - /// \brief Initialize constraint solver by the entities collected by current storage - void initializeSolver(SketchSolver_Solver& theSolver); - -private: - /// \brief Store coincident points - void addCoincidentPoints(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2); - /// \brief Remove point from lists of coincidence - void removeCoincidentPoint(const Slvs_hEntity& thePoint); - /// \brief Remove point-point coincidence - void removeCoincidence(const Slvs_Constraint& theCoincidence); - -public: - /// \brief Check two points are coincident - bool isCoincident(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const; - - /// \brief Check two points are coincident or have same coordinates - bool isEqual(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const; - - /// \brief Check the entity is horizontal of vertical - bool isAxisParallel(const Slvs_hEntity& theEntity) const; - - /// \brief Verifies the entity is used in any equal constraint - /// \param[in] theEntity entity to be found - /// \param[out] theEqual constraint, which uses the entity - /// \return \c true, if the Equal constrait is found - bool isUsedInEqual(const Slvs_hEntity& theEntity, Slvs_Constraint& theEqual) const; - - /// \brief Fixes specified entity - /// \param theEntity ID of the entity to be fixed - /// \return List of created constraints - std::vector fixEntity(const Slvs_hEntity& theEntity); - -private: - /// \brief Fixes specified point - /// \param [in] thePoint point to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixPoint(const Slvs_Entity& thePoint, std::vector& theCreated); - /// \brief Fixes specified line - /// \param [in] theLine line to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixLine(const Slvs_Entity& theLine, std::vector& theCreated); - /// \brief Fixes specified circle - /// \param [in] theCircle circle to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixCircle(const Slvs_Entity& theCircle, std::vector& theCreated); - /// \brief Fixes specified arc - /// \param [in] theArc arc to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixArc(const Slvs_Entity& theArc, std::vector& theCreated); - -private: - Slvs_hParam myParamMaxID; ///< current parameter index (may differs with the number of parameters) - std::vector myParameters; ///< list of parameters used in the current group of constraints (sorted by the identifier) - Slvs_hEntity myEntityMaxID; ///< current entity index (may differs with the number of entities) - std::vector myEntities; ///< list of entities used in the current group of constraints (sorted by the identifier) - Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints) - std::vector myConstraints; ///< list of constraints used in the current group (sorted by the identifier) - - std::vector< std::set > myCoincidentPoints; ///< lists of coincident points - Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point - - bool myNeedToResolve; ///< parameters are changed and group needs to be resolved - bool myDuplicatedConstraint; ///< shows the storage has same constraint twice - - std::set myTemporaryConstraints; ///< list of transient constraints - std::set myRemovedParameters; ///< list of just removed parameters (cleared when returning to applicant) - std::set myRemovedEntities; ///< list of just removed entities (cleared when returning to applicant) - std::set myRemovedConstraints; ///< list of just removed constraints (cleared when returning to applicant) - std::set myUpdatedParameters; ///< list of just updated parameters (cleared when isNeedToResolve() called) -#endif }; #endif diff --git a/src/SketchSolver/SketchSolver_Group.cpp b/src/SketchSolver/SketchSolver_Group.cpp index b019c7ed3..11f25e8d0 100644 --- a/src/SketchSolver/SketchSolver_Group.cpp +++ b/src/SketchSolver/SketchSolver_Group.cpp @@ -533,7 +533,6 @@ void SketchSolver_Group::removeTemporaryConstraints() // ============================================================================ void SketchSolver_Group::removeConstraint(ConstraintPtr theConstraint) { - bool isFullyRemoved = true; ConstraintConstraintMap::iterator aCIter = myConstraints.begin(); for (; aCIter != myConstraints.end(); aCIter++) if (aCIter->first == theConstraint) { diff --git a/src/SketchSolver/SketchSolver_Storage.h b/src/SketchSolver/SketchSolver_Storage.h index 138c8994f..ae0ac3602 100644 --- a/src/SketchSolver/SketchSolver_Storage.h +++ b/src/SketchSolver/SketchSolver_Storage.h @@ -101,15 +101,6 @@ public: /// \brief Remove all features became invalid SKETCHSOLVER_EXPORT void removeInvalidEntities(); -//// /// \brief Mark specified constraint as temporary -//// virtual void setTemporary(ConstraintPtr theConstraint) = 0; -//// /// \brief Returns number of temporary constraints -//// virtual size_t nbTemporary() const = 0; -//// /// \brief Remove temporary constraints -//// /// \param theNbConstraints [in] number of temporary constraints to be deleted -//// /// \return number of remaining temporary constraints -//// virtual size_t removeTemporary(size_t theNbConstraints = 1) = 0; - /// \brief Check whether the feature or its attributes are used by this storage /// \param theFeature [in] feature to be checked /// \return \c true if the feature interacts with the storage diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp index a34cee193..d8cb75f57 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.cpp @@ -45,7 +45,6 @@ SolveSpaceSolver_Storage::SolveSpaceSolver_Storage(const GroupID& theGroup) myParamMaxID(SLVS_E_UNKNOWN), myEntityMaxID(SLVS_E_UNKNOWN), myConstrMaxID(SLVS_C_UNKNOWN), - myFixed(SLVS_E_UNKNOWN), myDuplicatedConstraint(false) { } @@ -887,167 +886,6 @@ void SolveSpaceSolver_Storage::copyEntity(const Slvs_hEntity& theFrom, const Slv } -bool SolveSpaceSolver_Storage::isPointFixed( - const Slvs_hEntity& thePointID, Slvs_hConstraint& theFixed, bool theAccurate) const -{ - // Search the set of coincident points - std::set aCoincident; - aCoincident.insert(thePointID); - - // Check whether one of coincident points is out-of-group - std::set::const_iterator aCoincIt = aCoincident.begin(); - for (; aCoincIt != aCoincident.end(); ++aCoincIt) { - Slvs_Entity aPoint = getEntity(*aCoincIt); - if (aPoint.group == SLVS_G_OUTOFGROUP) - return true; - } - - // Search the Rigid constraint - theFixed = SLVS_C_UNKNOWN; - std::vector::const_iterator aConstrIter = myConstraints.begin(); - for (; aConstrIter != myConstraints.end(); aConstrIter++) - if (aConstrIter->type == SLVS_C_WHERE_DRAGGED && - aCoincident.find(aConstrIter->ptA) != aCoincident.end()) { - theFixed = aConstrIter->h; - if (aConstrIter->ptA == thePointID) - return true; - } - if (theFixed != SLVS_C_UNKNOWN) - return true; - - if (theAccurate) { - // Try to find the fixed entity which uses such point or its coincidence - std::vector::const_iterator anEntIter = myEntities.begin(); - for (; anEntIter != myEntities.end(); anEntIter++) { - for (int i = 0; i < 4; i++) { - Slvs_hEntity aPt = anEntIter->point[i]; - if (aPt != SLVS_E_UNKNOWN && - (aPt == thePointID || aCoincident.find(aPt) != aCoincident.end())) { - if (isEntityFixed(anEntIter->h, true)) - return true; - } - } - } - } - return SLVS_E_UNKNOWN; -} - -bool SolveSpaceSolver_Storage::isEntityFixed(const Slvs_hEntity& theEntityID, bool theAccurate) const -{ - int aPos = Search(theEntityID, myEntities); - if (aPos < 0 || aPos >= (int)myEntities.size()) - return false; - - // Firstly, find how many points are under Rigid constraint - int aNbFixed = 0; - for (int i = 0; i < 4; i++) { - Slvs_hEntity aPoint = myEntities[aPos].point[i]; - if (aPoint == SLVS_E_UNKNOWN) - continue; - - std::set aCoincident; - aCoincident.insert(aPoint); - - // Search the Rigid constraint - std::vector::const_iterator aConstrIter = myConstraints.begin(); - for (; aConstrIter != myConstraints.end(); aConstrIter++) - if (aConstrIter->type == SLVS_C_WHERE_DRAGGED && - aCoincident.find(aConstrIter->ptA) != aCoincident.end()) - aNbFixed++; - } - - std::list aList; - std::list::iterator anIt; - Slvs_hConstraint aTempID; // used in isPointFixed() method - - if (myEntities[aPos].type == SLVS_E_LINE_SEGMENT) { - if (aNbFixed == 2) - return true; - else if (aNbFixed == 0 || !theAccurate) - return false; - // Additional check (the line may be fixed if it is used by different constraints): - // 1. The line is used in Equal constraint, another entity is fixed and there is a fixed point on line - aList = getConstraintsByType(SLVS_C_PT_ON_LINE); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if (anIt->entityA == theEntityID && isPointFixed(anIt->ptA, aTempID)) - break; - if (anIt != aList.end()) { - aList = getConstraintsByType(SLVS_C_EQUAL_LENGTH_LINES); - aList.splice(aList.end(), getConstraintsByType(SLVS_C_EQUAL_LINE_ARC_LEN)); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) { - Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA; - if (isEntityFixed(anOther, false)) - return true; - } - } - // 2. The line is used in Parallel/Perpendicular/Vertical/Horizontal and Length constraints - aList = getConstraintsByType(SLVS_C_PARALLEL); - aList.splice(aList.end(), getConstraintsByType(SLVS_C_PERPENDICULAR)); - aList.splice(aList.end(), getConstraintsByType(SLVS_C_VERTICAL)); - aList.splice(aList.end(), getConstraintsByType(SLVS_C_HORIZONTAL)); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) { - Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA; - if (isEntityFixed(anOther, false)) - break; - } - if (anIt != aList.end()) { - aList = getConstraintsByType(SLVS_C_PT_PT_DISTANCE); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if ((anIt->ptA == myEntities[aPos].point[0] && anIt->ptB == myEntities[aPos].point[1]) || - (anIt->ptA == myEntities[aPos].point[1] && anIt->ptB == myEntities[aPos].point[0])) - return true; - } - // 3. Another verifiers ... - } else if (myEntities[aPos].type == SLVS_E_CIRCLE) { - if (aNbFixed == 0) - return false; - // Search for Diameter constraint - aList = getConstraintsByType(SLVS_C_DIAMETER); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if (anIt->entityA == theEntityID) - return true; - if (!theAccurate) - return false; - // Additional check (the circle may be fixed if it is used by different constraints): - // 1. The circle is used in Equal constraint and another entity is fixed - aList = getConstraintsByType(SLVS_C_EQUAL_RADIUS); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) { - Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA; - if (isEntityFixed(anOther, false)) - return true; - } - // 2. Another verifiers ... - } else if (myEntities[aPos].type == SLVS_E_ARC_OF_CIRCLE) { - if (aNbFixed > 2) - return true; - else if (aNbFixed <= 1) - return false; - // Search for Diameter constraint - aList = getConstraintsByType(SLVS_C_DIAMETER); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if (anIt->entityA == theEntityID) - return true; - if (!theAccurate) - return false; - // Additional check (the arc may be fixed if it is used by different constraints): - // 1. The arc is used in Equal constraint and another entity is fixed - aList = getConstraintsByType(SLVS_C_EQUAL_RADIUS); - aList.splice(aList.end(), getConstraintsByType(SLVS_C_EQUAL_LINE_ARC_LEN)); - for (anIt = aList.begin(); anIt != aList.end(); anIt++) - if (anIt->entityA == theEntityID || anIt->entityB == theEntityID) { - Slvs_hEntity anOther = anIt->entityA == theEntityID ? anIt->entityB : anIt->entityA; - if (isEntityFixed(anOther, false)) - return true; - } - // 2. Another verifiers ... - } - return false; -} - - Slvs_hConstraint SolveSpaceSolver_Storage::addConstraint(const Slvs_Constraint& theConstraint) { if (theConstraint.h > 0 && theConstraint.h <= myConstrMaxID) { @@ -1115,8 +953,6 @@ bool SolveSpaceSolver_Storage::removeConstraint(const Slvs_hConstraint& theConst if (anEntities[i] != SLVS_E_UNKNOWN) aResult = removeEntity(anEntities[i]) && aResult; // remove temporary fixed point, if available - if (myFixed == theConstraintID) - myFixed = SLVS_E_UNKNOWN; if (myDuplicatedConstraint) { // Check the duplicated constraints are still available myDuplicatedConstraint = false; @@ -1148,26 +984,6 @@ const Slvs_Constraint& SolveSpaceSolver_Storage::getConstraint(const Slvs_hConst return aDummy; } -std::list SolveSpaceSolver_Storage::getConstraintsByType(int theConstraintType) const -{ - std::list aResult; - std::vector::const_iterator aCIter = myConstraints.begin(); - for (; aCIter != myConstraints.end(); aCIter++) - if (aCIter->type == theConstraintType) - aResult.push_back(*aCIter); - return aResult; -} - - -void SolveSpaceSolver_Storage::addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID) -{ - if (myFixed != SLVS_E_UNKNOWN) - return; // the point is already fixed - int aPos = Search(theConstraintID, myConstraints); - if (aPos >= 0 && aPos < (int)myConstraints.size()) - myFixed = theConstraintID; -} - void SolveSpaceSolver_Storage::initializeSolver(SolverPtr theSolver) { @@ -1189,320 +1005,7 @@ void SolveSpaceSolver_Storage::initializeSolver(SolverPtr theSolver) aSolver->setParameters(myParameters.data(), (int)myParameters.size()); aSolver->setEntities(myEntities.data(), (int)myEntities.size()); - - // Copy constraints excluding the fixed one - std::vector aConstraints = myConstraints; - if (myFixed != SLVS_E_UNKNOWN) { - Slvs_hEntity aFixedPoint = SLVS_E_UNKNOWN; - std::vector::iterator anIt = aConstraints.begin(); - for (; anIt != aConstraints.end(); anIt++) - if (anIt->h == myFixed) { - aFixedPoint = anIt->ptA; - aConstraints.erase(anIt); - break; - } - // set dragged parameters - int aPos = Search(aFixedPoint, myEntities); - aSolver->setDraggedParameters(myEntities[aPos].param); - } - aSolver->setConstraints(aConstraints.data(), (int)aConstraints.size()); -} - - -bool SolveSpaceSolver_Storage::isEqual( - const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const -{ - // Precise checking of coincidence: verify that points have equal coordinates - int aEnt1Pos = Search(thePoint1, myEntities); - int aEnt2Pos = Search(thePoint2, myEntities); - if (aEnt1Pos >= 0 && aEnt1Pos < (int)myEntities.size() && - aEnt2Pos >= 0 && aEnt2Pos < (int)myEntities.size()) { - double aDist[2]; - int aParamPos; - for (int i = 0; i < 2; i++) { - aParamPos = Search(myEntities[aEnt1Pos].param[i], myParameters); - aDist[i] = myParameters[aParamPos].val; - aParamPos = Search(myEntities[aEnt2Pos].param[i], myParameters); - aDist[i] -= myParameters[aParamPos].val; - } - if (aDist[0] * aDist[0] + aDist[1] * aDist[1] < tolerance * tolerance) - return true; - } - return false; -} - - -std::vector SolveSpaceSolver_Storage::fixEntity(const Slvs_hEntity& theEntity) -{ - std::vector aNewConstraints; - - int aPos = Search(theEntity, myEntities); - if (aPos >= 0 && aPos < (int)myEntities.size()) { - switch (myEntities[aPos].type) { - case SLVS_E_POINT_IN_2D: - case SLVS_E_POINT_IN_3D: - fixPoint(myEntities[aPos], aNewConstraints); - break; - case SLVS_E_LINE_SEGMENT: - fixLine(myEntities[aPos], aNewConstraints); - break; - case SLVS_E_CIRCLE: - fixCircle(myEntities[aPos], aNewConstraints); - break; - case SLVS_E_ARC_OF_CIRCLE: - fixArc(myEntities[aPos], aNewConstraints); - break; - default: - break; - } - } - - return aNewConstraints; -} - -void SolveSpaceSolver_Storage::fixPoint(const Slvs_Entity& thePoint, - std::vector& theCreated) -{ - Slvs_Constraint aConstraint; - Slvs_hConstraint aConstrID = SLVS_E_UNKNOWN; - bool isFixed = isPointFixed(thePoint.h, aConstrID, true); - bool isForceUpdate = (isFixed /*&& isTemporary(aConstrID)*/); - if (!isForceUpdate) { // create new constraint - if (isFixed) return; - aConstraint = Slvs_MakeConstraint(SLVS_E_UNKNOWN, thePoint.group, SLVS_C_WHERE_DRAGGED, thePoint.wrkpl, - 0.0, thePoint.h, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); - aConstraint.h = addConstraint(aConstraint); - theCreated.push_back(aConstraint.h); - } else { // update already existent constraint - if (!isFixed || aConstrID == SLVS_E_UNKNOWN) - return; - int aPos = Search(aConstrID, myConstraints); - if (aPos >= 0 && aPos < (int)myConstraints.size()) - myConstraints[aPos].ptA = thePoint.h; - } -} - -void SolveSpaceSolver_Storage::fixLine(const Slvs_Entity& theLine, - std::vector& theCreated) -{ - Slvs_Entity aPoint[2] = { - getEntity(theLine.point[0]), - getEntity(theLine.point[1]) - }; - - Slvs_Constraint anEqual; - if (isAxisParallel(theLine.h)) { - // Fix one point and a line length - Slvs_hConstraint aFixed; - if (!isPointFixed(theLine.point[0], aFixed, true) && - !isPointFixed(theLine.point[1], aFixed, true)) - fixPoint(aPoint[0], theCreated); - if (!isUsedInEqual(theLine.h, anEqual)) { - // Check the distance is not set yet - std::vector::const_iterator aDistIt = myConstraints.begin(); - for (; aDistIt != myConstraints.end(); ++aDistIt) - if ((aDistIt->type == SLVS_C_PT_PT_DISTANCE) && - ((aDistIt->ptA == theLine.point[0] && aDistIt->ptB == theLine.point[1]) || - (aDistIt->ptA == theLine.point[1] && aDistIt->ptB == theLine.point[0]))) - return; - // Calculate distance between points on the line - double aCoords[4]; - for (int i = 0; i < 2; i++) - for (int j = 0; j < 2; j++) { - Slvs_Param aParam = getParameter(aPoint[i].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, theLine.group, - SLVS_C_PT_PT_DISTANCE, theLine.wrkpl, aLength, - theLine.point[0], theLine.point[1], SLVS_E_UNKNOWN, SLVS_E_UNKNOWN); - aDistance.h = addConstraint(aDistance); - theCreated.push_back(aDistance.h); - } - return; - } - else if (isUsedInEqual(theLine.h, anEqual)) { - // Check another entity of Equal is already fixed - Slvs_hEntity anOtherEntID = anEqual.entityA == theLine.h ? anEqual.entityB : anEqual.entityA; - if (isEntityFixed(anOtherEntID, true)) { - // Fix start point of the line (if end point is not fixed yet) ... - Slvs_hConstraint anEndFixedID = SLVS_E_UNKNOWN; - bool isFixed = isPointFixed(theLine.point[1], anEndFixedID, true); - if (isFixed == SLVS_E_UNKNOWN) - fixPoint(aPoint[0], theCreated); - // ... and create fixed point lying on this line - Slvs_hEntity aPointToCopy = anEndFixedID == SLVS_E_UNKNOWN ? theLine.point[1] : theLine.point[0]; - // Firstly, search already fixed point on line - bool isPonLineFixed = false; - Slvs_hEntity aFixedPoint; - std::vector::const_iterator aPLIter = myConstraints.begin(); - for (; aPLIter != myConstraints.end() && !isPonLineFixed; ++aPLIter) - if (aPLIter->type == SLVS_C_PT_ON_LINE && aPLIter->entityA == theLine.h) { - isPonLineFixed = isPointFixed(aPLIter->ptA, anEndFixedID); - aFixedPoint = aPLIter->ptA; - } - - if (isPonLineFixed) { // update existent constraint - copyEntity(aPointToCopy, aFixedPoint); - } else { // create new constraint - Slvs_hEntity aCopied = copyEntity(aPointToCopy); - Slvs_Constraint aPonLine = Slvs_MakeConstraint(SLVS_E_UNKNOWN, theLine.group, SLVS_C_PT_ON_LINE, - theLine.wrkpl, 0.0, aCopied, SLVS_E_UNKNOWN, theLine.h, SLVS_E_UNKNOWN); - aPonLine.h = addConstraint(aPonLine); - theCreated.push_back(aPonLine.h); - fixPoint(getEntity(aCopied), theCreated); - } - return; - } - } - - // Fix both points - for (int i = 0; i < 2; i++) - fixPoint(aPoint[i], theCreated); -} - -void SolveSpaceSolver_Storage::fixCircle(const Slvs_Entity& theCircle, - std::vector& theCreated) -{ - bool isFixRadius = true; - // Verify the arc is under Equal constraint - Slvs_Constraint anEqual; - if (isUsedInEqual(theCircle.h, anEqual)) { - // Check another entity of Equal is already fixed - Slvs_hEntity anOtherEntID = anEqual.entityA == theCircle.h ? anEqual.entityB : anEqual.entityA; - if (isEntityFixed(anOtherEntID, true)) - isFixRadius = false; - } - - fixPoint(getEntity(theCircle.point[0]), theCreated); - - if (isFixRadius) { - // Search the radius is already fixed - std::vector::const_iterator aDiamIter = myConstraints.begin(); - for (; aDiamIter != myConstraints.end(); ++aDiamIter) - if (aDiamIter->type == SLVS_C_DIAMETER && aDiamIter->entityA == theCircle.h) - return; - - // Fix radius of a circle - const Slvs_Entity& aRadEnt = getEntity(theCircle.distance); - double aRadius = getParameter(aRadEnt.param[0]).val; - Slvs_Constraint aFixedR = Slvs_MakeConstraint(SLVS_E_UNKNOWN, theCircle.group, SLVS_C_DIAMETER, - theCircle.wrkpl, aRadius * 2.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, theCircle.h, SLVS_E_UNKNOWN); - aFixedR.h = addConstraint(aFixedR); - theCreated.push_back(aFixedR.h); - } -} - -void SolveSpaceSolver_Storage::fixArc(const Slvs_Entity& theArc, - std::vector& theCreated) -{ - Slvs_Entity aPoint[3] = { - getEntity(theArc.point[0]), - getEntity(theArc.point[1]), - getEntity(theArc.point[2]) - }; - - bool isFixRadius = true; - std::list aPointsToFix; - aPointsToFix.push_back(aPoint[1]); - aPointsToFix.push_back(aPoint[2]); - - // Verify the arc is under Equal constraint - Slvs_Constraint anEqual; - if (isUsedInEqual(theArc.h, anEqual)) { - // Check another entity of Equal is already fixed - Slvs_hEntity anOtherEntID = anEqual.entityA == theArc.h ? anEqual.entityB : anEqual.entityA; - if (isEntityFixed(anOtherEntID, true)) { - isFixRadius = false; - Slvs_Entity anOtherEntity = getEntity(anOtherEntID); - if (anOtherEntity.type == SLVS_E_LINE_SEGMENT) { - aPointsToFix.pop_back(); - aPointsToFix.push_back(aPoint[0]); - } - } - } - - Slvs_hConstraint aConstrID; - int aNbPointsToFix = 2; // number of fixed points for the arc - if (isPointFixed(theArc.point[0], aConstrID, true)) - aNbPointsToFix--; - - double anArcPoints[3][2]; - for (int i = 0; i < 3; i++) { - const Slvs_Entity& aPointOnArc = getEntity(theArc.point[i]); - for (int j = 0; j < 2; j++) - anArcPoints[i][j] = getParameter(aPointOnArc.param[j]).val; - } - - // Radius of the arc - std::shared_ptr aCenter(new GeomAPI_Pnt2d(anArcPoints[0][0], anArcPoints[0][1])); - std::shared_ptr aStart(new GeomAPI_Pnt2d(anArcPoints[1][0], anArcPoints[1][1])); - double aRadius = aCenter->distance(aStart); - - // Update end point of the arc to be on a curve - std::shared_ptr anEnd(new GeomAPI_Pnt2d(anArcPoints[2][0], anArcPoints[2][1])); - double aDistance = anEnd->distance(aCenter); - std::shared_ptr aDir = anEnd->xy()->decreased(aCenter->xy()); - if (aDistance < tolerance) - aDir = aStart->xy()->decreased(aCenter->xy())->multiplied(-1.0); - else - aDir = aDir->multiplied(aRadius / aDistance); - double xy[2] = {aCenter->x() + aDir->x(), aCenter->y() + aDir->y()}; - const Slvs_Entity& aEndPoint = getEntity(theArc.point[2]); - for (int i = 0; i < 2; i++) { - Slvs_Param aParam = getParameter(aEndPoint.param[i]); - aParam.val = xy[i]; - updateParameter(aParam); - } - - std::list::iterator aPtIt = aPointsToFix.begin(); - for (; aNbPointsToFix > 0; aPtIt++, aNbPointsToFix--) - fixPoint(*aPtIt, theCreated); - - if (isFixRadius) { - // Fix radius of the arc - bool isExists = false; - std::vector::iterator anIt = myConstraints.begin(); - for (; anIt != myConstraints.end() && !isExists; ++anIt) - if (anIt->type == SLVS_C_DIAMETER && anIt->entityA == theArc.h) - isExists = true; - if (!isExists) { - Slvs_Constraint aFixedR = Slvs_MakeConstraint(SLVS_E_UNKNOWN, theArc.group, SLVS_C_DIAMETER, - theArc.wrkpl, aRadius * 2.0, SLVS_E_UNKNOWN, SLVS_E_UNKNOWN, theArc.h, SLVS_E_UNKNOWN); - aFixedR.h = addConstraint(aFixedR); - theCreated.push_back(aFixedR.h); - } - } -} - - -bool SolveSpaceSolver_Storage::isAxisParallel(const Slvs_hEntity& theEntity) const -{ - std::vector::const_iterator anIter = myConstraints.begin(); - for (; anIter != myConstraints.end(); anIter++) - if ((anIter->type == SLVS_C_HORIZONTAL || anIter->type == SLVS_C_VERTICAL) && - anIter->entityA == theEntity) - return true; - return false; -} - -bool SolveSpaceSolver_Storage::isUsedInEqual( - const Slvs_hEntity& theEntity, Slvs_Constraint& theEqual) const -{ - // Check the entity is used in Equal constraint - std::vector::const_iterator anEqIter = myConstraints.begin(); - for (; anEqIter != myConstraints.end(); anEqIter++) - if ((anEqIter->type == SLVS_C_EQUAL_LENGTH_LINES || - anEqIter->type == SLVS_C_EQUAL_LINE_ARC_LEN || - anEqIter->type == SLVS_C_EQUAL_RADIUS) && - (anEqIter->entityA == theEntity || anEqIter->entityB == theEntity)) { - theEqual = *anEqIter; - return true; - } - return false; + aSolver->setConstraints(myConstraints.data(), (int)myConstraints.size()); } diff --git a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h index bf742f513..a6646caa0 100644 --- a/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h +++ b/src/SketchSolver/SolveSpaceSolver/SolveSpaceSolver_Storage.h @@ -38,17 +38,6 @@ public: /// \return \c true if the value of parameter is updated virtual bool update(ParameterWrapperPtr theParameter); -//// /// \brief Removes constraint from the storage -//// /// \return \c true if the constraint and all its parameters are remove successfully -//// virtual bool removeConstraint(ConstraintPtr theConstraint); -//// /// \brief Removes feature from the storage -//// /// \return \c true if the feature and its attributes are removed successfully; -//// /// \c false if the feature or any it attribute is used by remaining constraints. -//// virtual bool removeEntity(FeaturePtr theFeature); -//// /// \brief Removes attribute from the storage -//// /// \return \c true if the attribute is not used by remaining features and constraints -//// virtual bool removeEntity(AttributePtr theAttribute); - /// \brief Update SketchPlugin features after resolving constraints /// \param theFixedOnly [in] if \c true the fixed points will be updated only virtual void refresh(bool theFixedOnly = false) const; @@ -138,20 +127,6 @@ public: const Slvs_hEntity& entityMaxID() const { return myEntityMaxID; } - /// \brief Verifies the current point or another coincident one is fixed - /// \param[in] thePointID entity to be checked fixed - /// \param[out] theFixed ID of constraint - /// \param[in] theAccurate if \c true, the calculation will be made for all type of constraints, - /// if \c false, only the point is verified - /// \return \c true if the point is fixed - bool isPointFixed(const Slvs_hEntity& thePointID, Slvs_hConstraint& theFixed, bool theAccurate = false) const; - /// \brief Verifies the current entity is fully fixed (may not be changed by constraints) - /// \param[in] theEntityID entity to be checked fixed - /// \param[in] theAccurate if \c true, the calculation will be made for all type of constraints, - /// if \c false, only points are verified - /// \return \c true if the entity is fixed - bool isEntityFixed(const Slvs_hEntity& theEntityID, bool theAccurate = false) const; - /** \brief Add new constraint to the current group * \param[in] theConstraint SolveSpace's constraint * \return the ID of added constraint @@ -171,31 +146,10 @@ public: bool removeConstraint(const Slvs_hConstraint& theConstraintID); /// \brief Returns the constraint by its ID const Slvs_Constraint& getConstraint(const Slvs_hConstraint& theConstraintID) const; - /// \brief Returns list of constraints of specified type - std::list getConstraintsByType(int theConstraintType) const; /// \brief Returns quantity of constraints in this storage size_t nbConstraints() const { return myConstraints.size(); } - /// \brief Attach constraint SLVS_C_WHERE_DRAGGED to this storage. It need to make precise calculations - void addConstraintWhereDragged(const Slvs_hConstraint& theConstraintID); - -//// /// \brief Add transient constraint -//// void addTemporaryConstraint(const Slvs_hConstraint& theConstraintID); -//// /// \brief Mark specified constraint as temporary -//// virtual void setTemporary(ConstraintPtr theConstraint); -//// /// \brief Remove all transient constraints -//// void removeAllTemporary(); -//// /// \brief Remove temporary constraint s. Preferable to remove the points under Point-on-Line constraint -//// /// \param theNbConstraints [in] number of temporary constraints to be deleted -//// /// \return Number of remaining temporary constraints -//// virtual size_t removeTemporary(size_t theNbConstraints); -//// /// \brief Checks the constraint is temporary -//// bool isTemporary(const Slvs_hConstraint& theConstraintID) const; -//// /// \brief Number of temporary constraints -//// virtual size_t nbTemporary() const -//// { return myTemporaryConstraints.size(); } - /// \brief Shows the storage has the same constraint twice virtual bool hasDuplicatedConstraint() const { return myDuplicatedConstraint; } @@ -203,42 +157,7 @@ public: /// \brief Initialize constraint solver by the entities collected by current storage virtual void initializeSolver(SolverPtr theSolver); -public: - /// \brief Check two points are coincident or have same coordinates - bool isEqual(const Slvs_hEntity& thePoint1, const Slvs_hEntity& thePoint2) const; - - /// \brief Check the entity is horizontal of vertical - bool isAxisParallel(const Slvs_hEntity& theEntity) const; - - /// \brief Verifies the entity is used in any equal constraint - /// \param[in] theEntity entity to be found - /// \param[out] theEqual constraint, which uses the entity - /// \return \c true, if the Equal constrait is found - bool isUsedInEqual(const Slvs_hEntity& theEntity, Slvs_Constraint& theEqual) const; - - /// \brief Fixes specified entity - /// \param theEntity ID of the entity to be fixed - /// \return List of created constraints - std::vector fixEntity(const Slvs_hEntity& theEntity); - private: - /// \brief Fixes specified point - /// \param [in] thePoint point to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixPoint(const Slvs_Entity& thePoint, std::vector& theCreated); - /// \brief Fixes specified line - /// \param [in] theLine line to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixLine(const Slvs_Entity& theLine, std::vector& theCreated); - /// \brief Fixes specified circle - /// \param [in] theCircle circle to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixCircle(const Slvs_Entity& theCircle, std::vector& theCreated); - /// \brief Fixes specified arc - /// \param [in] theArc arc to be fixed - /// \param [out] theCreated list of the Fixed constraints created - void fixArc(const Slvs_Entity& theArc, std::vector& theCreated); - /// \brief Update arc points to be on circle sharp. void adjustArc(const Slvs_Entity& theArc); @@ -266,11 +185,8 @@ private: Slvs_hConstraint myConstrMaxID; ///< current constraint index (may differs with the number of constraints) std::vector myConstraints; ///< list of constraints used in the current group (sorted by the identifier) - Slvs_hConstraint myFixed; ///< identifier of one of temporary constraints to fix separate point - bool myDuplicatedConstraint; ///< shows the storage has same constraint twice -//// std::set myTemporaryConstraints; ///< list of transient constraints std::set myUpdatedParameters; ///< list of just updated parameters (cleared when isNeedToResolve() called) SameConstraintMap myEqualConstraints; ///< list of groups of equal constraints