void PartSet_Tools::findCoincidences(FeaturePtr theStartCoin, QList<FeaturePtr>& theList,
QList<FeaturePtr>& theCoincidencies,
- std::string theAttr)
+ std::string theAttr, QList<bool>& theIsAttributes)
{
std::shared_ptr<GeomAPI_Pnt2d> aOrig = getCoincedencePoint(theStartCoin);
if (aOrig.get() == NULL)
if (!theList.contains(aFeature)) {
theList.append(aFeature);
theCoincidencies.append(theStartCoin);
+ theIsAttributes.append(true); // point attribute on a feature
const std::set<AttributePtr>& aRefsList = aFeature->data()->refsToMe();
std::set<AttributePtr>::const_iterator aIt;
for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincedencePoint(aConstrFeature);
if (aPnt.get() && aOrig->isEqual(aPnt)) {
findCoincidences(aConstrFeature, theList, theCoincidencies,
- SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ SketchPlugin_ConstraintCoincidence::ENTITY_A(), theIsAttributes);
findCoincidences(aConstrFeature, theList, theCoincidencies,
- SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ SketchPlugin_ConstraintCoincidence::ENTITY_B(), theIsAttributes);
}
}
}
if (!theList.contains(aFeature))
theList.append(aFeature);
theCoincidencies.append(theStartCoin);
+ theIsAttributes.append(false); // point attribute on a feature
const std::set<AttributePtr>& aRefsList = aResult->data()->refsToMe();
std::set<AttributePtr>::const_iterator aIt;
std::shared_ptr<GeomAPI_Pnt2d> aPnt = getCoincedencePoint(aConstrFeature);
if (aPnt.get() && aOrig->isEqual(aPnt)) {
findCoincidences(aConstrFeature, theList, theCoincidencies,
- SketchPlugin_ConstraintCoincidence::ENTITY_A());
+ SketchPlugin_ConstraintCoincidence::ENTITY_A(), theIsAttributes);
findCoincidences(aConstrFeature, theList, theCoincidencies,
- SketchPlugin_ConstraintCoincidence::ENTITY_B());
+ SketchPlugin_ConstraintCoincidence::ENTITY_B(), theIsAttributes);
}
}
}
std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint2d = convertPoint(aLastShapePoint);
-
+ /// find features that should be deleted (e.g. Middle Point) or updated (e.g. Length)
std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
getConstraints(aFeaturesToDelete, aFeaturesToUpdate);
-
+ // find references(attributes and features) to the base feature
std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
std::list<AttributePtr> aRefsToFeature;
getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature);
std::cout << "[" << aRefsToFeature.size() << "] " << aRefsInfo << std::endl;
std::cout << "---- getRefAttributes:end ----" << std::endl;
#endif
- // coincidence to result points
- // find coincidences to the base object, it should be used when attribute is found
- // in myObjectToPoints
- //std::map<AttributePtr, FeaturePtr> aCoincidencesToBaseFeature;
- //getCoincidencesToObject(aBaseObject, aCoincidencesToBaseFeature);
-
std::set<AttributePoint2DPtr> aFurtherCoincidences;
std::set<std::pair<AttributePtr, AttributePtr>> aModifiedAttributes;
const std::string& aKind = aBaseFeature->getKind();
anIt != aLast; anIt++) {
AttributePtr anAttribute = *anIt;
- //if (replaceCoincidenceAttribute(anAttribute, aModifiedAttributes))
- // continue;
-
if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences))
continue;
+ // move tangency constraint to the nearest feature if possible
+ if (aNewFeature.get() && moveTangency(anAttribute, aNewFeature))
+ continue;
+
if (aReplacingResult.get()) {
AttributeRefAttrPtr aRefAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
return aFoundPoint;
}
-bool SketchPlugin_Trim::replaceCoincidenceAttribute(const AttributePtr& theCoincidenceAttribute,
- const std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
+bool SketchPlugin_Trim::moveTangency(const AttributePtr& theAttribute,
+ const FeaturePtr& theFeature)
{
- FeaturePtr aCoincidenceFeature = ModelAPI_Feature::feature(theCoincidenceAttribute->owner());
- if (aCoincidenceFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (aFeature->getKind() != SketchPlugin_ConstraintTangent::ID())
return false;
- AttributeRefAttrPtr aCAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aCoincidenceFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
- AttributeRefAttrPtr aCAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aCoincidenceFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
- AttributePtr aCAttrRefA = aCAttrA->attr();
- AttributePtr aCAttrRefB = aCAttrB->attr();
-
- bool isProcessed = false;
- for (std::set<std::pair<AttributePtr, AttributePtr>>::const_iterator
- anIt = theModifiedAttributes.begin(); anIt != theModifiedAttributes.end(); anIt++) {
- AttributePtr anAttributeBefore = anIt->first;
- if (anAttributeBefore == aCAttrRefA) {
- aCAttrA->setAttr(anIt->second);
- isProcessed = true;
- }
- if (anAttributeBefore == aCAttrRefB) {
- aCAttrB->setAttr(anIt->second);
- isProcessed = true;
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ theAttribute);
+ if (!aRefAttr.get())
+ return false;
+
+ // get shape of tangent object to the current
+ std::string aTangentAttr = SketchPlugin_Constraint::ENTITY_A();
+ if (aRefAttr->id() == SketchPlugin_Constraint::ENTITY_A())
+ aTangentAttr = SketchPlugin_Constraint::ENTITY_B();
+ AttributeRefAttrPtr aTangentRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aFeature->attribute(aTangentAttr));
+ FeaturePtr aTangentFeature = ModelAPI_Feature::feature(aTangentRefAttr->object());
+
+ // get shape of the feature of the attribute
+ FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(aRefAttr->object());
+ anAttributeFeature->execute(); // the modified value should be applyed to recompute shape
+ PointToRefsMap aPointToAttributeOrObject;
+ std::list<FeaturePtr> aFeatures;
+ aFeatures.push_back(anAttributeFeature);
+ ModelGeomAlgo_Point2D::getPointsIntersectedShape(aTangentFeature, aFeatures,
+ aPointToAttributeOrObject);
+ if (!aPointToAttributeOrObject.empty())
+ return true; // the attribute feature has a point of intersection, so we do not replace it
+
+ // get shape of the feature
+ aPointToAttributeOrObject.clear();
+ aFeatures.clear();
+ aFeatures.push_back(theFeature);
+ ModelGeomAlgo_Point2D::getPointsIntersectedShape(aTangentFeature, aFeatures,
+ aPointToAttributeOrObject);
+ if (!aPointToAttributeOrObject.empty()) {
+ std::set<ResultPtr> anEdgeShapes;
+ ModelGeomAlgo_Shape::shapesOfType(theFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
+ if (!anEdgeShapes.empty()) {
+ ResultPtr aResult = *anEdgeShapes.begin();
+ if (aResult.get()) {
+ aRefAttr->setObject(aResult);
+ return true; // the attribute feature has a point of intersection, so we do not replace it
+ }
}
}
- return isProcessed;
+ return false;
}
AISObjectPtr SketchPlugin_Trim::getAISObject(AISObjectPtr thePrevious)
std::set<AttributePtr>::const_iterator aIt;
for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ std::shared_ptr<ModelAPI_Attribute> anAttr = (*aIt);
+ FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
std::string aRefFeatureKind = aRefFeature->getKind();
- if (aRefFeatureKind == SketchPlugin_ConstraintMirror::ID() ||
- aRefFeatureKind == SketchPlugin_MultiRotation::ID() ||
- aRefFeatureKind == SketchPlugin_MultiTranslation::ID() ||
+ std::string anAttributeId = anAttr->id();
+ if ((aRefFeatureKind == SketchPlugin_ConstraintMirror::ID() &&
+ anAttributeId == SketchPlugin_ConstraintMirror::MIRROR_LIST_ID()) ||
+ (aRefFeatureKind == SketchPlugin_MultiRotation::ID() &&
+ anAttributeId == SketchPlugin_MultiRotation::ROTATION_LIST_ID()) ||
+ (aRefFeatureKind == SketchPlugin_MultiTranslation::ID() &&
+ anAttributeId == SketchPlugin_MultiTranslation::TRANSLATION_LIST_ID()) ||
aRefFeatureKind == SketchPlugin_ConstraintMiddle::ID())
theFeaturesToDelete.insert(aRefFeature);
else if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID())
}
}
-/*void SketchPlugin_Trim::getCoincidencesToObject(const ObjectPtr& theObject,
- std::map<AttributePtr, FeaturePtr>& theCoincidencesToBaseFeature)
-{
- const std::set<AttributePtr>& aRefsList = theObject->data()->refsToMe();
- std::set<AttributePtr>::const_iterator aIt;
- for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
- std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
- FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
- if (aRefFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
- continue;
- AttributePtr anAttribute;
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
- (aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
- if (aRefAttr->isObject() && aRefAttr->object() == theObject)
- {
- anAttribute = aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_B());
- }
- else {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
- (aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
- if (aRefAttr->isObject() && aRefAttr->object() == theObject)
- anAttribute = aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_A());
- }
- if (!anAttribute.get())
- continue;
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
- if (aRefAttr->isObject())
- continue; // one of attributes of coincidence contains link to an attribute
-
- anAttribute = aRefAttr->attr();
- if (anAttribute.get())
- {
- theCoincidencesToBaseFeature[anAttribute] = aRefFeature;
- }
- }
-}*/
-
void SketchPlugin_Trim::updateRefAttConstraints(
const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(),
aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
// layed on feature coincidences to divide it on several shapes
- //SketchPlugin_Sketch* aSketch = sketch();
std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));