std::shared_ptr<GeomAPI_XY>& theTangentA,
std::shared_ptr<GeomAPI_XY>& theTangentB);
-/// Get coincide edges for fillet
-static std::set<FeaturePtr> getCoincides(const FeaturePtr& theConstraintCoincidence);
-
static std::set<FeaturePtr> findFeaturesToRemove(const FeaturePtr theFeature,
const AttributePtr theAttribute);
// set flag here to avoid building Fillet presentation if "Redisplay" event appears
myFilletCreated = true;
- // Calculate Fillet parameters if does not yet
- if (!myBaseFeatures[0] || !myBaseFeatures[1])
- calculateFilletParameters();
-
- // Create arc feature.
- FeaturePtr aFilletArc = sketch()->addFeature(SketchPlugin_Arc::ID());
-
- // Set arc attributes.
- bool aWasBlocked = aFilletArc->data()->blockSendAttributeUpdated(true);
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFilletArc->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenterXY->x(),
- myCenterXY->y());
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFilletArc->attribute(SketchPlugin_Arc::START_ID()));
- std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFilletArc->attribute(SketchPlugin_Arc::END_ID()));
- if(aStartPoint->isInitialized() && aEndPoint->isInitialized()
- && (aStartPoint->pnt()->xy()->distance(myTangentXY1) > tolerance
- || aEndPoint->pnt()->xy()->distance(myTangentXY2) > tolerance)) {
- std::dynamic_pointer_cast<SketchPlugin_Arc>(aFilletArc)->setReversed(false);
- }
- aStartPoint->setValue(myTangentXY1->x(), myTangentXY1->y());
- aEndPoint->setValue(myTangentXY2->x(), myTangentXY2->y());
- aFilletArc->data()->blockSendAttributeUpdated(aWasBlocked);
- aFilletArc->execute();
+ // create feature for fillet arc
+ FeaturePtr aFilletArc = createFilletArc();
// Delete features with refs to points of edges.
std::shared_ptr<GeomDataAPI_Point2D> aStartPoint1;
recalculateAttributes(aFilletArc, SketchPlugin_Arc::END_ID(),
myBaseFeatures[aFeatInd2], myFeatAttributes[anAttrInd2]);
+ FeaturePtr aConstraint;
+
// Create coincidence features.
- FeaturePtr aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(aFilletArc->attribute(SketchPlugin_Arc::START_ID()));
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setAttr(myBaseFeatures[aFeatInd1]->attribute(myFeatAttributes[anAttrInd1]));
- aConstraint->execute();
+ aConstraint = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
+ aFilletArc->attribute(SketchPlugin_Arc::START_ID()),
+ myBaseFeatures[aFeatInd1]->attribute(myFeatAttributes[anAttrInd1]));
ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
- aConstraint = sketch()->addFeature(SketchPlugin_ConstraintCoincidence::ID());
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(aFilletArc->attribute(SketchPlugin_Arc::END_ID()));
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setAttr(myBaseFeatures[aFeatInd2]->attribute(myFeatAttributes[anAttrInd2]));
- aConstraint->execute();
+ aConstraint = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
+ aFilletArc->attribute(SketchPlugin_Arc::END_ID()),
+ myBaseFeatures[aFeatInd2]->attribute(myFeatAttributes[anAttrInd2]));
ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
// Create tangent features.
for (int i = 0; i < 2; i++) {
- aConstraint = sketch()->addFeature(SketchPlugin_ConstraintTangent::ID());
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setObject(aFilletArc->lastResult());
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- bool isArc = myBaseFeatures[i]->getKind() == SketchPlugin_Arc::ID();
- aRefAttr->setObject(isArc ? myBaseFeatures[i]->lastResult() :
- myBaseFeatures[i]->firstResult());
+ aConstraint = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintTangent::ID(),
+ aFilletArc->lastResult(),
+ myBaseFeatures[i]->lastResult());
aConstraint->execute();
ModelAPI_EventCreator::get()->sendUpdated(aConstraint, anUpdateEvent);
}
if (!aFilletPoint2D.get())
return false;
- if (!findFeaturesContainingFilletPoint(aFilletPoint2D)) {
+ std::set<FeaturePtr> aFilletFeatures =
+ SketchPlugin_Tools::findFeaturesCoincidentToPoint(aFilletPoint2D);
+ if (aFilletFeatures.size() != 2) {
setError("Error: Selected point does not have two suitable edges for fillet.");
return false;
}
+ std::set<FeaturePtr>::iterator aFIt = aFilletFeatures.begin();
+ myBaseFeatures[0] = *aFIt;
+ myBaseFeatures[1] = *(++aFIt);
+
std::shared_ptr<GeomAPI_Pnt2d> aFilletPnt2d = aFilletPoint2D->pnt();
double aRadius = calculateFilletRadius(myBaseFeatures);
return true;
}
-bool SketchPlugin_Fillet::findFeaturesContainingFilletPoint(
- std::shared_ptr<GeomDataAPI_Point2D> theFilletPoint)
+FeaturePtr SketchPlugin_Fillet::createFilletArc()
{
- // Obtain constraint coincidence for the fillet point.
- FeaturePtr aConstraintCoincidence;
- const std::set<AttributePtr>& aRefsList = theFilletPoint->owner()->data()->refsToMe();
- for(std::set<AttributePtr>::const_iterator anIt = aRefsList.cbegin();
- anIt != aRefsList.cend();
- ++anIt) {
- std::shared_ptr<ModelAPI_Attribute> anAttr = (*anIt);
- FeaturePtr aFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(anAttr->owner());
- if(aFeature->getKind() == SketchPlugin_ConstraintCoincidence::ID()) {
- AttributeRefAttrPtr anAttrRefA =
- aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_A());
- AttributeRefAttrPtr anAttrRefB =
- aFeature->refattr(SketchPlugin_ConstraintCoincidence::ENTITY_B());
- if(anAttrRefA.get() && !anAttrRefA->isObject()) {
- AttributePtr anAttrA = anAttrRefA->attr();
- if(theFilletPoint == anAttrA) {
- aConstraintCoincidence = aFeature;
- break;
- }
- }
- if(anAttrRefB.get() && !anAttrRefB->isObject()) {
- AttributePtr anAttrB = anAttrRefB->attr();
- if(theFilletPoint == anAttrB) {
- aConstraintCoincidence = aFeature;
- break;
- }
- }
- }
- }
+ // Calculate Fillet parameters if does not yet
+ if (!myBaseFeatures[0] || !myBaseFeatures[1])
+ calculateFilletParameters();
- if(!aConstraintCoincidence.get())
- return false;
+ // Create arc feature.
+ FeaturePtr aFilletArc = sketch()->addFeature(SketchPlugin_Arc::ID());
- // Get coincide edges.
- std::set<FeaturePtr> anEdgeFeatures = getCoincides(aConstraintCoincidence);
- std::set<FeaturePtr>::iterator aLinesIt = anEdgeFeatures.begin();
- for (int i = 0; aLinesIt != anEdgeFeatures.end() && i < 2; ++aLinesIt, ++i)
- myBaseFeatures[i] = *aLinesIt;
+ // Set arc attributes.
+ bool aWasBlocked = aFilletArc->data()->blockSendAttributeUpdated(true);
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFilletArc->attribute(SketchPlugin_Arc::CENTER_ID()))->setValue(myCenterXY->x(),
+ myCenterXY->y());
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFilletArc->attribute(SketchPlugin_Arc::START_ID()));
+ std::shared_ptr<GeomDataAPI_Point2D> aEndPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ aFilletArc->attribute(SketchPlugin_Arc::END_ID()));
+ if(aStartPoint->isInitialized() && aEndPoint->isInitialized()
+ && (aStartPoint->pnt()->xy()->distance(myTangentXY1) > tolerance
+ || aEndPoint->pnt()->xy()->distance(myTangentXY2) > tolerance)) {
+ std::dynamic_pointer_cast<SketchPlugin_Arc>(aFilletArc)->setReversed(false);
+ }
+ aStartPoint->setValue(myTangentXY1->x(), myTangentXY1->y());
+ aEndPoint->setValue(myTangentXY2->x(), myTangentXY2->y());
+ aFilletArc->data()->blockSendAttributeUpdated(aWasBlocked);
+ aFilletArc->execute();
- return myBaseFeatures[0] && myBaseFeatures[1];
+ return aFilletArc;
}
// ========= Auxiliary functions =================
return std::min(aLengths[0], aLengths[1]) / 6.0;
}
-std::set<FeaturePtr> getCoincides(const FeaturePtr& theConstraintCoincidence)
-{
- std::set<FeaturePtr> aCoincides;
-
- std::shared_ptr<GeomAPI_Pnt2d> aFilletPnt =
- SketchPlugin_Tools::getCoincidencePoint(theConstraintCoincidence);
-
- SketchPlugin_Tools::findCoincidences(theConstraintCoincidence,
- SketchPlugin_ConstraintCoincidence::ENTITY_A(),
- aCoincides,
- true);
- SketchPlugin_Tools::findCoincidences(theConstraintCoincidence,
- SketchPlugin_ConstraintCoincidence::ENTITY_B(),
- aCoincides,
- true);
-
- // Remove points from set of coincides.
- std::set<FeaturePtr> aNewSetOfCoincides;
- for(std::set<FeaturePtr>::iterator anIt = aCoincides.begin(); anIt != aCoincides.end(); ++anIt) {
- std::shared_ptr<SketchPlugin_SketchEntity> aSketchEntity =
- std::dynamic_pointer_cast<SketchPlugin_SketchEntity>(*anIt);
- if(aSketchEntity.get() && (aSketchEntity->isCopy() || aSketchEntity->isExternal())) {
- continue;
- }
- if((*anIt)->getKind() == SketchPlugin_Line::ID()) {
- aNewSetOfCoincides.insert(*anIt);
- } else if((*anIt)->getKind() == SketchPlugin_Arc::ID()) {
- AttributePtr anAttrCenter = (*anIt)->attribute(SketchPlugin_Arc::CENTER_ID());
- std::shared_ptr<GeomDataAPI_Point2D> aPointCenter2D =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttrCenter);
- if(aPointCenter2D.get() && aFilletPnt->isEqual(aPointCenter2D->pnt())) {
- continue;
- }
- aNewSetOfCoincides.insert(*anIt);
- }
- }
- aCoincides = aNewSetOfCoincides;
-
- // If we still have more than two coincides remove auxilary entities from set of coincides.
- if(aCoincides.size() > 2) {
- aNewSetOfCoincides.clear();
- for(std::set<FeaturePtr>::iterator
- anIt = aCoincides.begin(); anIt != aCoincides.end(); ++anIt) {
- if(!(*anIt)->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID())->value()) {
- aNewSetOfCoincides.insert(*anIt);
- }
- }
- aCoincides = aNewSetOfCoincides;
- }
-
- return aCoincides;
-}
-
std::set<FeaturePtr> findFeaturesToRemove(const FeaturePtr theFeature,
const AttributePtr theAttribute) {
std::set<FeaturePtr> aFeaturesToBeRemoved;
private:
bool calculateFilletParameters();
+ /// Create new feature presenting a fillet arc and initialize its parameters
+ FeaturePtr createFilletArc();
+
+ void createCoincidenceWithFilletArc();
+
bool findFeaturesContainingFilletPoint(std::shared_ptr<GeomDataAPI_Point2D> theFilletPoint);
private:
// Create constraints.
std::string anArcType = string(ARC_TYPE())->value();
if(anArcType == ARC_TYPE_BY_CENTER_AND_POINTS()) {
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
CENTER_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
START_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
END_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
ObjectPtr(),
false);
} else if(anArcType == ARC_TYPE_BY_THREE_POINTS()) {
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
START_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
END_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
ObjectPtr(),
false);
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
PASSED_POINT_REF_ID(),
AttributePtr(),
anArcFeature->lastResult(),
true);
} else if(anArcType == ARC_TYPE_BY_TANGENT_EDGE()) {
// constraints for tangent arc
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
TANGENT_POINT_ID(),
anArcFeature->attribute(SketchPlugin_Arc::START_ID()),
ObjectPtr(),
AttributeRefAttrPtr aRefAttrB = aTangent->refattr(SketchPlugin_Constraint::ENTITY_B());
aRefAttrB->setObject(anArcFeature->lastResult());
// constraint for end point
- SketchPlugin_Tools::createConstraint(this,
+ SketchPlugin_Tools::createCoincidenceOrTangency(this,
END_POINT_REF_ID(),
anArcFeature->attribute(SketchPlugin_Arc::END_ID()),
ObjectPtr(),
void SketchPlugin_MacroCircle::constraintsForCircleByCenterAndPassed(FeaturePtr theCircleFeature)
{
// Create constraints.
- SketchPlugin_Tools::createConstraint(
+ SketchPlugin_Tools::createCoincidenceOrTangency(
this, CENTER_POINT_REF_ID(),
theCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID()),
ObjectPtr(), false);
- SketchPlugin_Tools::createConstraint(
+ SketchPlugin_Tools::createCoincidenceOrTangency(
this, PASSED_POINT_REF_ID(), AttributePtr(),
theCircleFeature->lastResult(), true);
}
// Create constraints.
ResultPtr aCircleResult = theCircleFeature->lastResult();
- for (int i = 0; i < 3; ++i)
- SketchPlugin_Tools::createConstraint(this, aPointRef[i], AttributePtr(), aCircleResult, true);
+ for (int i = 0; i < 3; ++i) {
+ SketchPlugin_Tools::createCoincidenceOrTangency(
+ this, aPointRef[i], AttributePtr(), aCircleResult, true);
+ }
}
FeaturePtr SketchPlugin_MacroCircle::createCircleFeature()
void SketchPlugin_MacroEllipse::constraintsForEllipse(FeaturePtr theEllipseFeature)
{
// Create constraints.
- SketchPlugin_Tools::createConstraint(
+ SketchPlugin_Tools::createCoincidenceOrTangency(
this, CENTER_POINT_REF_ID(),
theEllipseFeature->attribute(SketchPlugin_Ellipse::CENTER_ID()),
ObjectPtr(), false);
- SketchPlugin_Tools::createConstraint(
+ SketchPlugin_Tools::createCoincidenceOrTangency(
this, MAJOR_AXIS_POINT_REF_ID(), AttributePtr(),
theEllipseFeature->lastResult(), true);
- SketchPlugin_Tools::createConstraint(
+ SketchPlugin_Tools::createCoincidenceOrTangency(
this, PASSED_POINT_REF_ID(), AttributePtr(),
theEllipseFeature->lastResult(), true);
}
#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Tools.h>
#include <ModelGeomAlgo_Point2D.h>
#include <ModelAPI_EventReentrantMessage.h>
//#define CREATE_CONSTRAINTS
-//#define DEBUG_SPLIT
#ifdef DEBUG_SPLIT
#include <iostream>
#endif
}
if (aFeaturePointAttribute.get()) {
// create new constraint and remove the current
- aCoincFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aCoincFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
aFeaturePointAttribute, aCoincFeature->refattr(aSecondAttribute)->attr());
theFeaturesToDelete.insert(aCIt->first);
// create new coincidences to split feature points
for (; aSFIt != aSFLast; aSFIt++) {
AttributePoint2DPtr aSFAttribute = *aSFIt;
if (aCoincPnt->isEqual(aSFAttribute->pnt())) {
- createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ SketchPlugin_Tools::createConstraint(sketch(), SketchPlugin_ConstraintCoincidence::ID(),
aSFAttribute, aCoincFeature->refattr(aSecondAttribute)->attr());
}
}
aFeature->attribute(SketchPlugin_Line::END_ID())));
anNewFeature = aFeature;
}
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theSplitFeature->attribute(SketchPlugin_Line::END_ID()),
aFeature->attribute(SketchPlugin_Line::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()),
aFirstPointAttrOfSplit);
theBaseFeatureModified->execute(); // to update result
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()),
theSplitFeature->attribute(SketchPlugin_Line::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
#ifdef CREATE_CONSTRAINTS
// additional constraints between split and base features
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintParallel::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theSplitFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintParallel::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theSplitFeature));
theCreatedFeatures.insert(aConstraintFeature);
if (theAfterFeature.get()) {
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintParallel::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theAfterFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintParallel::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theAfterFeature));
theCreatedFeatures.insert(aConstraintFeature);
}
#endif
aFeature->attribute(SketchPlugin_Arc::END_ID())));
anNewFeature = aFeature;
}
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theSplitFeature->attribute(SketchPlugin_Arc::END_ID()),
aFeature->attribute(SketchPlugin_Arc::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()),
aFirstPointAttrOfSplit);
theBaseFeatureModified->execute(); // to update result
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()),
theSplitFeature->attribute(SketchPlugin_Arc::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
// additional constraints between split and base features
#ifdef CREATE_CONSTRAINTS
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theSplitFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintEqual::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theSplitFeature));
theCreatedFeatures.insert(aConstraintFeature);
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(aBaseFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintTangent::ID(),
+ getFeatureResult(theSplitFeature),
+ getFeatureResult(aBaseFeature));
theCreatedFeatures.insert(aConstraintFeature);
if (theAfterFeature.get()) {
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theAfterFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintEqual::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theAfterFeature));
theCreatedFeatures.insert(aConstraintFeature);
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(theAfterFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintTangent::ID(),
+ getFeatureResult(theSplitFeature),
+ getFeatureResult(theAfterFeature));
theCreatedFeatures.insert(aConstraintFeature);
}
#endif
(theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID())));
// additional constraints between split and base features
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()),
theSplitFeature->attribute(SketchPlugin_Arc::END_ID()));
theCreatedFeatures.insert(aConstraintFeature);
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Arc::START_ID()),
theSplitFeature->attribute(SketchPlugin_Arc::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
#ifdef CREATE_CONSTRAINTS
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(theBaseFeatureModified));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintTangent::ID(),
+ getFeatureResult(theSplitFeature),
+ getFeatureResult(theBaseFeatureModified));
theCreatedFeatures.insert(aConstraintFeature);
#endif
return anNewFeature;
return aFeature;
}
-FeaturePtr SketchPlugin_Split::createConstraint(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const AttributePtr& theSecondAttribute)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setAttr(theSecondAttribute);
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Split::createConstraintForObjects(
- const std::string& theConstraintId,
- const ObjectPtr& theFirstObject,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setObject(theFirstObject);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
- return aConstraint;
-}
-
void SketchPlugin_Split::updateFeaturesAfterSplit(
const std::set<FeaturePtr>& theFeaturesToUpdate)
{
const AttributePtr& theFirstPointAttr,
const AttributePtr& theSecondPointAttr);
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theSecondAttribute an attribute of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
- const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
-
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theFirstAttribute an attribute of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Object>& theFirstObject,
- const std::shared_ptr<ModelAPI_Object>& theSecondObject);
-
/// Add feature coincidence constraint between given attributes
/// \param theFeaturesToUpdate a constraint index
void updateFeaturesAfterSplit(const std::set<FeaturePtr>& theFeaturesToUpdate);
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
+#ifdef DEBUG_TRIM
+#include <iostream>
+#endif
+
namespace SketchPlugin_Tools {
void clearExpressions(AttributeDoublePtr theAttribute)
}
}
-void createConstraint(SketchPlugin_Feature* theFeature,
- const std::string& theId,
- const AttributePtr theAttr,
- const ObjectPtr theObject,
- const bool theIsCanBeTangent)
+void createCoincidenceOrTangency(SketchPlugin_Feature* theFeature,
+ const std::string& theId,
+ const AttributePtr theAttr,
+ const ObjectPtr theObject,
+ const bool theIsCanBeTangent)
{
AttributeRefAttrPtr aRefAttr = theFeature->refattr(theId);
if(aRefAttr.get() && aRefAttr->isInitialized()) {
thePassingPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(anAttr)->pnt();
}
+
+FeaturePtr createConstraint(SketchPlugin_Sketch* theSketch,
+ const std::string& theConstraintId,
+ const AttributePtr& theFirstAttribute,
+ const AttributePtr& theSecondAttribute)
+{
+ FeaturePtr aConstraint = theSketch->addFeature(theConstraintId);
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ aRefAttr->setAttr(theFirstAttribute);
+
+ aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ aRefAttr->setAttr(theSecondAttribute);
+
+#if defined(DEBUG_TRIM) || defined(DEBUG_SPLIT)
+ std::cout << "<createConstraint to attribute> :"
+ << " first attribute - " << theFirstAttribute->id()
+ << " second attribute - " << theSecondAttribute->id()
+ << std::endl;
+#endif
+
+ return aConstraint;
+}
+
+FeaturePtr createConstraint(SketchPlugin_Sketch* theSketch,
+ const std::string& theConstraintId,
+ const AttributePtr& theFirstAttribute,
+ const ObjectPtr& theSecondObject)
+{
+ FeaturePtr aConstraint = theSketch->addFeature(theConstraintId);
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ aRefAttr->setAttr(theFirstAttribute);
+
+ aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ aRefAttr->setObject(theSecondObject);
+
+#if defined(DEBUG_TRIM) || defined(DEBUG_SPLIT)
+ std::cout << "<createConstraint to attribute> :"
+ << " first attribute - " << theFirstAttribute->id()
+ << " second object - " << ModelAPI_Feature::feature(theSecondObject)->getKind()
+ << std::endl;
+#endif
+
+ return aConstraint;
+}
+
+FeaturePtr createConstraint(SketchPlugin_Sketch* theSketch,
+ const std::string& theConstraintId,
+ const ObjectPtr& theFirstObject,
+ const ObjectPtr& theSecondObject)
+{
+ FeaturePtr aConstraint = theSketch->addFeature(theConstraintId);
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ aRefAttr->setObject(theFirstObject);
+
+ aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ aRefAttr->setObject(theSecondObject);
+
+#if defined(DEBUG_TRIM) || defined(DEBUG_SPLIT)
+ std::cout << "<createConstraint to attribute> :"
+ << " first object - " << ModelAPI_Feature::feature(theFirstObject)->getKind()
+ << " second object - " << ModelAPI_Feature::feature(theSecondObject)->getKind()
+ << std::endl;
+#endif
+
+ return aConstraint;
+}
+
} // namespace SketchPlugin_Tools
#include <GeomDataAPI_Point2D.h>
class SketchPlugin_Feature;
+class SketchPlugin_Sketch;
namespace SketchPlugin_Tools {
void resetAttribute(SketchPlugin_Feature* theFeature, const std::string& theId);
+/// Create new constraint between given attributes
+/// \param[in] theSketch a sketch where the constraint will be created
+/// \param[in] theConstraintId a constraint identifier
+/// \param[in] theFirstAttribute an attribute of further constraint
+/// \param[in] theSecondAttribute an attribute of further constraint
+FeaturePtr createConstraint(SketchPlugin_Sketch* theSketch,
+ const std::string& theConstraintId,
+ const AttributePtr& theFirstAttribute,
+ const AttributePtr& theSecondAttribute);
+
+/// Create new constraint between given attribute and object
+/// \param[in] theSketch a sketch where the constraint will be created
+/// \param[in] theConstraintId a constraint identifier
+/// \param[in] theFirstAttribute an attribute of further constraint
+/// \param[in] theSecondObject an attribute of further constraint
+FeaturePtr createConstraint(SketchPlugin_Sketch* theSketch,
+ const std::string& theConstraintId,
+ const AttributePtr& theFirstAttribute,
+ const ObjectPtr& theSecondObject);
+
+/// Create new constraint between given objects
+/// \param[in] theSketch a sketch where the constraint will be created
+/// \param[in] theConstraintId a constraint identifier
+/// \param[in] theFirstObject an attribute of further constraint
+/// \param[in] theSecondObject an attribute of further constraint
+FeaturePtr createConstraint(SketchPlugin_Sketch* theSketch,
+ const std::string& theConstraintId,
+ const ObjectPtr& theFirstObject,
+ const ObjectPtr& theSecondObject);
+
/// Creates coincidence or tangent constraint.
/// \param[in] theFeature to get selected attribute or object
/// \param[in] theId ID of attribute where selection is.
/// \param[in] theObject object for constraint
/// \param[in] theIsCanBeTangent if true constraint can be tangent or coincidence, depending on
/// the selection in the attribute with passed ID.
-void createConstraint(SketchPlugin_Feature* theFeature,
- const std::string& theId,
- const AttributePtr theAttr,
- const ObjectPtr theObject,
- const bool theIsCanBeTangent);
+void createCoincidenceOrTangency(SketchPlugin_Feature* theFeature,
+ const std::string& theId,
+ const AttributePtr theAttr,
+ const ObjectPtr theObject,
+ const bool theIsCanBeTangent);
/// Creates passing point or tangent curve basing on the given attributes are initialized.
/// \param[in] theRefAttr prefered attribute to be converted
#include <SketchPlugin_Circle.h>
#include <SketchPlugin_ConstraintCoincidence.h>
#include <SketchPlugin_ConstraintEqual.h>
-//#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintTangent.h>
#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintMirror.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Point.h>
#include <SketchPlugin_Projection.h>
+#include <SketchPlugin_Tools.h>
#include <ModelAPI_EventReentrantMessage.h>
#include <cmath>
-//#define DEBUG_TRIM_METHODS
-//#define DEBUG_TRIM
-
#ifdef DEBUG_TRIM
#include <iostream>
#endif
const std::list<ObjectPtr>& anObjects = anInfo.second;
for (std::list<ObjectPtr>::const_iterator anObjectIt = anObjects.begin();
anObjectIt != anObjects.end(); anObjectIt++) {
- createConstraintToObject(SketchPlugin_ConstraintCoincidence::ID(), aPointAttribute,
- *anObjectIt);
+ SketchPlugin_Tools::createConstraint(sketch(), SketchPlugin_ConstraintCoincidence::ID(),
+ aPointAttribute, *anObjectIt);
}
}
std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
if (aPoint2d->isEqual(aRefPnt2d)) {
// create new coincidence and then remove the old one
- createConstraint(SketchPlugin_ConstraintCoincidence::ID(), aRefPointAttr, aPointAttribute);
+ SketchPlugin_Tools::createConstraint(sketch(), SketchPlugin_ConstraintCoincidence::ID(),
+ aRefPointAttr, aPointAttribute);
theFeaturesToDelete.insert(aFeature);
}
}
(aBaseFeature->attribute(aModifiedAttribute)));
// Collinear constraint for lines
- createConstraintForObjects(SketchPlugin_ConstraintCollinear::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(anNewFeature));
-
+ SketchPlugin_Tools::createConstraint(sketch(), SketchPlugin_ConstraintCollinear::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(anNewFeature));
}
return anNewFeature;
}
(aBaseFeature->attribute(aModifiedAttribute)));
// equal Radius constraint for arcs
- createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(anNewFeature));
+ SketchPlugin_Tools::createConstraint(sketch(), SketchPlugin_ConstraintEqual::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(anNewFeature));
// coincident centers constraint
- createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
- aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
- anNewFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
+ SketchPlugin_Tools::createConstraint(sketch(), SketchPlugin_ConstraintCoincidence::ID(),
+ aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
+ anNewFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
#ifdef DEBUG_TRIM
std::cout << "Created arc on points:" << std::endl;
return aFeature;
}
-FeaturePtr SketchPlugin_Trim::createConstraint(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const AttributePtr& theSecondAttribute)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setAttr(theSecondAttribute);
-
-#ifdef DEBUG_TRIM
- std::cout << "<createConstraint to attribute> :"
- << "first attribute - " << theFirstAttribute->id()
- << "second attribute - " << theSecondAttribute->id()
- << std::endl;
-#endif
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Trim::createConstraintToObject(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
-#ifdef DEBUG_TRIM
- std::cout << "<createConstraint to attribute> :"
- << "first attribute - " << theFirstAttribute->id()
- << "second object - " << ModelAPI_Feature::feature(theSecondObject)->getKind()
- << std::endl;
-#endif
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Trim::createConstraintForObjects(
- const std::string& theConstraintId,
- const ObjectPtr& theFirstObject,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setObject(theFirstObject);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
- return aConstraint;
-}
-
std::shared_ptr<ModelAPI_Result> SketchPlugin_Trim::getFeatureResult(
const std::shared_ptr<ModelAPI_Feature>& theFeature)
{
const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint);
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theSecondAttribute an attribute of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraint(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
- const std::shared_ptr<ModelAPI_Attribute>& theSecondAttribute);
-
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theSecondObject an object of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraintToObject(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Attribute>& theFirstAttribute,
- const std::shared_ptr<ModelAPI_Object>& theSecondObject);
-
- /// Add feature coincidence constraint between given attributes
- /// \param theConstraintId a constraint index
- /// \param theFirstAttribute an attribute of further coincidence
- /// \param theFirstAttribute an attribute of further coincidence
- std::shared_ptr<ModelAPI_Feature> createConstraintForObjects(const std::string& theConstraintId,
- const std::shared_ptr<ModelAPI_Object>& theFirstObject,
- const std::shared_ptr<ModelAPI_Object>& theSecondObject);
-
/// Result result of the feature to build constraint with. For arc, circle it is an edge result.
/// \param theFeature a feature
/// \return result object