X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FSketchPlugin%2FSketchPlugin_ConstraintSplit.cpp;h=e21de959145bec5bc7e92a910de48e5ee504953e;hb=b5893b0a30fac08134c24de4565cb513a43affa6;hp=a7b725c9d41317195f517e0c257cce5c38d19bb6;hpb=454529f85169f883a6bf9ac18e2e85e34f081d8b;p=modules%2Fshaper.git diff --git a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp index a7b725c9d..e21de9591 100755 --- a/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp +++ b/src/SketchPlugin/SketchPlugin_ConstraintSplit.cpp @@ -16,6 +16,7 @@ #include #include #include +#include #include #include @@ -32,6 +33,7 @@ #include #include #include +#include #include #include @@ -43,7 +45,9 @@ #include -#define DEBUG_SPLIT +//#define CREATE_CONSTRAINTS + +//#define DEBUG_SPLIT #ifdef DEBUG_SPLIT #include #endif @@ -72,8 +76,10 @@ void SketchPlugin_ConstraintSplit::execute() setError("Error: Base object is not initialized."); return; } - AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); + AttributePoint2DPtr aFirstPointAttrOfSplit = + getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_A())); + AttributePoint2DPtr aSecondPointAttrOfSplit = + getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_B())); if (!aFirstPointAttrOfSplit.get() || !aFirstPointAttrOfSplit->isInitialized() || !aSecondPointAttrOfSplit.get() || !aSecondPointAttrOfSplit->isInitialized()) { setError("Error: Sub-shape is not initialized."); @@ -91,9 +97,11 @@ void SketchPlugin_ConstraintSplit::execute() FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value()); ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature); std::set aFeaturesToDelete, aFeaturesToUpdate; - std::map aTangentFeatures; + + //std::map aTangentFeatures; std::map aCoincidenceToFeature; - getConstraints(aFeaturesToDelete, aFeaturesToUpdate, aTangentFeatures, aCoincidenceToFeature); + getConstraints(aFeaturesToDelete, aFeaturesToUpdate, /*aTangentFeatures, */ + aCoincidenceToFeature); std::map > aBaseRefAttributes; std::list aRefsToFeature; @@ -118,7 +126,8 @@ void SketchPlugin_ConstraintSplit::execute() std::cout << std::endl; if (!aCoincidenceToFeature.empty()) { - std::cout << "Coincidences to base feature[" << aCoincidenceToFeature.size() << "]: " << std::endl; + std::cout << "Coincidences to base feature[" << + aCoincidenceToFeature.size() << "]: " << std::endl; std::map::const_iterator anIt = aCoincidenceToFeature.begin(), aLast = aCoincidenceToFeature.end(); for (int i = 1; anIt != aLast; anIt++, i++) { @@ -128,29 +137,15 @@ void SketchPlugin_ConstraintSplit::execute() std::cout << i << "-" << getFeatureInfo(aFeature) << std::endl; std::cout << " -Attribute to correct:" << anAttributeId << std::endl; - std::cout << " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl; + std::cout << " -Point attribute:" << + ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl; } } - if (!aTangentFeatures.empty()) { - std::cout << std::endl; - std::cout << "Tangencies to base feature[" << aTangentFeatures.size() << "]: " << std::endl; - std::map::const_iterator anIt = aTangentFeatures.begin(), - aLast = aTangentFeatures.end(); - for (int i = 1; anIt != aLast; anIt++, i++) { - FeaturePtr aFeature = (*anIt).first; - std::string anAttributeId = (*anIt).second.first; - std::shared_ptr aPointAttr = (*anIt).second.second; - - std::cout << i << "-" << getFeatureInfo(aFeature) << std::endl; - std::cout << " -Attribute to correct:" << anAttributeId << std::endl; - std::cout << " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << std::endl; - } - } - - std::map >::const_iterator aRefIt = aBaseRefAttributes.begin(), - aRefLast = aBaseRefAttributes.end(); - std::cout << std::endl << "References to attributes of base feature [" << aBaseRefAttributes.size() << "]" << std::endl; + std::map >::const_iterator + aRefIt = aBaseRefAttributes.begin(), aRefLast = aBaseRefAttributes.end(); + std::cout << std::endl << "References to attributes of base feature [" << + aBaseRefAttributes.size() << "]" << std::endl; for (; aRefIt != aRefLast; aRefIt++) { AttributePtr aBaseAttr = aRefIt->first; std::list aRefAttributes = aRefIt->second; @@ -165,11 +160,14 @@ void SketchPlugin_ConstraintSplit::execute() FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner()); aRefsInfo.append("(" + aRFeature->name() + ") "); } - std::shared_ptr aPointAttr = std::dynamic_pointer_cast(aBaseAttr); - std::cout << aPointAttr->id().c_str() << ": " << "[" << aRefAttributes.size() << "] " << aRefsInfo << std::endl; + std::shared_ptr aPointAttr = + std::dynamic_pointer_cast(aBaseAttr); + std::cout << aPointAttr->id().c_str() << + ": " << "[" << aRefAttributes.size() << "] " << aRefsInfo << std::endl; } std::cout << std::endl; - std::cout << std::endl << "References to base feature [" << aRefsToFeature.size() << "]" << std::endl; + std::cout << std::endl << "References to base feature [" << + aRefsToFeature.size() << "]" << std::endl; std::list::const_iterator aRefAttrIt = aRefsToFeature.begin(), aRefAttrLast = aRefsToFeature.end(); std::string aRefsInfo; @@ -202,13 +200,15 @@ void SketchPlugin_ConstraintSplit::execute() aModifiedAttributes); if (aFeatureKind == SketchPlugin_Circle::ID()) { FeaturePtr aCircleFeature = aBaseFeature; - splitCircle(aSplitFeature, aBaseFeature, anAfterFeature, aFurtherCoincidences, aCreatedFeatures, - aModifiedAttributes); + splitCircle(aSplitFeature, aBaseFeature, anAfterFeature, aFurtherCoincidences, + aCreatedFeatures, aModifiedAttributes); updateRefFeatureConstraints(getFeatureResult(aBaseFeature), aRefsToFeature); + AttributePtr aCenterAttr = aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()); aFeaturesToDelete.insert(aCircleFeature); - aBaseObjectAttr->setObject(ResultPtr()); // as circle is removed, temporary fill this attribute*/ + // as circle is removed, temporary fill this attribute*/ + aBaseObjectAttr->setObject(ResultPtr()); } #ifdef DEBUG_SPLIT @@ -237,8 +237,8 @@ void SketchPlugin_ConstraintSplit::execute() } std::cout << "Modifed attributes (constraints to attributes are moved here):" << std::endl; - std::set >::const_iterator aPIt = aModifiedAttributes.begin(), - aPLast = aModifiedAttributes.end(); + std::set >::const_iterator + aPIt = aModifiedAttributes.begin(), aPLast = aModifiedAttributes.end(); std::string aResInfo; for (; aPIt != aPLast; aPIt++) { if (!aResInfo.empty()) @@ -268,9 +268,7 @@ void SketchPlugin_ConstraintSplit::execute() // coincidence to feature updateCoincidenceConstraintsToFeature(aCoincidenceToFeature, aFurtherCoincidences, - aFeatureResults); - // tangency - updateTangentConstraintsToFeature(aTangentFeatures, aFurtherCoincidences); + aFeatureResults, aSplitFeature); updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes); @@ -285,6 +283,7 @@ void SketchPlugin_ConstraintSplit::execute() } #endif ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete); + Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED)); #ifdef DEBUG_SPLIT std::cout << "update features after split:" << std::endl; @@ -339,24 +338,40 @@ AISObjectPtr SketchPlugin_ConstraintSplit::getAISObject(AISObjectPtr thePrevious aPoints.push_back(aStartPoint); std::shared_ptr aSecondPnt2d = aSecondPointAttrOfSplit->pnt(); - std::shared_ptr aSecondPoint = sketch()->to3D(aSecondPnt2d->x(), aSecondPnt2d->y()); + 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 = GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes); + GeomAlgoAPI_ShapeTools::splitShape_p(aBaseShape, aPoints, aSplitShapes); + std::shared_ptr aShape = + GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes); AISObjectPtr anAIS = thePrevious; if (aShape) { if (!anAIS) anAIS = AISObjectPtr(new GeomAPI_AISObject); anAIS->createShape(aShape); - anAIS->setWidth(5); + std::shared_ptr anAuxiliaryAttr = + aBaseFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID()); + + bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value(); + std::vector aColor; - aColor = Config_PropManager::color("Visualization", "sketch_entity_color", - SKETCH_ENTITY_COLOR); - anAIS->setColor(aColor[0], aColor[1], aColor[2]); + double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH(); + int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE(); + if (isConstruction) { + aColor = Config_PropManager::color("Visualization", "sketch_auxiliary_color"); + aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY(); + aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY(); + } + else { + aColor = Config_PropManager::color("Visualization", "sketch_entity_color"); + } + anAIS->setColor(aColor[0], aColor[1], aColor[2]); + anAIS->setWidth(aWidth + 1); + anAIS->setLineStyle(aLineStyle); } return anAIS; } @@ -364,12 +379,13 @@ AISObjectPtr SketchPlugin_ConstraintSplit::getAISObject(AISObjectPtr thePrevious } std::shared_ptr SketchPlugin_ConstraintSplit::getPointOfRefAttr( - const AttributePtr& theAttribute) + const AttributePtr& theAttribute) { AttributePoint2DPtr aPointAttribute; if (theAttribute->attributeType() == ModelAPI_AttributeRefAttr::typeId()) { - AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast(theAttribute); + AttributeRefAttrPtr aRefAttr = + std::dynamic_pointer_cast(theAttribute); if (aRefAttr.get() && aRefAttr->isInitialized()) { AttributePtr anAttribute = aRefAttr->attr(); if (anAttribute.get() && anAttribute->attributeType() == GeomDataAPI_Point2D::typeId()) @@ -379,16 +395,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(); @@ -400,15 +411,14 @@ 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)); } } void SketchPlugin_ConstraintSplit::getConstraints(std::set& theFeaturesToDelete, std::set& theFeaturesToUpdate, - std::map& theTangentFeatures, std::map& theCoincidenceToFeature) { std::shared_ptr aData = data(); @@ -430,47 +440,11 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set& theFeatu std::string aRefFeatureKind = aRefFeature->getKind(); if (aRefFeatureKind == SketchPlugin_ConstraintMirror::ID() || aRefFeatureKind == SketchPlugin_MultiRotation::ID() || - aRefFeatureKind == SketchPlugin_MultiTranslation::ID()) + aRefFeatureKind == SketchPlugin_MultiTranslation::ID() || + aRefFeatureKind == SketchPlugin_ConstraintMiddle::ID()) theFeaturesToDelete.insert(aRefFeature); else if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) theFeaturesToUpdate.insert(aRefFeature); - else if (aRefFeatureKind == SketchPlugin_ConstraintTangent::ID()) { - if (aBaseFeature->getKind() == SketchPlugin_Circle::ID()) /// TEMPORARY limitaion - theFeaturesToDelete.insert(aRefFeature); /// until tangency between arc and line is implemented - 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 = SketchPlugin_ConstraintCoincidence::findCoincidenceFeature - (ModelAPI_Feature::feature(aResult1), - ModelAPI_Feature::feature(aResult2)); - // get the point not lying on the splitting feature - for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) { - AttributeRefAttrPtr aRefAttr = aCoincidenceFeature->refattr(ATTRIBUTE(i)); - if (!aRefAttr || aRefAttr->isObject()) - continue; - AttributePoint2DPtr aPoint = - std::dynamic_pointer_cast(aRefAttr->attr()); - if (!aPoint) - continue; - if (aPoint->owner() != aBaseFeature) { - aTangentPoint = aPoint; - break; - } - } - } - if (aTangentPoint.get()) { - FeaturePtr aFeature1 = ModelAPI_Feature::feature(aResult1); - std::string anAttributeToBeModified = aFeature1 == aBaseFeature - ? SketchPlugin_Constraint::ENTITY_A() : SketchPlugin_Constraint::ENTITY_B(); - theTangentFeatures[aRefFeature] = std::make_pair(anAttributeToBeModified, aTangentPoint); - } - else - theFeaturesToDelete.insert(aRefFeature); /// there is not coincident point between tangent constraint - } - } else if (aRefFeatureKind == SketchPlugin_ConstraintCoincidence::ID()) { std::string anAttributeToBeModified; AttributePoint2DPtr aCoincidentPoint; @@ -517,27 +491,25 @@ void SketchPlugin_ConstraintSplit::getConstraints(std::set& theFeatu if (anAttribute.get()) aCoincidentPoint = std::dynamic_pointer_cast(anAttribute); } - if (aCoincidentPoint.get()) { - if (isToFeature) - theCoincidenceToFeature[aRefFeature] = std::make_pair(anAttributeToBeModified, - aCoincidentPoint); - } - else - theFeaturesToDelete.insert(aRefFeature); /// this case should not happen + if (aCoincidentPoint.get() && isToFeature) + theCoincidenceToFeature[aRefFeature] = std::make_pair(anAttributeToBeModified, + aCoincidentPoint); } } } void SketchPlugin_ConstraintSplit::getRefAttributes(const FeaturePtr& theFeature, - std::map >& theRefs, - std::list& theRefsToFeature) + std::map >& theRefs, + std::list& theRefsToFeature) { theRefs.clear(); - std::list aPointAttributes = theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); + std::list aPointAttributes = + theFeature->data()->attributes(GeomDataAPI_Point2D::typeId()); std::set aPointAttributesSet; - std::list::const_iterator aPIt = aPointAttributes.begin(), aPLast = aPointAttributes.end(); + std::list::const_iterator aPIt = + aPointAttributes.begin(), aPLast = aPointAttributes.end(); for (; aPIt != aPLast; aPIt++) aPointAttributesSet.insert(*aPIt); @@ -554,7 +526,8 @@ 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() && aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) { + if (anAttrInRef.get() && + aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) { if (theRefs.find(anAttrInRef) != theRefs.end()) theRefs[anAttrInRef].push_back(aRefAttr); else { @@ -574,11 +547,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 @@ -601,6 +584,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 @@ -625,45 +621,9 @@ void SketchPlugin_ConstraintSplit::updateCoincidenceConstraintsToFeature( } } -void SketchPlugin_ConstraintSplit::updateTangentConstraintsToFeature( - const std::map, IdToPointPair>& theTangentFeatures, - const std::set >& theFurtherCoincidences) -{ - if (theTangentFeatures.empty()) - return; - - std::map::const_iterator aTIt = theTangentFeatures.begin(), - aTLast = theTangentFeatures.end(); -#ifdef DEBUG_SPLIT - std::cout << std::endl; - std::cout << "Tangencies to feature(modified):"<< std::endl; -#endif - for (; aTIt != aTLast; aTIt++) { - FeaturePtr aTangentFeature = aTIt->first; - std::string anAttributeId = aTIt->second.first; - AttributePoint2DPtr aTangentPoint = aTIt->second.second; - std::set::const_iterator aFCIt = theFurtherCoincidences.begin(), - aFCLast = theFurtherCoincidences.end(); - std::shared_ptr aCoincPnt = aTangentPoint->pnt(); - AttributePoint2DPtr aFeaturePointAttribute; - /// here we rely on created coincidence between further coincidence point and tangent result - for (; aFCIt != aFCLast && !aFeaturePointAttribute.get(); aFCIt++) { - AttributePoint2DPtr aFCAttribute = *aFCIt; - if (aCoincPnt->isEqual(aFCAttribute->pnt())) - aFeaturePointAttribute = aFCAttribute; - } - if (aFeaturePointAttribute.get()) { - FeaturePtr aFeature = std::dynamic_pointer_cast(aFeaturePointAttribute->owner()); - aTangentFeature->refattr(anAttributeId)->setObject(getFeatureResult(aFeature)); - } -#ifdef DEBUG_SPLIT - std::cout << " -" << getFeatureInfo(aTangentFeature) << std::endl; -#endif - } -} - -void SketchPlugin_ConstraintSplit::updateRefFeatureConstraints(const ResultPtr& theFeatureBaseResult, - const std::list& theRefsToFeature) +void SketchPlugin_ConstraintSplit::updateRefFeatureConstraints( + const ResultPtr& theFeatureBaseResult, + const std::list& theRefsToFeature) { std::list::const_iterator anIt = theRefsToFeature.begin(), aLast = theRefsToFeature.end(); @@ -675,19 +635,20 @@ void SketchPlugin_ConstraintSplit::updateRefFeatureConstraints(const ResultPtr& } void SketchPlugin_ConstraintSplit::updateRefAttConstraints( - const std::map >& theBaseRefAttributes, - const std::set >& theModifiedAttributes) + const std::map >& theBaseRefAttributes, + const std::set >& theModifiedAttributes) { #ifdef DEBUG_SPLIT std::cout << "SketchPlugin_ConstraintSplit::updateRefAttConstraints" << std::endl; #endif - std::set >::const_iterator anIt = theModifiedAttributes.begin(), - aLast = theModifiedAttributes.end(); + std::set >::const_iterator + anIt = theModifiedAttributes.begin(), aLast = theModifiedAttributes.end(); for (; anIt != aLast; anIt++) { AttributePtr anAttribute = anIt->first; - if (theBaseRefAttributes.find(anAttribute) == theBaseRefAttributes.end()) /// not found in references + /// not found in references + if (theBaseRefAttributes.find(anAttribute) == theBaseRefAttributes.end()) continue; std::list aRefAttributes = theBaseRefAttributes.at(anAttribute); std::list::const_iterator aRefIt = aRefAttributes.begin(), @@ -729,33 +690,42 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, if (aFeatureKind != SketchPlugin_Line::ID()) return; - AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + AttributePoint2DPtr aFirstPointAttrOfSplit = + getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); + 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, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); + 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: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aStartPointAttrOfBase) << std::endl; - std::cout << "1st point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aFirstPointAttrOfSplit) << std::endl; - std::cout << "2nd point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aSecondPointAttrOfSplit) << std::endl; - std::cout << "End point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl; + std::cout << "Start point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(aStartPointAttrOfBase) << std::endl; + std::cout << "1st point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(aFirstPointAttrOfSplit) << std::endl; + std::cout << "2nd point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(aSecondPointAttrOfSplit) << std::endl; + std::cout << "End point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl; #endif /// create a split feature - theSplitFeature = createLineFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); + theSplitFeature = + createLineFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); theCreatedFeatures.insert(theSplitFeature); // before split feature if (aStartPointAttrOfBase->pnt()->isEqual(aFirstPointAttrOfSplit->pnt())) { theModifiedAttributes.insert(std::make_pair(aStartPointAttrOfBase, - theSplitFeature->attribute(SketchPlugin_Line::START_ID()))); + theSplitFeature->attribute(SketchPlugin_Line::START_ID()))); } else { theBaseFeatureModified = aBaseFeature; ///< use base feature to store all constraints here @@ -774,7 +744,7 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, aFeature = createLineFeature(aBaseFeature, aSecondPointAttrOfSplit, anEndPointAttrOfBase); theCreatedFeatures.insert(aFeature); theModifiedAttributes.insert(std::make_pair(anEndPointAttrOfBase, - aFeature->attribute(SketchPlugin_Line::END_ID()))); + aFeature->attribute(SketchPlugin_Line::END_ID()))); } aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(), theSplitFeature->attribute(SketchPlugin_Line::END_ID()), @@ -795,14 +765,15 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, thePoints.insert(std::dynamic_pointer_cast (theSplitFeature->attribute(SketchPlugin_Line::END_ID()))); theModifiedAttributes.insert(std::make_pair(anEndPointAttrOfBase, - theSplitFeature->attribute(SketchPlugin_Line::END_ID()))); + theSplitFeature->attribute(SketchPlugin_Line::END_ID()))); } // base split, that is defined before split feature should be changed at end // (after the after feature creation). Otherwise modified value will be used in after feature // before split feature if (!aStartPointAttrOfBase->pnt()->isEqual(aFirstPointAttrOfSplit->pnt())) { /// move end arc point to start of split - fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()), aFirstPointAttrOfSplit); + fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()), + aFirstPointAttrOfSplit); theBaseFeatureModified->execute(); // to update result aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(), theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()), @@ -818,6 +789,7 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, thePoints.insert(std::dynamic_pointer_cast (theSplitFeature->attribute(SketchPlugin_Line::START_ID()))); +#ifdef CREATE_CONSTRAINTS // additional constraints between split and base features aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintParallel::ID(), getFeatureResult(aBaseFeature), @@ -829,6 +801,7 @@ void SketchPlugin_ConstraintSplit::splitLine(FeaturePtr& theSplitFeature, getFeatureResult(theAfterFeature)); theCreatedFeatures.insert(aConstraintFeature); } +#endif } void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, @@ -853,27 +826,29 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, if (aFeatureKind != SketchPlugin_Arc::ID()) return; - AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + AttributePoint2DPtr aFirstPointAttrOfSplit = + getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); + 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; } - // manually change type of arc to avoid incorrect self-constrainting of the tangent arc - aBaseFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue( - SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()); - arrangePointsOnArc(aBaseFeature, 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: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aStartPointAttrOfBase) << std::endl; - std::cout << "1st point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aFirstPointAttrOfSplit) << std::endl; - std::cout << "2nd point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(aSecondPointAttrOfSplit) << std::endl; - std::cout << "End point: " << ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl; + std::cout << "Start point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(aStartPointAttrOfBase) << std::endl; + std::cout << "1st point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(aFirstPointAttrOfSplit) << std::endl; + std::cout << "2nd point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(aSecondPointAttrOfSplit) << std::endl; + std::cout << "End point: " << + ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl; #endif /// split feature @@ -883,7 +858,7 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, // before split feature if (aStartPointAttrOfBase->pnt()->isEqual(aFirstPointAttrOfSplit->pnt())) { theModifiedAttributes.insert(std::make_pair(aStartPointAttrOfBase, - theSplitFeature->attribute(SketchPlugin_Arc::START_ID()))); + theSplitFeature->attribute(SketchPlugin_Arc::START_ID()))); } else { theBaseFeatureModified = aBaseFeature; ///< use base feature to store all constraints here @@ -930,7 +905,8 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, // before split feature if (!aStartPointAttrOfBase->pnt()->isEqual(aFirstPointAttrOfSplit->pnt())) { /// move end arc point to start of split - fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()), aFirstPointAttrOfSplit); + fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()), + aFirstPointAttrOfSplit); theBaseFeatureModified->execute(); // to update result aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(), theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()), @@ -947,6 +923,7 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, (theSplitFeature->attribute(SketchPlugin_Arc::START_ID()))); // additional constraints between split and base features +#ifdef CREATE_CONSTRAINTS aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(), getFeatureResult(aBaseFeature), getFeatureResult(theSplitFeature)); @@ -965,6 +942,7 @@ void SketchPlugin_ConstraintSplit::splitArc(FeaturePtr& theSplitFeature, getFeatureResult(theAfterFeature)); theCreatedFeatures.insert(aConstraintFeature); } +#endif } void SketchPlugin_ConstraintSplit::splitCircle(FeaturePtr& theSplitFeature, @@ -989,21 +967,27 @@ void SketchPlugin_ConstraintSplit::splitCircle(FeaturePtr& theSplitFeature, if (aFeatureKind != SketchPlugin_Circle::ID()) return; - AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); - AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B())); + AttributePoint2DPtr aFirstPointAttrOfSplit = + getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A())); + AttributePoint2DPtr aSecondPointAttrOfSplit = + getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B())); /// split feature - theSplitFeature = createArcFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); + 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, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); - std::dynamic_pointer_cast(theBaseFeatureModified)->setReversed(!aSplitReversed); + theBaseFeatureModified = createArcFeature(aBaseFeature, + aFirstPointAttrOfSplit, aSecondPointAttrOfSplit); + std::dynamic_pointer_cast( + theBaseFeatureModified)->setReversed(!aSplitReversed); theBaseFeatureModified->execute(); - theModifiedAttributes.insert(std::make_pair(aBaseFeature->attribute(SketchPlugin_Circle::CENTER_ID()), - theBaseFeatureModified->attribute(SketchPlugin_Arc::CENTER_ID()))); + theModifiedAttributes.insert( + std::make_pair(aBaseFeature->attribute(SketchPlugin_Circle::CENTER_ID()), + theBaseFeatureModified->attribute(SketchPlugin_Arc::CENTER_ID()))); theCreatedFeatures.insert(theBaseFeatureModified); @@ -1022,10 +1006,12 @@ void SketchPlugin_ConstraintSplit::splitCircle(FeaturePtr& theSplitFeature, theSplitFeature->attribute(SketchPlugin_Arc::START_ID())); theCreatedFeatures.insert(aConstraintFeature); +#ifdef CREATE_CONSTRAINTS aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(), getFeatureResult(theSplitFeature), getFeatureResult(theBaseFeatureModified)); theCreatedFeatures.insert(aConstraintFeature); +#endif } void SketchPlugin_ConstraintSplit::arrangePointsOnLine( @@ -1054,7 +1040,7 @@ void SketchPlugin_ConstraintSplit::arrangePointsOnArc( std::shared_ptr aCenter = std::dynamic_pointer_cast( theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt(); - bool isReversed = theArc->boolean(SketchPlugin_Arc::INVERSED_ID())->value(); + bool isReversed = theArc->boolean(SketchPlugin_Arc::REVERSED_ID())->value(); // collect directions to each point std::shared_ptr aStartDir( @@ -1083,13 +1069,25 @@ void SketchPlugin_ConstraintSplit::arrangePointsOnArc( void SketchPlugin_ConstraintSplit::fillAttribute(const AttributePtr& theModifiedAttribute, const AttributePtr& theSourceAttribute) { - AttributePoint2DPtr aModifiedAttribute = std::dynamic_pointer_cast( - theModifiedAttribute); - AttributePoint2DPtr aSourceAttribute = std::dynamic_pointer_cast( - theSourceAttribute); - - if (aModifiedAttribute.get() && aSourceAttribute.get()) - aModifiedAttribute->setValue(aSourceAttribute->pnt()); + std::string anAttributeType = theModifiedAttribute->attributeType(); + if (anAttributeType == GeomDataAPI_Point2D::typeId()) { + AttributePoint2DPtr aModifiedAttribute = std::dynamic_pointer_cast( + theModifiedAttribute); + AttributePoint2DPtr aSourceAttribute = std::dynamic_pointer_cast( + theSourceAttribute); + + if (aModifiedAttribute.get() && aSourceAttribute.get()) + aModifiedAttribute->setValue(aSourceAttribute->pnt()); + } + else if (anAttributeType == ModelAPI_AttributeBoolean::typeId()) { + AttributeBooleanPtr aModifiedAttribute = std::dynamic_pointer_cast( + theModifiedAttribute); + AttributeBooleanPtr aSourceAttribute = std::dynamic_pointer_cast( + theSourceAttribute); + + if (aModifiedAttribute.get() && aSourceAttribute.get()) + aModifiedAttribute->setValue(aSourceAttribute->value()); + } } FeaturePtr SketchPlugin_ConstraintSplit::createLineFeature(const FeaturePtr& theBaseFeature, @@ -1105,6 +1103,10 @@ FeaturePtr SketchPlugin_ConstraintSplit::createLineFeature(const FeaturePtr& the fillAttribute(aFeature->attribute(SketchPlugin_Line::START_ID()), theFirstPointAttr); fillAttribute(aFeature->attribute(SketchPlugin_Line::END_ID()), theSecondPointAttr); + + fillAttribute(aFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()), + theBaseFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID())); + aFeature->execute(); // to obtain result return aFeature; @@ -1129,24 +1131,25 @@ 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 the "attribute updated" + // 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); - - aFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue( - SketchPlugin_Arc::ARC_TYPE_CENTER_START_END()); + bool aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true); fillAttribute(aFeature->attribute(SketchPlugin_Arc::CENTER_ID()), theBaseFeature->attribute(aCenterAttributeId)); fillAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), theFirstPointAttr); fillAttribute(aFeature->attribute(SketchPlugin_Arc::END_ID()), theSecondPointAttr); + fillAttribute(aFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID()), + theBaseFeature->attribute(SketchPlugin_SketchEntity::AUXILIARY_ID())); + /// fill referersed state of created arc as it is on the base arc if (theBaseFeature->getKind() == SketchPlugin_Arc::ID()) { - bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->value(); - aFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->setValue(aReversed); + bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value(); + aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed); } - aFeature->data()->blockSendAttributeUpdated(false); + aFeature->data()->blockSendAttributeUpdated(aWasBlocked); aFeature->execute(); // to obtain result return aFeature; @@ -1168,7 +1171,8 @@ FeaturePtr SketchPlugin_ConstraintSplit::createConstraint(const std::string& the return aConstraint; } -FeaturePtr SketchPlugin_ConstraintSplit::createConstraintForObjects(const std::string& theConstraintId, +FeaturePtr SketchPlugin_ConstraintSplit::createConstraintForObjects( + const std::string& theConstraintId, const ObjectPtr& theFirstObject, const ObjectPtr& theSecondObject) { @@ -1242,7 +1246,7 @@ std::set > SketchPlugin_ConstraintSplit::get return anAttributes; } - +#ifdef _DEBUG std::string SketchPlugin_ConstraintSplit::getFeatureInfo( const std::shared_ptr& theFeature, const bool isUseAttributesInfo) @@ -1258,14 +1262,15 @@ std::string SketchPlugin_ConstraintSplit::getFeatureInfo( if (isUseAttributesInfo) { std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(theFeature, getEdgeAttributes(theFeature)); - if (!aPointsInfo.empty()) { /// processing of feature with point 2d attributes, like line, arc, circle + /// processing of feature with point 2d attributes, like line, arc, circle + if (!aPointsInfo.empty()) { anInfo += ": "; anInfo += "\n"; anInfo += aPointsInfo; } else { /// process constraint coincidence, find points in ref attr attributes std::list anAttrs = theFeature->data()->attributes( - ModelAPI_AttributeRefAttr::typeId()); + ModelAPI_AttributeRefAttr::typeId()); std::list::const_iterator anIt = anAttrs.begin(), aLast = anAttrs.end(); std::string anAttributesInfo; for(; anIt != aLast; anIt++) { @@ -1278,7 +1283,7 @@ std::string SketchPlugin_ConstraintSplit::getFeatureInfo( std::string aType = anAttr->attributeType(); if (aType == ModelAPI_AttributeRefAttr::typeId()) { std::shared_ptr aRefAttr = - std::dynamic_pointer_cast(anAttr); + std::dynamic_pointer_cast(anAttr); if (aRefAttr.get()) { if (aRefAttr->isObject()) { FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->object()); @@ -1302,4 +1307,4 @@ std::string SketchPlugin_ConstraintSplit::getFeatureInfo( } return anInfo; } - +#endif