- boost::shared_ptr<ModelAPI_AttributeRefAttr> anOrigAttr =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
- if (anOrigAttr && anOrigAttr->isObject()) {
- const ObjectPtr& anObj = theAttribute->owner();
- const FeaturePtr aFeature = boost::dynamic_pointer_cast<ModelAPI_Feature>(anObj);
-
- std::list<boost::shared_ptr<ModelAPI_Attribute> > anAttrs =
- aFeature->data()->attributes(ModelAPI_AttributeRefAttr::type());
- std::list<boost::shared_ptr<ModelAPI_Attribute> >::iterator anAttr = anAttrs.begin();
- for(; anAttr != anAttrs.end(); anAttr++) {
- if (*anAttr && *anAttr != theAttribute) {
- boost::shared_ptr<ModelAPI_AttributeRefAttr> aRef =
- boost::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anAttr);
- // check the object is already presented
- if (aRef->isObject() && aRef->object() == anOrigAttr->object())
- return false;
+ if(!theAttribute.get()) {
+ return false;
+ }
+
+ AttributeRefAttrPtr aBase = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(theAttribute);
+ if(aBase->isObject()) {
+ return false;
+ }
+
+ // If we alredy have some result then all ok
+ FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(theAttribute->owner());
+ AttributePtr aBaseLinesAttribute = aFeature->attribute(SketchPlugin_Constraint::ENTITY_C());
+ AttributeRefListPtr aRefListOfBaseLines = std::dynamic_pointer_cast<ModelAPI_AttributeRefList>(aBaseLinesAttribute);
+ if(!aRefListOfBaseLines->list().empty()) {
+ return true;
+ }
+
+ AttributePtr anAttrBase = aBase->attr();
+ const std::set<AttributePtr>& aRefsList = anAttrBase->owner()->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ FeaturePtr aCoincident;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aConstrFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aConstrFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
+ AttributeRefAttrPtr anAttrRefA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_A()));
+ AttributeRefAttrPtr anAttrRefB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstrFeature->attribute(SketchPlugin_ConstraintCoincidence::ENTITY_B()));
+ if(anAttrRefA.get() && !anAttrRefA->isObject()) {
+ AttributePtr anAttrA = anAttrRefA->attr();
+ if(anAttrBase == anAttrA) {
+ aCoincident = aConstrFeature;
+ break;
+ }
+ }
+ if(anAttrRefA.get() && !anAttrRefB->isObject()) {
+ AttributePtr anAttrB = anAttrRefB->attr();
+ if(anAttrBase == anAttrB) {
+ aCoincident = aConstrFeature;
+ break;
+ }
+ }
+ }
+ }
+
+ if(!aCoincident.get()) {
+ return false;
+ }
+
+ std::set<FeaturePtr> aCoinsides;
+ SketchPlugin_Tools::findCoincidences(aCoincident,
+ SketchPlugin_ConstraintCoincidence::ENTITY_A(),
+ aCoinsides);
+ SketchPlugin_Tools::findCoincidences(aCoincident,
+ SketchPlugin_ConstraintCoincidence::ENTITY_B(),
+ aCoinsides);
+ // Remove points
+ std::set<FeaturePtr> aNewLines;
+ for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
+ if((*anIt)->getKind() != SketchPlugin_Point::ID()) {
+ aNewLines.insert(*anIt);
+ }
+ }
+ aCoinsides = aNewLines;
+
+ // Remove auxilary lines
+ if(aCoinsides.size() > 2) {
+ aNewLines.clear();
+ for(std::set<FeaturePtr>::iterator anIt = aCoinsides.begin(); anIt != aCoinsides.end(); ++anIt) {
+ if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
+ aNewLines.insert(*anIt);