X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintSplit.cpp;h=ccf819ab626e340bb18825946e1a40a6387a9e3d;hb=8f060aedd5949990421a96e3b4086f43efa13d24;hp=4ac4418410890de78bb75ddba68f0a2d32d3f17a;hpb=ff1e21d254ea2aaa6ecc7bdad7c445be7dda7aa5;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index 4ac441841..ccf819ab6 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -72,9 +72,9 @@ void SketchPlugin_ConstraintSplit::execute() setError("Error: Base object is not initialized."); return; } - AttributePoint2DPtr aFirstPointAttrOfSplit = + AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = + AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); if (!aFirstPointAttrOfSplit.get() || !aFirstPointAttrOfSplit->isInitialized() || !aSecondPointAttrOfSplit.get() || !aSecondPointAttrOfSplit->isInitialized()) { @@ -93,6 +93,7 @@ void SketchPlugin_ConstraintSplit::execute() FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature); std::set aFeaturesToDelete, aFeaturesToUpdate; + std::map aTangentFeatures; std::map aCoincidenceToFeature; getConstraints(aFeaturesToDelete, aFeaturesToUpdate, aTangentFeatures, aCoincidenceToFeature); @@ -120,7 +121,7 @@ void SketchPlugin_ConstraintSplit::execute() std::cout << std::endl; if (!aCoincidenceToFeature.empty()) { - std::cout << "Coincidences to base feature[" << + std::cout << "Coincidences to base feature[" << aCoincidenceToFeature.size() << "]: " << std::endl; std::map::const_iterator anIt = aCoincidenceToFeature.begin(), aLast = aCoincidenceToFeature.end(); @@ -131,7 +132,7 @@ void SketchPlugin_ConstraintSplit::execute() std::cout << i << "-" << getFeatureInfo(aFeature) << std::endl; std::cout << " -Attribute to correct:" << anAttributeId << std::endl; - std::cout << " -Point attribute:" << + std::cout << " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl; } } @@ -148,14 +149,14 @@ void SketchPlugin_ConstraintSplit::execute() std::cout << i << "-" << getFeatureInfo(aFeature) << std::endl; std::cout << " -Attribute to correct:" << anAttributeId << std::endl; - std::cout << " -Point attribute:" << + std::cout << " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl; } } - std::map >::const_iterator + std::map >::const_iterator aRefIt = aBaseRefAttributes.begin(), aRefLast = aBaseRefAttributes.end(); - std::cout << std::endl << "References to attributes of base feature [" << + std::cout << std::endl << "References to attributes of base feature [" << aBaseRefAttributes.size() << "]" << std::endl; for (; aRefIt != aRefLast; aRefIt++) { AttributePtr aBaseAttr = aRefIt->first; @@ -171,13 +172,13 @@ void SketchPlugin_ConstraintSplit::execute() FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner()); aRefsInfo.append("(" + aRFeature->name() + ") "); } - std::shared_ptr aPointAttr = + std::shared_ptr aPointAttr = std::dynamic_pointer_cast(aBaseAttr); - std::cout << aPointAttr->id().c_str() << + std::cout << aPointAttr->id().c_str() << ": " << "[" << aRefAttributes.size() << "] " << aRefsInfo << std::endl; } std::cout << std::endl; - std::cout << std::endl << "References to base feature [" << + std::cout << std::endl << "References to base feature [" << aRefsToFeature.size() << "]" << std::endl; std::list::const_iterator aRefAttrIt = aRefsToFeature.begin(), aRefAttrLast = aRefsToFeature.end(); @@ -211,11 +212,12 @@ void SketchPlugin_ConstraintSplit::execute() aModifiedAttributes); if (aFeatureKind == SketchPlugin_Circle::ID()) { FeaturePtr aCircleFeature = aBaseFeature; - splitCircle(aSplitFeature, aBaseFeature, anAfterFeature, aFurtherCoincidences, + splitCircle(aSplitFeature, aBaseFeature, anAfterFeature, aFurtherCoincidences, aCreatedFeatures, aModifiedAttributes); updateRefFeatureConstraints(getFeatureResult(aBaseFeature), aRefsToFeature); + AttributePtr aCenterAttr = aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()); aFeaturesToDelete.insert(aCircleFeature); // as circle is removed, temporary fill this attribute*/ aBaseObjectAttr->setObject(ResultPtr()); @@ -247,7 +249,7 @@ void SketchPlugin_ConstraintSplit::execute() } std::cout << "Modifed attributes (constraints to attributes are moved here):" << std::endl; - std::set >::const_iterator + std::set >::const_iterator aPIt = aModifiedAttributes.begin(), aPLast = aModifiedAttributes.end(); std::string aResInfo; for (; aPIt != aPLast; aPIt++) { @@ -278,7 +280,7 @@ void SketchPlugin_ConstraintSplit::execute() // coincidence to feature updateCoincidenceConstraintsToFeature(aCoincidenceToFeature, aFurtherCoincidences, - aFeatureResults); + aFeatureResults, aSplitFeature); // tangency updateTangentConstraintsToFeature(aTangentFeatures, aFurtherCoincidences); @@ -349,14 +351,14 @@ AISObjectPtr SketchPlugin_ConstraintSplit::getAISObject(AISObjectPtr thePrevious aPoints.push_back(aStartPoint); std::shared_ptr aSecondPnt2d = aSecondPointAttrOfSplit->pnt(); - std::shared_ptr aSecondPoint = + std::shared_ptr aSecondPoint = sketch()->to3D(aSecondPnt2d->x(), aSecondPnt2d->y()); aPoints.push_back(aSecondPoint); std::set > aSplitShapes; GeomAlgoAPI_ShapeTools::splitShape(aBaseShape, aPoints, aSplitShapes); - std::shared_ptr aShape = + std::shared_ptr aShape = GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes); AISObjectPtr anAIS = thePrevious; @@ -381,7 +383,7 @@ std::shared_ptr SketchPlugin_ConstraintSplit::getPointOfRef AttributePoint2DPtr aPointAttribute; if (theAttribute->attributeType() == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr aRefAttr = + AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); if (aRefAttr.get() && aRefAttr->isInitialized()) { AttributePtr anAttribute = aRefAttr->attr(); @@ -392,16 +394,11 @@ std::shared_ptr SketchPlugin_ConstraintSplit::getPointOfRef return aPointAttribute; } -void SketchPlugin_ConstraintSplit::getFeaturePoints(AttributePoint2DPtr& theStartPointAttr, +void SketchPlugin_ConstraintSplit::getFeaturePoints(const FeaturePtr& theFeature, + AttributePoint2DPtr& theStartPointAttr, AttributePoint2DPtr& theEndPointAttr) { - AttributePoint2DPtr aPointAttribute; - - AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast( - data()->attribute(SketchPlugin_Constraint::VALUE())); - FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); - - std::string aFeatureKind = aBaseFeature->getKind(); + std::string aFeatureKind = theFeature->getKind(); std::string aStartAttributeName, anEndAttributeName; if (aFeatureKind == SketchPlugin_Line::ID()) { aStartAttributeName = SketchPlugin_Line::START_ID(); @@ -413,9 +410,9 @@ void SketchPlugin_ConstraintSplit::getFeaturePoints(AttributePoint2DPtr& theStar } if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) { theStartPointAttr = std::dynamic_pointer_cast( - aBaseFeature->attribute(aStartAttributeName)); + theFeature->attribute(aStartAttributeName)); theEndPointAttr = std::dynamic_pointer_cast( - aBaseFeature->attribute(anEndAttributeName)); + theFeature->attribute(anEndAttributeName)); } } @@ -450,14 +447,14 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set& theFeatu else if (aRefFeatureKind == SketchPlugin_ConstraintTangent::ID()) { if (aBaseFeature->getKind() == SketchPlugin_Circle::ID()) /// TEMPORARY limitaion /// until tangency between arc and line is implemented - theFeaturesToDelete.insert(aRefFeature); + theFeaturesToDelete.insert(aRefFeature); else { std::string anAttributeToBeModified; AttributePoint2DPtr aTangentPoint; ObjectPtr aResult1 = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->object(); ObjectPtr aResult2 = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_B())->object(); if (aResult1.get() && aResult2.get()) { - FeaturePtr aCoincidenceFeature = + FeaturePtr aCoincidenceFeature = SketchPlugin_ConstraintCoincidence::findCoincidenceFeature (ModelAPI_Feature::feature(aResult1), ModelAPI_Feature::feature(aResult2)); @@ -483,7 +480,7 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set& theFeatu theTangentFeatures[aRefFeature] = std::make_pair(anAttributeToBeModified, aTangentPoint); } else /// there is not coincident point between tangent constraint - theFeaturesToDelete.insert(aRefFeature); + theFeaturesToDelete.insert(aRefFeature); } } else if (aRefFeatureKind == SketchPlugin_ConstraintCoincidence::ID()) { @@ -545,11 +542,11 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature { theRefs.clear(); - std::list aPointAttributes = + std::list aPointAttributes = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); std::set aPointAttributesSet; - std::list::const_iterator aPIt = + std::list::const_iterator aPIt = aPointAttributes.begin(), aPLast = aPointAttributes.end(); for (; aPIt != aPLast; aPIt++) aPointAttributesSet.insert(*aPIt); @@ -567,7 +564,7 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(anAttr); if (!aRefAttr->isObject()) { /// find attributes referenced to feature point attributes AttributePtr anAttrInRef = aRefAttr->attr(); - if (anAttrInRef.get() && + if (anAttrInRef.get() && aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) { if (theRefs.find(anAttrInRef) != theRefs.end()) theRefs[anAttrInRef].push_back(aRefAttr); @@ -588,11 +585,21 @@ void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature void SketchPlugin_ConstraintSplit::updateCoincidenceConstraintsToFeature( const std::map, IdToPointPair>& theCoincidenceToFeature, const std::set >& theFurtherCoincidences, - const std::set& theFeatureResults) + const std::set& theFeatureResults, + const FeaturePtr& theSplitFeature) { if (theCoincidenceToFeature.empty()) return; + // we should build coincidence constraints to end of the split feature + std::set > aNewCoincidencesToSplitFeature; + AttributePoint2DPtr aStartPointAttr, anEndPointAttr; + getFeaturePoints(theSplitFeature, aStartPointAttr, anEndPointAttr); + if (theFurtherCoincidences.find(aStartPointAttr) == theFurtherCoincidences.end()) + aNewCoincidencesToSplitFeature.insert(aStartPointAttr); + if (theFurtherCoincidences.find(anEndPointAttr) == theFurtherCoincidences.end()) + aNewCoincidencesToSplitFeature.insert(anEndPointAttr); + std::map::const_iterator aCIt = theCoincidenceToFeature.begin(), aCLast = theCoincidenceToFeature.end(); #ifdef DEBUG_SPLIT @@ -615,6 +622,19 @@ void SketchPlugin_ConstraintSplit::updateCoincidenceConstraintsToFeature( if (aFeaturePointAttribute.get()) { aCoincFeature->refattr(anAttributeId)->setObject(ResultPtr()); aCoincFeature->refattr(anAttributeId)->setAttr(aFeaturePointAttribute); + // create new coincidences to split feature points + std::set::const_iterator aSFIt = aNewCoincidencesToSplitFeature.begin(), + aSFLast = aNewCoincidencesToSplitFeature.end(); + for (; aSFIt != aSFLast; aSFIt++) { + AttributePoint2DPtr aSFAttribute = *aSFIt; + if (aCoincPnt->isEqual(aSFAttribute->pnt())) { + std::string aSecondAttribute = SketchPlugin_Constraint::ENTITY_A(); + if (anAttributeId == SketchPlugin_Constraint::ENTITY_A()) + aSecondAttribute = SketchPlugin_Constraint::ENTITY_B(); + createConstraint(SketchPlugin_ConstraintCoincidence::ID(), + aSFAttribute, aCoincFeature->refattr(aSecondAttribute)->attr()); + } + } } else { /// find feature by shape intersected the point @@ -667,7 +687,7 @@ void SketchPlugin_ConstraintSplit::updateTangentConstraintsToFeature( aFeaturePointAttribute = aFCAttribute; } if (aFeaturePointAttribute.get()) { - FeaturePtr aFeature = + FeaturePtr aFeature = std::dynamic_pointer_cast(aFeaturePointAttribute->owner()); aTangentFeature->refattr(anAttributeId)->setObject(getFeatureResult(aFeature)); } @@ -698,13 +718,13 @@ void SketchPlugin_ConstraintSplit::updateRefAttConstraints( std::cout << "SketchPlugin_ConstraintSplit::updateRefAttConstraints" << std::endl; #endif - std::set >::const_iterator + std::set >::const_iterator anIt = theModifiedAttributes.begin(), aLast = theModifiedAttributes.end(); for (; anIt != aLast; anIt++) { AttributePtr anAttribute = anIt->first; /// not found in references - if (theBaseRefAttributes.find(anAttribute) == theBaseRefAttributes.end()) + if (theBaseRefAttributes.find(anAttribute) == theBaseRefAttributes.end()) continue; std::list aRefAttributes = theBaseRefAttributes.at(anAttribute); std::list::const_iterator aRefIt = aRefAttributes.begin(), @@ -746,34 +766,35 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, if (aFeatureKind != SketchPlugin_Line::ID()) return; - AttributePoint2DPtr aFirstPointAttrOfSplit = + AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = + AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B())); AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase; - getFeaturePoints(aStartPointAttrOfBase, anEndPointAttrOfBase); + + getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase); if (!aStartPointAttrOfBase.get() && !anEndPointAttrOfBase.get()) { setError("Error: Feature has no start and end points."); return; } - arrangePointsOnLine(aStartPointAttrOfBase, anEndPointAttrOfBase, + arrangePointsOnLine(aStartPointAttrOfBase, anEndPointAttrOfBase, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); #ifdef DEBUG_SPLIT std::cout << "Arranged points (to build split between 1st and 2nd points:" << std::endl; - std::cout << "Start point: " << + std::cout << "Start point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aStartPointAttrOfBase) << std::endl; - std::cout << "1st point: " << + std::cout << "1st point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aFirstPointAttrOfSplit) << std::endl; - std::cout << "2nd point: " << + std::cout << "2nd point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aSecondPointAttrOfSplit) << std::endl; - std::cout << "End point: " << + std::cout << "End point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl; #endif /// create a split feature - theSplitFeature = + theSplitFeature = createLineFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); theCreatedFeatures.insert(theSplitFeature); @@ -827,7 +848,7 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, // before split feature if (!aStartPointAttrOfBase->pnt()->isEqual(aFirstPointAttrOfSplit->pnt())) { /// move end arc point to start of split - fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()), + fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()), aFirstPointAttrOfSplit); theBaseFeatureModified->execute(); // to update result aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(), @@ -879,12 +900,12 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, if (aFeatureKind != SketchPlugin_Arc::ID()) return; - AttributePoint2DPtr aFirstPointAttrOfSplit = + AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = + AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B())); AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase; - getFeaturePoints(aStartPointAttrOfBase, anEndPointAttrOfBase); + getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase); if (!aStartPointAttrOfBase.get() && !anEndPointAttrOfBase.get()) { setError("Error: Feature has no start and end points."); return; @@ -898,13 +919,13 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); #ifdef DEBUG_SPLIT std::cout << "Arranged points (to build split between 1st and 2nd points:" << std::endl; - std::cout << "Start point: " << + std::cout << "Start point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aStartPointAttrOfBase) << std::endl; - std::cout << "1st point: " << + std::cout << "1st point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aFirstPointAttrOfSplit) << std::endl; - std::cout << "2nd point: " << + std::cout << "2nd point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aSecondPointAttrOfSplit) << std::endl; - std::cout << "End point: " << + std::cout << "End point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl; #endif @@ -1022,19 +1043,19 @@ void SketchPlugin_ConstraintSplit::splitCircle(FeaturePtr& theSplitFeature, if (aFeatureKind != SketchPlugin_Circle::ID()) return; - AttributePoint2DPtr aFirstPointAttrOfSplit = + AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = + AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B())); /// split feature - theSplitFeature = + theSplitFeature = createArcFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); bool aSplitReversed = std::dynamic_pointer_cast(theSplitFeature)->isReversed(); theCreatedFeatures.insert(theSplitFeature); /// base feature is a left part of the circle - theBaseFeatureModified = createArcFeature(aBaseFeature, + theBaseFeatureModified = createArcFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); std::dynamic_pointer_cast( theBaseFeatureModified)->setReversed(!aSplitReversed); @@ -1168,7 +1189,7 @@ FeaturePtr SketchPlugin_ConstraintSplit::createArcFeature(const FeaturePtr& theB return aFeature; aFeature = aSketch->addFeature(SketchPlugin_Arc::ID()); - // update fillet arc: make the arc correct for sure, so, it is not needed to process + // update fillet arc: make the arc correct for sure, so, it is not needed to process // the "attribute updated" // by arc; moreover, it may cause cyclicity in hte mechanism of updater aFeature->data()->blockSendAttributeUpdated(true); @@ -1283,7 +1304,7 @@ std::set > SketchPlugin_ConstraintSplit::get return anAttributes; } - +#ifdef _DEBUG std::string SketchPlugin_ConstraintSplit::getFeatureInfo( const std::shared_ptr& theFeature, const bool isUseAttributesInfo) @@ -1300,7 +1321,7 @@ std::string SketchPlugin_ConstraintSplit::getFeatureInfo( std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(theFeature, getEdgeAttributes(theFeature)); /// processing of feature with point 2d attributes, like line, arc, circle - if (!aPointsInfo.empty()) { + if (!aPointsInfo.empty()) { anInfo += ": "; anInfo += "\n"; anInfo += aPointsInfo; @@ -1344,4 +1365,4 @@ std::string SketchPlugin_ConstraintSplit::getFeatureInfo( } return anInfo; } - +#endif