-// Copyright (C) 2014-2017 CEA/DEN, EDF R&D
+// Copyright (C) 2014-2019 CEA/DEN, EDF R&D
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
-// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//
-// See http://www.salome-platform.org/ or
-// email : webmaster.salome@opencascade.com<mailto:webmaster.salome@opencascade.com>
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
#include "SketchPlugin_Tools.h"
std::set<AttributePtr>::const_iterator aIt;
for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>((*aIt)->owner());
- if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
+ if (aConstrFeature && aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID())
aCoincident.insert(aConstrFeature);
}
return aCoincident;
std::list< std::set<AttributePoint2DPtr> >::iterator aFound1 = find(thePoint1);
std::list< std::set<AttributePoint2DPtr> >::iterator aFound2 = find(thePoint2);
if (aFound1 == myCoincidentPoints.end()) {
- std::set<AttributePoint2DPtr> aNewSet;
- aNewSet.insert(thePoint1);
- if (thePoint2)
- aNewSet.insert(thePoint2);
- myCoincidentPoints.push_back(aNewSet);
+ if (aFound2 == myCoincidentPoints.end()) {
+ std::set<AttributePoint2DPtr> aNewSet;
+ aNewSet.insert(thePoint1);
+ if (thePoint2)
+ aNewSet.insert(thePoint2);
+ myCoincidentPoints.push_back(aNewSet);
+ } else
+ aFound2->insert(thePoint1);
} else if (aFound2 == myCoincidentPoints.end()) {
if (thePoint2)
aFound1->insert(thePoint2);
std::set<AttributePoint2DPtr> coincidentPoints(const AttributePoint2DPtr& thePoint)
{
+ collectCoincidentPoints(thePoint);
+
std::list< std::set<AttributePoint2DPtr> >::iterator aFound = find(thePoint);
if (aFound == myCoincidentPoints.end())
return std::set<AttributePoint2DPtr>();
}
private:
+ void coincidences(const FeaturePtr& theFeature,
+ std::set<FeaturePtr>& theCoincidences) const
+ {
+ // iterate through coincideces for the given feature
+ std::set<FeaturePtr> aCoincidences = SketchPlugin_Tools::findCoincidentConstraints(theFeature);
+ std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
+ for (; aCIt != aCoincidences.end(); ++aCIt)
+ {
+ if (theCoincidences.find(*aCIt) != theCoincidences.end())
+ continue; // already processed
+ theCoincidences.insert(*aCIt);
+ // iterate on coincident attributes
+ for (int i = 0, aPtInd = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
+ AttributeRefAttrPtr aRefAttr = (*aCIt)->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
+ if (aRefAttr && !aRefAttr->isObject())
+ {
+ FeaturePtr anOwner = ModelAPI_Feature::feature(aRefAttr->attr()->owner());
+ if (anOwner != theFeature)
+ coincidences(anOwner, theCoincidences);
+ }
+ }
+ }
+ }
+
+ // Iteratively search points coincident to the given point
+ // (two points may be coincident through the third point)
+ void collectCoincidentPoints(const AttributePoint2DPtr& thePoint)
+ {
+ AttributePoint2DPtr aPoints[2];
+
+ FeaturePtr anOwner = ModelAPI_Feature::feature(thePoint->owner());
+ std::set<FeaturePtr> aCoincidences;
+ coincidences(anOwner, aCoincidences);
+
+ std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
+ for (; aCIt != aCoincidences.end(); ++aCIt) {
+ aPoints[0] = AttributePoint2DPtr();
+ aPoints[1] = AttributePoint2DPtr();
+ for (int i = 0, aPtInd = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
+ AttributeRefAttrPtr aRefAttr = (*aCIt)->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
+ if (aRefAttr && !aRefAttr->isObject())
+ aPoints[aPtInd++] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
+ }
+
+ if (aPoints[0] && aPoints[1])
+ addCoincidence(aPoints[0], aPoints[1]);
+ }
+ }
+
std::list< std::set<AttributePoint2DPtr> >::iterator find(const AttributePoint2DPtr& thePoint)
{
std::list< std::set<AttributePoint2DPtr> >::iterator aSeek = myCoincidentPoints.begin();
std::set<AttributePoint2DPtr> findPointsCoincidentToPoint(const AttributePoint2DPtr& thePoint)
{
CoincidentPoints aCoincidentPoints;
- AttributePoint2DPtr aPoints[2];
-
- FeaturePtr anOwner = ModelAPI_Feature::feature(thePoint->owner());
- std::set<FeaturePtr> aCoincidences = findCoincidentConstraints(anOwner);
- std::set<FeaturePtr>::const_iterator aCIt = aCoincidences.begin();
- for (; aCIt != aCoincidences.end(); ++aCIt) {
- aPoints[0] = AttributePoint2DPtr();
- aPoints[1] = AttributePoint2DPtr();
- for (int i = 0, aPtInd = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
- AttributeRefAttrPtr aRefAttr = (*aCIt)->refattr(SketchPlugin_Constraint::ATTRIBUTE(i));
- if (!aRefAttr)
- continue;
- if (!aRefAttr->isObject())
- aPoints[aPtInd++] = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
- }
-
- if (aPoints[0])
- aCoincidentPoints.addCoincidence(aPoints[0], aPoints[1]);
- }
-
return aCoincidentPoints.coincidentPoints(thePoint);
}