Move similar methods to SketchPlugin_SegmentationTools namespace.
#include <Geom_Ellipse.hxx>
#include <Geom_Line.hxx>
#include <Geom_TrimmedCurve.hxx>
+#include <GeomAPI_ProjectPointOnCurve.hxx>
#include <BRep_Tool.hxx>
#include <TopoDS_Edge.hxx>
#include <TopoDS.hxx>
}
// LCOV_EXCL_STOP
+
+const std::shared_ptr<GeomAPI_Pnt> GeomAPI_Curve::project(
+ const std::shared_ptr<GeomAPI_Pnt>& thePoint) const
+{
+ std::shared_ptr<GeomAPI_Pnt> aResult;
+ if (MY_CURVE.IsNull())
+ return aResult;
+
+ const gp_Pnt& aPoint = thePoint->impl<gp_Pnt>();
+
+ GeomAPI_ProjectPointOnCurve aProj(aPoint, MY_CURVE);
+ Standard_Integer aNbPoint = aProj.NbPoints();
+ if (aNbPoint > 0) {
+ gp_Pnt aNearest = aProj.NearestPoint();
+ aResult = GeomPointPtr(new GeomAPI_Pnt(aNearest.X(), aNearest.Y(), aNearest.Z()));
+ }
+ return aResult;
+}
+
// ================================================================================================
bool GeomAPI_Curve::Comparator::operator()(const GeomCurvePtr& theCurve1,
GEOMAPI_EXPORT
std::shared_ptr<GeomAPI_Pnt> getPoint(double theParam);
+ /// Project point on curve
+ GEOMAPI_EXPORT const std::shared_ptr<GeomAPI_Pnt> project(
+ const std::shared_ptr<GeomAPI_Pnt>& thePoint) const;
+
public:
/// \brief Compare addresses of curves
class Comparator
{
bool isInside = false;
if (theBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theBaseShape));
- if (anEdge->isLine()) {
- std::shared_ptr<GeomAPI_Lin> aLine = anEdge->line();
- theProjectedPoint = aLine->project(thePoint);
- }
- else if (anEdge->isCircle() || anEdge->isArc()) {
- std::shared_ptr<GeomAPI_Circ> aCircle = anEdge->circle();
- theProjectedPoint = aCircle->project(thePoint);
- }
+ GeomCurvePtr aCurve(new GeomAPI_Curve(theBaseShape->edge()));
+ theProjectedPoint = aCurve->project(thePoint);
if (theProjectedPoint.get()) {
std::shared_ptr<GeomAPI_Vertex> aVertexShape(new GeomAPI_Vertex(theProjectedPoint->x(),
theProjectedPoint->y(), theProjectedPoint->z()));
bool isInside = isPointOnEdge(theBaseShape, thePoint, theProjectedPoint);
if (isInside) {
std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(theBaseShape));
- if (!anEdge->isCircle()) {
+ if (!anEdge->isClosed()) {
// check the point is not on the boundary
GeomVertexPtr aVertex(new GeomAPI_Vertex(theProjectedPoint->x(),
theProjectedPoint->y(), theProjectedPoint->z()));
#include <GeomAPI_XY.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAlgoAPI_ShapeTools.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
#include <ModelAPI_AttributeBoolean.h>
#include <ModelAPI_AttributeDouble.h>
#include <SketchPlugin_ConstraintMirror.h>
#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintTangent.h>
+#include <SketchPlugin_Ellipse.h>
+#include <SketchPlugin_EllipticArc.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Point.h>
-#include <SketchPlugin_Tools.h>
#include <ModelGeomAlgo_Point2D.h>
#include <ModelAPI_EventReentrantMessage.h>
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_POINT());
ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_OBJECT());
-
- // TODO: remove
- //data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeReference::typeId());
- //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
- //data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
}
void SketchPlugin_Split::execute()
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
data()->attribute(SELECTED_OBJECT()));
- //ObjectPtr aBaseObject = anObjectAttr->value();
- //AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- // aData->attribute(SketchPlugin_Constraint::VALUE()));
if(!aBaseObjectAttr->isInitialized()) {
setError("Error: Base object is not initialized.");
return;
}
ObjectPtr aBaseObject = aBaseObjectAttr->value();
AttributePoint2DPtr aFirstPointAttrOfSplit = getPointAttribute(true);
- // getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_A()));
AttributePoint2DPtr aSecondPointAttrOfSplit = getPointAttribute(false);
- // getPointOfRefAttr(aData->attribute(SketchPlugin_Constraint::ENTITY_B()));
if (!aFirstPointAttrOfSplit.get() || !aFirstPointAttrOfSplit->isInitialized() ||
!aSecondPointAttrOfSplit.get() || !aSecondPointAttrOfSplit->isInitialized()) {
setError("Error: Sub-shape is not initialized.");
return;
}
- /// Remove reference of this feature to feature used in preview, it is not necessary anymore
- /// as trim will be removed after execute
+ // Remove reference of this feature to feature used in preview, it is not necessary anymore
+ // as trim will be removed after execute
AttributeReferencePtr aPreviewObjectAttr =
std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
data()->attribute(PREVIEW_OBJECT()));
// Find feature constraints
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
- ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
+ ResultPtr aBaseFeatureResult = aBaseFeature->lastResult();
std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
//std::map<FeaturePtr, IdToPointPair> aTangentFeatures;
std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
std::list<AttributePtr> aRefsToFeature;
- getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature);
+ SketchPlugin_SegmentationTools::getRefAttributes(
+ aBaseFeature, aBaseRefAttributes, aRefsToFeature);
std::map<AttributePtr, AttributePtr> aBasePointModifiedAttributes;
aReplacingFeature = splitCircle(aSplitFeature, aBaseFeature, anAfterFeature,
aFurtherCoincidences, aCreatedFeatures, aModifiedAttributes);
- updateRefFeatureConstraints(getFeatureResult(aBaseFeature), aRefsToFeature);
+ updateRefFeatureConstraints(aBaseFeature->lastResult(), aRefsToFeature);
AttributePtr aCenterAttr = aCircleFeature->attribute(SketchPlugin_Circle::CENTER_ID());
aFeaturesToDelete.insert(aCircleFeature);
#endif
std::set<ResultPtr> aFeatureResults;
- aFeatureResults.insert(getFeatureResult(aBaseFeature));
+ aFeatureResults.insert(aBaseFeature->lastResult());
if (anAfterFeature.get() && anAfterFeature != aBaseFeature)
- aFeatureResults.insert(getFeatureResult(anAfterFeature));
+ aFeatureResults.insert(anAfterFeature->lastResult());
// coincidence to feature
updateCoincidenceConstraintsToFeature(aCoincidenceToFeature, aFurtherCoincidences,
aFeatureResults, aSplitFeature, aFeaturesToDelete);
- updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes);
+ SketchPlugin_SegmentationTools::updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes);
// delete constraints
#ifdef DEBUG_SPLIT
std::cout << std::endl;
}
#endif
- updateFeaturesAfterSplit(aFeaturesToUpdate);
+ SketchPlugin_SegmentationTools::updateFeaturesAfterOperation(aFeaturesToUpdate);
// Send events to update the sub-features by the solver.
if(isUpdateFlushed) {
ResultPtr aReplacingResult;
if (aReplacingFeature.get()) {
aReplacingFeature->execute(); // need it to obtain result
- aReplacingResult = getFeatureResult(aReplacingFeature);
+ aReplacingResult = aReplacingFeature->lastResult();
}
if (aReplacingResult.get()) { // base object was removed
aPreviewObject = aReplacingResult;
aPreviewObject = ObjectPtr();
aBaseFeature->execute(); // should recompute shapes of result to do not check obsolete one
- aBaseObject = getFeatureResult(aBaseFeature);
+ aBaseObject = aBaseFeature->lastResult();
std::shared_ptr<GeomAPI_Pnt> aPreviewPnt = sketch()->to3D(aPreviewPnt2d->x(),
aPreviewPnt2d->y());
ResultPtr aBaseResult = std::dynamic_pointer_cast<ModelAPI_Result>(aBaseObject);
aPreviewObject = aBaseResult;
}
if (!aPreviewObject.get() && aNewFeature.get()) {
- ResultPtr aNewFeatureResult = getFeatureResult(aNewFeature);
+ ResultPtr aNewFeatureResult = aNewFeature->lastResult();
if (aNewFeatureResult.get()) {
GeomShapePtr aShape = aNewFeatureResult->shape();
std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
std::shared_ptr<GeomAPI_Pnt2d> aPoint = aMessage->clickedPoint();
if (anObject.get() && aPoint.get()) {
- //if (myCashedShapes.find(anObject) == myCashedShapes.end())
- // fillObjectShapes(anObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
- if (myCashedShapes.find(anObject) == myCashedShapes.end())
- fillObjectShapes(anObject, sketch()->data()->owner());
+ if (myCashedShapes.find(anObject) == myCashedShapes.end()) {
+ SketchPlugin_SegmentationTools::fillObjectShapes(
+ this, anObject, myCashedShapes, myCashedReferences);
+ }
const std::set<GeomShapePtr>& aShapes = myCashedShapes[anObject];
if (aShapes.size() > 1) {
std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
- GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
+ GeomShapePtr aSelectedShape = SketchPlugin_SegmentationTools::getSubShape(this,
+ SELECTED_OBJECT(), SELECTED_POINT(), myCashedShapes, myCashedReferences);
if (aSelectedShape.get()) {
aFilledAttributeName = SELECTED_OBJECT();
}
AISObjectPtr SketchPlugin_Split::getAISObject(AISObjectPtr thePrevious)
{
- /*AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Constraint::VALUE()));
- FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
-
- AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(
- data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
- AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(
- data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
-
- if (aBaseObjectAttr->isInitialized() && aBaseFeature.get() &&
- aFirstPointAttrOfSplit->isInitialized() &&
- aSecondPointAttrOfSplit->isInitialized()) {
-
- ResultPtr aResult = getFeatureResult(aBaseFeature);
- GeomShapePtr aBaseShape = aResult->shape();
- std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
-
- std::shared_ptr<GeomAPI_Pnt2d> aStartPnt2d = aFirstPointAttrOfSplit->pnt();
- std::shared_ptr<GeomAPI_Pnt> aStartPoint = sketch()->to3D(aStartPnt2d->x(), aStartPnt2d->y());
- aPoints.push_back(aStartPoint);
-
- std::shared_ptr<GeomAPI_Pnt2d> aSecondPnt2d = aSecondPointAttrOfSplit->pnt();
- std::shared_ptr<GeomAPI_Pnt> aSecondPoint =
- sketch()->to3D(aSecondPnt2d->x(), aSecondPnt2d->y());
- aPoints.push_back(aSecondPoint);
-
- std::set<std::shared_ptr<GeomAPI_Shape> > aSplitShapes;
-
- GeomAlgoAPI_ShapeTools::splitShape_p(aBaseShape, aPoints, aSplitShapes);
- std::shared_ptr<GeomAPI_Shape> aShape =
- GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes);
-
- AISObjectPtr anAIS = thePrevious;
- if (aShape) {
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createShape(aShape);
- std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
- aBaseFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
-
- bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
-
- std::vector<int> aColor;
- 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;
- }
- return AISObjectPtr();*/
-#ifdef DEBUG_SPLIT
- std::cout << "SketchPlugin_Split::getAISObject: " << data()->name() << std::endl;
-#endif
-
- AISObjectPtr anAIS = thePrevious;
-
- std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
- GeomShapePtr aPreviewShape = getSubShape(PREVIEW_OBJECT(), PREVIEW_POINT());
- if (aPreviewShape.get())
- aShapes.push_back(aPreviewShape);
- GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
- if (aSelectedShape.get())
- aShapes.push_back(aSelectedShape);
-
- if (aShapes.empty())
- return AISObjectPtr();
-
- GeomShapePtr aBaseShape = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- if (!aBaseShape.get())
- return AISObjectPtr();
-
- if (aBaseShape.get()) {
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createShape(aBaseShape);
-
- std::vector<int> aColor;
- aColor = Config_PropManager::color("Visualization", "operation_remove_feature_color");
- double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH();
- int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
- anAIS->setColor(aColor[0], aColor[1], aColor[2]);
- // width when there is not base object should be extened in several points
- // in order to see this preview over highlight
- anAIS->setWidth(aWidth+4);
- anAIS->setLineStyle(aLineStyle);
- }
- else
- anAIS = AISObjectPtr();
- return anAIS;
+ return SketchPlugin_SegmentationTools::getAISObject(thePrevious,
+ this, PREVIEW_OBJECT(), PREVIEW_POINT(), SELECTED_OBJECT(), SELECTED_POINT());
}
//********************************************************************
-void SketchPlugin_Split::fillObjectShapes(const ObjectPtr& theObject,
- const ObjectPtr& theSketch)
-{
- std::set<std::shared_ptr<GeomAPI_Shape> > aShapes;
- std::map<std::shared_ptr<GeomDataAPI_Point2D>, std::shared_ptr<GeomAPI_Pnt> > aPointToAttributes;
- std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
- // current feature
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- // edges on feature
- std::set<ResultPtr> anEdgeResults;
- ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeResults);
- if (!anEdgeResults.empty()) {
- GeomShapePtr aFeatureShape = (*anEdgeResults.begin())->shape();
-
- // coincidences to the feature
- ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(),
- aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
- // layed on feature coincidences to divide it on several shapes
- std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
- std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
- ModelGeomAlgo_Point2D::getPointsInsideShape_p(aFeatureShape, aRefAttributes, aC->pnt(),
- aX->dir(), aY, aPoints, aPointToAttributes);
-
- if (!aPoints.empty())
- GeomAlgoAPI_ShapeTools::splitShape_p(aFeatureShape, aPoints, aShapes);
- }
- myCashedShapes[theObject] = aShapes;
- myCashedReferences[theObject] = aPointToAttributes;
-}
-
-GeomShapePtr SketchPlugin_Split::getSubShape(const std::string& theObjectAttributeId,
- const std::string& thePointAttributeId)
-{
- GeomShapePtr aBaseShape;
-
- AttributeReferencePtr anObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(theObjectAttributeId));
- ObjectPtr aBaseObject = anObjectAttr->value();
- if (!aBaseObject.get())
- return aBaseShape;
-
- // point on feature
- AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(thePointAttributeId));
- std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPointAttr->pnt();
- std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
- anAttributePnt2d->y());
-
-#ifdef TRIM_SHAPE
- if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
-
- const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
- if (!aShapes.empty()) {
- std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
- for (; anIt != aLast; anIt++) {
- GeomShapePtr aShape = *anIt;
- std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
- if (ModelGeomAlgo_Point2D::isPointOnEdge(aShape, anAttributePnt, aProjectedPoint))
- aBaseShape = aShape;
- }
- }
-#else
- if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject, sketch()->data()->owner());
-
- std::shared_ptr<GeomAPI_Pnt> aStartPoint;
- std::shared_ptr<GeomAPI_Pnt> aSecondPoint;
- const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
- std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
- for (; anIt != aLast; anIt++) {
- GeomShapePtr aCurrentShape = *anIt;
- std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
- if (ModelGeomAlgo_Point2D::isPointOnEdge(aCurrentShape, anAttributePnt, aProjectedPoint)) {
- if (aCurrentShape->shapeType() == GeomAPI_Shape::EDGE) {
- std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aCurrentShape));
- aStartPoint = anEdge->firstPoint();
- aSecondPoint = anEdge->lastPoint();
- }
- break;
- }
- }
-
- if (!aStartPoint.get() || !aSecondPoint.get())
- return aBaseShape;
-
- //AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- // data()->attribute(SketchPlugin_Constraint::VALUE()));
- FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject/*aBaseObjectAttr->value()*/);
-
- //AttributePoint2DPtr aFirstPointAttrOfSplit = getPointOfRefAttr(
- // data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
- //AttributePoint2DPtr aSecondPointAttrOfSplit = getPointOfRefAttr(
- // data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
- if (anObjectAttr->isInitialized() && aBaseFeature.get() && aPointAttr->isInitialized()) {
- //aFirstPointAttrOfSplit->isInitialized() &&
- //aSecondPointAttrOfSplit->isInitialized()) {
- ResultPtr aResult = getFeatureResult(aBaseFeature);
- GeomShapePtr aResultShape = aResult->shape();
- std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
-
- //std::shared_ptr<GeomAPI_Pnt2d> aStartPnt2d = aFirstPointAttrOfSplit->pnt();
- //std::shared_ptr<GeomAPI_Pnt> aStartPoint = sketch()->to3D(aStartPnt2d->x(), aStartPnt2d->y());
- aPoints.push_back(aStartPoint);
-
- //std::shared_ptr<GeomAPI_Pnt2d> aSecondPnt2d = aSecondPointAttrOfSplit->pnt();
- //std::shared_ptr<GeomAPI_Pnt> aSecondPoint =
- // sketch()->to3D(aSecondPnt2d->x(), aSecondPnt2d->y());
- aPoints.push_back(aSecondPoint);
-
- std::set<std::shared_ptr<GeomAPI_Shape> > aSplitShapes;
- GeomAlgoAPI_ShapeTools::splitShape_p(aResultShape, aPoints, aSplitShapes);
- aBaseShape = GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes);
-#endif
- }
- return aBaseShape;
-}
-
-void SketchPlugin_Split::getFeaturePoints(const FeaturePtr& theFeature,
- AttributePoint2DPtr& theStartPointAttr,
- AttributePoint2DPtr& theEndPointAttr)
-{
- std::string aFeatureKind = theFeature->getKind();
- std::string aStartAttributeName, anEndAttributeName;
- if (aFeatureKind == SketchPlugin_Line::ID()) {
- aStartAttributeName = SketchPlugin_Line::START_ID();
- anEndAttributeName = SketchPlugin_Line::END_ID();
- }
- else if (aFeatureKind == SketchPlugin_Arc::ID()) {
- aStartAttributeName = SketchPlugin_Arc::START_ID();
- anEndAttributeName = SketchPlugin_Arc::END_ID();
- }
- if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) {
- theStartPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theFeature->attribute(aStartAttributeName));
- theEndPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theFeature->attribute(anEndAttributeName));
- }
-}
-
void SketchPlugin_Split::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
std::set<FeaturePtr>& theFeaturesToUpdate,
std::map<FeaturePtr, IdToPointPair>& theCoincidenceToFeature)
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
data()->attribute(SELECTED_OBJECT()));
- //AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- // aData->attribute(SketchPlugin_Constraint::VALUE()));
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
- ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
+ ResultPtr aBaseFeatureResult = aBaseFeature->lastResult();
std::set<AttributePtr> aRefsList = aBaseFeatureResult->data()->refsToMe();
std::set<AttributePtr> aFRefsList = aBaseFeature->data()->refsToMe();
AttributeRefAttrPtr anAttrA = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_A());
AttributeRefAttrPtr anAttrB = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_B());
bool isToFeature = false;
- if (anAttrA->isObject() || anAttrB->isObject()) { /// coincidence to base feature
+ if (anAttrA->isObject() || anAttrB->isObject()) { // coincidence to base feature
FeaturePtr aFeature = anAttrA->isObject() ? ModelAPI_Feature::feature(anAttrA->object())
: FeaturePtr();
isToFeature = aFeature.get() && aFeature == aBaseFeature;
if (isToFeature)
aCoincidentPoint = SketchPlugin_ConstraintCoincidence::getPoint(aRefFeature);
}
- if (!isToFeature) { /// coincidence to point on base feature
+ if (!isToFeature) { // coincidence to point on base feature
AttributePtr anAttribute;
if (!anAttrA->isObject()) {
}
}
-void SketchPlugin_Split::getRefAttributes(const FeaturePtr& theFeature,
- std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
- std::list<AttributePtr>& theRefsToFeature)
-{
- theRefs.clear();
-
- std::list<AttributePtr> aPointAttributes =
- theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
- std::set<AttributePtr> aPointAttributesSet;
-
- std::list<AttributePtr>::const_iterator aPIt =
- aPointAttributes.begin(), aPLast = aPointAttributes.end();
- for (; aPIt != aPLast; aPIt++)
- aPointAttributesSet.insert(*aPIt);
-
- std::set<AttributePtr> aRefsAttributes = getFeatureResult(theFeature)->data()->refsToMe();
- std::set<AttributePtr> aFRefsList = theFeature->data()->refsToMe();
- aRefsAttributes.insert(aFRefsList.begin(), aFRefsList.end());
-
- std::set<AttributePtr>::const_iterator aIt;
- for (aIt = aRefsAttributes.cbegin(); aIt != aRefsAttributes.cend(); ++aIt) {
- AttributePtr anAttr = (*aIt);
- FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttr->owner());
- if (anAttrFeature.get() != this &&
- anAttr.get() && anAttr->attributeType() == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
- if (!aRefAttr->isObject()) { /// find attributes referenced to feature point attributes
- AttributePtr anAttrInRef = aRefAttr->attr();
- if (anAttrInRef.get() &&
- aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) {
- if (theRefs.find(anAttrInRef) != theRefs.end())
- theRefs[anAttrInRef].push_back(aRefAttr);
- else {
- std::list<AttributePtr> anAttrList;
- anAttrList.push_back(aRefAttr);
- theRefs[anAttrInRef] = anAttrList;
- }
- }
- }
- else { /// find attributes referenced to feature itself
- theRefsToFeature.push_back(anAttr);
- }
- }
- }
-}
-
void SketchPlugin_Split::updateCoincidenceConstraintsToFeature(
const std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature,
const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
// we should build coincidence constraints to end of the split feature
std::set<std::shared_ptr<GeomDataAPI_Point2D> > aNewCoincidencesToSplitFeature;
AttributePoint2DPtr aStartPointAttr, anEndPointAttr;
- getFeaturePoints(theSplitFeature, aStartPointAttr, anEndPointAttr);
+ SketchPlugin_SegmentationTools::getFeaturePoints(
+ theSplitFeature, aStartPointAttr, anEndPointAttr);
if (theFurtherCoincidences.find(aStartPointAttr) == theFurtherCoincidences.end())
aNewCoincidencesToSplitFeature.insert(aStartPointAttr);
if (theFurtherCoincidences.find(anEndPointAttr) == theFurtherCoincidences.end())
}
}
else {
- /// find feature by shape intersected the point
+ // find feature by shape intersected the point
ResultPtr aResultForCoincidence = *(theFeatureResults.begin());
if (theFeatureResults.size() > 1) { // try to find point on additional feature
}
}
-void SketchPlugin_Split::updateRefAttConstraints(
- const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
- const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes)
-{
-#ifdef DEBUG_SPLIT
- std::cout << "SketchPlugin_Split::updateRefAttConstraints" << std::endl;
-#endif
-
- std::set<std::pair<AttributePtr, AttributePtr> >::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())
- continue;
- std::list<AttributePtr> aRefAttributes = theBaseRefAttributes.at(anAttribute);
- std::list<AttributePtr>::const_iterator aRefIt = aRefAttributes.begin(),
- aRLast = aRefAttributes.end();
-
- AttributePtr aNewAttribute = anIt->second;
- for (; aRefIt != aRLast; aRefIt++) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
- if (aRefAttr.get()) {
- aRefAttr->setAttr(aNewAttribute);
-#ifdef DEBUG_SPLIT
- FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->owner());
- std::cout << " -" << getFeatureInfo(aFeature) << std::endl;
-#endif
- }
- }
- }
-}
-
FeaturePtr SketchPlugin_Split::splitLine(FeaturePtr& theSplitFeature,
FeaturePtr& theBaseFeatureModified,
FeaturePtr& theAfterFeature,
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
data()->attribute(SELECTED_OBJECT()));
- //AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- // data()->attribute(SketchPlugin_Constraint::VALUE()));
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
std::string aFeatureKind = aBaseFeature->getKind();
if (aFeatureKind != SketchPlugin_Line::ID())
return anNewFeature;
AttributePoint2DPtr aFirstPointAttrOfSplit = getPointAttribute(true);
- //getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
AttributePoint2DPtr aSecondPointAttrOfSplit = getPointAttribute(false);
- //getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
- getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
+ SketchPlugin_SegmentationTools::getFeaturePoints(
+ aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
if (!aStartPointAttrOfBase.get() && !anEndPointAttrOfBase.get()) {
setError("Error: Feature has no start and end points.");
return anNewFeature;
ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl;
#endif
- /// create a split feature
+ // create a split feature
theSplitFeature =
createLineFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
theCreatedFeatures.insert(theSplitFeature);
theSplitFeature->attribute(SketchPlugin_Line::START_ID())));
}
else {
- theBaseFeatureModified = aBaseFeature; ///< use base feature to store all constraints here
- /// move end arc point to start of split
+ theBaseFeatureModified = aBaseFeature; // use base feature to store all constraints here
+ // move end arc point to start of split
}
// after split feature
if (!aSecondPointAttrOfSplit->pnt()->isEqual(anEndPointAttrOfBase->pnt())) {
FeaturePtr aFeature;
if (!theBaseFeatureModified.get()) {
- aFeature = aBaseFeature; ///< use base feature to store all constraints here
+ aFeature = aBaseFeature; // use base feature to store all constraints here
fillAttribute(aFeature->attribute(SketchPlugin_Line::START_ID()), aSecondPointAttrOfSplit);
aFeature->execute(); // to update result
}
// (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
+ // move end arc point to start of split
fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()),
aFirstPointAttrOfSplit);
theBaseFeatureModified->execute(); // to update result
// additional constraints between split and base features
aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
SketchPlugin_ConstraintParallel::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theSplitFeature));
+ aBaseFeature->lastResult(),
+ theSplitFeature->lastResult());
theCreatedFeatures.insert(aConstraintFeature);
if (theAfterFeature.get()) {
aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
SketchPlugin_ConstraintParallel::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theAfterFeature));
+ aBaseFeature->lastResult(),
+ theAfterFeature->lastResult());
theCreatedFeatures.insert(aConstraintFeature);
}
#endif
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
data()->attribute(SELECTED_OBJECT()));
- //AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- // data()->attribute(SketchPlugin_Constraint::VALUE()));
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
std::string aFeatureKind = aBaseFeature->getKind();
if (aFeatureKind != SketchPlugin_Arc::ID())
return anNewFeature;
AttributePoint2DPtr aFirstPointAttrOfSplit = getPointAttribute(true);
- //getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
AttributePoint2DPtr aSecondPointAttrOfSplit = getPointAttribute(false);
- //getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
- getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
+ SketchPlugin_SegmentationTools::getFeaturePoints(
+ aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
if (!aStartPointAttrOfBase.get() && !anEndPointAttrOfBase.get()) {
setError("Error: Feature has no start and end points.");
return anNewFeature;
ModelGeomAlgo_Point2D::getPointAttributeInfo(anEndPointAttrOfBase) << std::endl;
#endif
- /// split feature
+ // split feature
theSplitFeature = createArcFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
theCreatedFeatures.insert(theSplitFeature);
theSplitFeature->attribute(SketchPlugin_Arc::START_ID())));
}
else {
- theBaseFeatureModified = aBaseFeature; ///< use base feature to store all constraints here
- /// move end arc point to start of split
+ theBaseFeatureModified = aBaseFeature; // use base feature to store all constraints here
+ // move end arc point to start of split
}
// after split feature
if (!aSecondPointAttrOfSplit->pnt()->isEqual(anEndPointAttrOfBase->pnt())) {
FeaturePtr aFeature;
if (!theBaseFeatureModified.get()) {
- aFeature = aBaseFeature; ///< use base feature to store all constraints here
+ aFeature = aBaseFeature; // use base feature to store all constraints here
fillAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), aSecondPointAttrOfSplit);
aFeature->execute(); // to update result
}
// (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
+ // move end arc point to start of split
fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()),
aFirstPointAttrOfSplit);
theBaseFeatureModified->execute(); // to update result
#ifdef CREATE_CONSTRAINTS
aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theSplitFeature));
+ aBaseFeature->lastResult(),
+ theSplitFeature->lastResult());
theCreatedFeatures.insert(aConstraintFeature);
aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(aBaseFeature));
+ theSplitFeature->lastResult(),
+ aBaseFeature->lastResult());
theCreatedFeatures.insert(aConstraintFeature);
if (theAfterFeature.get()) {
aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theAfterFeature));
+ aBaseFeature->lastResult(),
+ theAfterFeature->lastResult());
theCreatedFeatures.insert(aConstraintFeature);
aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(theAfterFeature));
+ theSplitFeature->lastResult(),
+ theAfterFeature->lastResult());
theCreatedFeatures.insert(aConstraintFeature);
}
#endif
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
data()->attribute(SELECTED_OBJECT()));
- //AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- // data()->attribute(SketchPlugin_Constraint::VALUE()));
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
std::string aFeatureKind = aBaseFeature->getKind();
if (aFeatureKind != SketchPlugin_Circle::ID())
return anNewFeature;
AttributePoint2DPtr aFirstPointAttrOfSplit = getPointAttribute(true);
- //getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_A()));
AttributePoint2DPtr aSecondPointAttrOfSplit = getPointAttribute(false);
- //getPointOfRefAttr(data()->attribute(SketchPlugin_Constraint::ENTITY_B()));
- /// split feature
+ // split feature
theSplitFeature =
createArcFeature(aBaseFeature, aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
bool aSplitReversed = std::dynamic_pointer_cast<SketchPlugin_Arc>(theSplitFeature)->isReversed();
theCreatedFeatures.insert(theSplitFeature);
- /// base feature is a left part of the circle
+ // base feature is a left part of the circle
theBaseFeatureModified = createArcFeature(aBaseFeature,
aFirstPointAttrOfSplit, aSecondPointAttrOfSplit);
anNewFeature = theBaseFeatureModified;
#ifdef CREATE_CONSTRAINTS
aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(theBaseFeatureModified));
+ theSplitFeature->lastResult(),
+ theBaseFeatureModified->lastResult());
theCreatedFeatures.insert(aConstraintFeature);
#endif
return anNewFeature;
}
FeaturePtr SketchPlugin_Split::createArcFeature(const FeaturePtr& theBaseFeature,
- const AttributePtr& theFirstPointAttr,
- const AttributePtr& theSecondPointAttr)
+ const AttributePtr& theFirstPointAttr,
+ const AttributePtr& theSecondPointAttr)
{
FeaturePtr aFeature;
SketchPlugin_Sketch* aSketch = sketch();
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
+ // 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::REVERSED_ID())->value();
aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed);
return aFeature;
}
-void SketchPlugin_Split::updateFeaturesAfterSplit(
- const std::set<FeaturePtr>& theFeaturesToUpdate)
-{
- std::set<FeaturePtr>::const_iterator anIt = theFeaturesToUpdate.begin(),
- aLast = theFeaturesToUpdate.end();
- for (; anIt != aLast; anIt++) {
- FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
- std::string aRefFeatureKind = aRefFeature->getKind();
- if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) {
- std::shared_ptr<SketchPlugin_ConstraintLength> aLenghtFeature =
- std::dynamic_pointer_cast<SketchPlugin_ConstraintLength>(*anIt);
- if (aLenghtFeature.get()) {
- std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(aLenghtFeature->attribute(SketchPlugin_Constraint::VALUE()));
- double aValue;
- if (aLenghtFeature->computeLenghtValue(aValue) && aValueAttr.get())
- aValueAttr->setValue(aValue);
- }
- }
- }
-}
-
-std::shared_ptr<ModelAPI_Result> SketchPlugin_Split::getFeatureResult(
- const std::shared_ptr<ModelAPI_Feature>& theFeature)
-{
- std::shared_ptr<ModelAPI_Result> aResult;
-
- std::string aFeatureKind = theFeature->getKind();
- if (aFeatureKind == SketchPlugin_Line::ID())
- aResult = theFeature->firstResult();
- else if (aFeatureKind == SketchPlugin_Arc::ID())
- aResult = theFeature->lastResult();
- else if (aFeatureKind == SketchPlugin_Circle::ID())
- aResult = theFeature->lastResult();
-
- return aResult;
-}
-
#ifdef _DEBUG
std::set<std::shared_ptr<ModelAPI_Attribute> > SketchPlugin_Split::getEdgeAttributes(
const std::shared_ptr<ModelAPI_Feature>& theFeature)
anAttributes.insert(theFeature->attribute(SketchPlugin_Arc::START_ID()));
anAttributes.insert(theFeature->attribute(SketchPlugin_Arc::END_ID()));
}
+ else if (aFeatureKind == SketchPlugin_EllipticArc::ID()) {
+ anAttributes.insert(theFeature->attribute(SketchPlugin_EllipticArc::START_POINT_ID()));
+ anAttributes.insert(theFeature->attribute(SketchPlugin_EllipticArc::END_POINT_ID()));
+ }
else if (aFeatureKind == SketchPlugin_Circle::ID()) {
}
{
std::shared_ptr<GeomDataAPI_Point2D> anAttribute;
- GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
+ GeomShapePtr aSelectedShape = SketchPlugin_SegmentationTools::getSubShape(this,
+ SELECTED_OBJECT(), SELECTED_POINT(), myCashedShapes, myCashedReferences);
if (!aSelectedShape.get())
return anAttribute;
std::shared_ptr<GeomAPI_Pnt> aLastPnt = anEdge->lastPoint();
std::shared_ptr<GeomDataAPI_Point2D> aFirstPointAttr, aLastPointAttr;
- /// find the points in feature attributes
+ // find the points in feature attributes
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
std::list<AttributePtr> a2DPointAttributes = aBaseFeature->data()->attributes(
GeomDataAPI_Point2D::typeId());
aLastPointAttr = anAttributePoint;
}
- /// find the points in coincident features
- PntToAttributesMap aRefAttributes = myCashedReferences[aBaseObject];
- PntToAttributesMap::const_iterator
+ // find the points in coincident features
+ const GeomAlgoAPI_ShapeTools::PointToRefsMap& aRefAttributes = myCashedReferences.at(aBaseObject);
+ GeomAlgoAPI_ShapeTools::PointToRefsMap::const_iterator
aRIt = aRefAttributes.begin(), aRLast = aRefAttributes.end();
for (; aRIt != aRLast; aRIt++) {
- std::shared_ptr<GeomDataAPI_Point2D> anAttribute = aRIt->first;
- std::shared_ptr<GeomAPI_Pnt> aPoint = aRIt->second;
+ const std::list<AttributePoint2DPtr>& anAttributes = aRIt->second.first;
+ GeomPointPtr aPoint = aRIt->first;
if (!aFirstPointAttr.get() && aFirstPnt->isEqual(aPoint))
- aFirstPointAttr = anAttribute;
+ aFirstPointAttr = anAttributes.front();
if (!aLastPointAttr.get() && aLastPnt->isEqual(aPoint))
- aLastPointAttr = anAttribute;
+ aLastPointAttr = anAttributes.front();
if (aFirstPointAttr.get() && aLastPointAttr.get())
break;
}
if (isUseAttributesInfo) {
std::string aPointsInfo = ModelGeomAlgo_Point2D::getPontAttributesInfo(theFeature,
getEdgeAttributes(theFeature));
- /// 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
+ else { // process constraint coincidence, find points in ref attr attributes
std::list<AttributePtr> anAttrs = theFeature->data()->attributes(
ModelAPI_AttributeRefAttr::typeId());
std::list<AttributePtr>::const_iterator anIt = anAttrs.begin(), aLast = anAttrs.end();
#define SketchPlugin_Split_H_
#include "SketchPlugin.h"
+#include "SketchPlugin_Tools.h"
-#include "GeomAPI_IPresentable.h"
+#include <GeomAPI_IPresentable.h>
#include <ModelAPI_IReentrant.h>
#include <SketchPlugin_Sketch.h>
* \ingroup Plugins
* \brief Feature for creation of a new constraint splitting object. Entities for split:
* - Linear segment by point(s) on this line
- * - Arc by point(s) on this arc
- * - Circle by at least 2 split-points on this circle
+ * - Circular/elliptic arc by point(s) on this arc
+ * - Circle/ellipse by at least 2 split-points on it
*
* The following constraints will be applied after split to keep the divided segments geometry:
* - Coincident constraints for both parts of created segments in the point of splitting
- * - For linear segments parallel, for circles - tangent constraint, for arc - tangent and equal
- * constraints. In case of three segments in result two couple of constraints are created
+ * - For linear segments parallel, for circles/ellipses - tangent constraint,
+ * for arc - tangent and equal constraints. In case of three segments in result
+ * two couple of constraints are created
* - parallel and equal constraints: the first is between 1st and middle entity, the second is
* between 1st and 3rd.
* - tangency constraints: the first between 1st and 2nd, the second between 2nd and 3rd.
* start point of arc/line.
* - Replication constraint used split feature will be deleted in the same way as it is deleted
* by any of entity delete in sketch which is used in this constraint.
- *
- * This constraint has three attributes:
- * SketchPlugin_Constraint::VALUE() contains reference object to be splitted
- * SketchPlugin_Constraint::ENTITY_A() and SketchPlugin_Constraint::ENTITY_B() for the points of split;
- *
*/
class SketchPlugin_Split : public SketchPlugin_Feature, public GeomAPI_IPresentable,
public ModelAPI_IReentrant
virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
private:
- /// Fulfill an internal container by shapes obtained from the parameter object
- /// Shapes are result of split operation by points coincident to shape of the object
- /// \param theObject a source object (will be splitted)
- /// \param theSketch a sketch object
- void fillObjectShapes(const ObjectPtr& theObject, const ObjectPtr& theSketch);
-
- GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
- const std::string& thePointAttributeId);
- /// Returns geom point attribute of the feature bounds. It processes line or arc.
- /// For circle feature, the result attributes are null
- /// \param theFeature a source feature
- /// \param theStartPointAttr an out attribute to start point
- /// \param theStartPointAttr an out attribute to end point
- void getFeaturePoints(const FeaturePtr& theFeature,
- std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
- std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
-
/// Obtains those constraints of the feature that should be modified. output maps contain
/// point of coincidence and attribute id to be modified after split
/// \param theFeaturesToDelete [out] constrains that will be deleted after split
std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate,
std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature);
- /// Obtains references to feature point attributes and to feature,
- /// e.g. for feature line: 1st container is
- /// <1st line point, list<entity_a in distance, entity_b in parallel> >
- /// <2nd line point, list<> >
- /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
- /// \param theFeature an investigated feature
- /// \param theRefs a container of list of referenced attributes
- void getRefAttributes(const FeaturePtr& theFeature,
- std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
- std::list<AttributePtr>& theRefsToFeature);
-
/// Move coincidence constraint from feature to point if it is found
/// \param theCoincidenceToFeature coincidence to feature to be connected to new feature
/// \param theFurtherCoincidences a list of points where coincidences will be build
void updateRefFeatureConstraints(const std::shared_ptr<ModelAPI_Result>& theFeatureBaseResult,
const std::list<AttributePtr>& theRefsToFeature);
- /// Move constraints from attribute of base feature to attribute after modification
- /// \param theBaseRefAttributes container of references to the attributes of base feature
- /// \param theModifiedAttributes container of attributes placed instead of base attributes
- /// at the same place
- void updateRefAttConstraints(
- const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
- const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes);
-
/// Make the base object is splitted by the point attributes
/// \param theSplitFeature a result split feature
/// \param theBeforeFeature a feature between start point and the 1st point of split feature
const AttributePtr& theFirstPointAttr,
const AttributePtr& theSecondPointAttr);
- /// Add feature coincidence constraint between given attributes
- /// \param theFeaturesToUpdate a constraint index
- void updateFeaturesAfterSplit(const std::set<FeaturePtr>& theFeaturesToUpdate);
-
- /// Result result of the feature to build constraint with. For arc, circle it is an edge result.
- /// \param theFeature a feature
- /// \return result object
- std::shared_ptr<ModelAPI_Result> getFeatureResult(
- const std::shared_ptr<ModelAPI_Feature>& theFeature);
-
/// Returns attributes of the feature, used in edge build, for arc it is end and start points
/// \param theFeature a feature
/// \return container of attributes
const bool isUseAttributesInfo = true);
#endif
private:
- typedef std::map<std::shared_ptr<GeomDataAPI_Point2D>,
- std::shared_ptr<GeomAPI_Pnt> > PntToAttributesMap;
std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
- std::map<std::shared_ptr<ModelAPI_Object>, PntToAttributesMap> myCashedReferences;
+ std::map<std::shared_ptr<ModelAPI_Object>,
+ GeomAlgoAPI_ShapeTools::PointToRefsMap> myCashedReferences;
};
#endif
#include "SketchPlugin_Tools.h"
+#include "SketchPlugin_Arc.h"
#include "SketchPlugin_ConstraintCoincidence.h"
#include "SketchPlugin_ConstraintCoincidenceInternal.h"
#include "SketchPlugin_ConstraintLength.h"
#include "SketchPlugin_ConstraintTangent.h"
#include "SketchPlugin_Ellipse.h"
+#include "SketchPlugin_EllipticArc.h"
#include "SketchPlugin_Line.h"
#include "SketchPlugin_Point.h"
+#include "SketchPlugin_Projection.h"
#include "SketchPlugin_SketchEntity.h"
+#include "SketchPlugin_Split.h"
+#include "SketchPlugin_Trim.h"
#include <SketcherPrs_Tools.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelGeomAlgo_Point2D.h>
+#include <ModelGeomAlgo_Shape.h>
+
#include <GeomAPI_Dir2d.h>
+#include <GeomAPI_Edge.h>
#include <GeomAPI_Pnt2d.h>
#include <GeomAPI_XY.h>
+#include <GeomAlgoAPI_CompoundBuilder.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
#include <GeomDataAPI_Point.h>
#include <GeomDataAPI_Point2D.h>
}
} // namespace SketchPlugin_Tools
+
+
+// =================================================================================================
+// namespace SketchPlugin_SegmentationTools
+// =================================================================================================
+
+void SketchPlugin_SegmentationTools::getFeaturePoints(const FeaturePtr& theFeature,
+ AttributePoint2DPtr& theStartPointAttr,
+ AttributePoint2DPtr& theEndPointAttr)
+{
+ std::string aFeatureKind = theFeature->getKind();
+ std::string aStartAttributeName, anEndAttributeName;
+ if (aFeatureKind == SketchPlugin_Line::ID()) {
+ aStartAttributeName = SketchPlugin_Line::START_ID();
+ anEndAttributeName = SketchPlugin_Line::END_ID();
+ }
+ else if (aFeatureKind == SketchPlugin_Arc::ID()) {
+ aStartAttributeName = SketchPlugin_Arc::START_ID();
+ anEndAttributeName = SketchPlugin_Arc::END_ID();
+ }
+ else if (aFeatureKind == SketchPlugin_EllipticArc::ID()) {
+ aStartAttributeName = SketchPlugin_EllipticArc::START_POINT_ID();
+ anEndAttributeName = SketchPlugin_EllipticArc::END_POINT_ID();
+ }
+ if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) {
+ theStartPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(aStartAttributeName));
+ theEndPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ theFeature->attribute(anEndAttributeName));
+ }
+}
+
+
+void SketchPlugin_SegmentationTools::getRefAttributes(
+ const FeaturePtr& theFeature,
+ std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
+ std::list<AttributePtr>& theRefsToFeature)
+{
+ theRefs.clear();
+
+ std::list<AttributePtr> aPointAttributes =
+ theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
+ std::set<AttributePtr> aPointAttributesSet;
+
+ std::list<AttributePtr>::const_iterator aPIt =
+ aPointAttributes.begin(), aPLast = aPointAttributes.end();
+ for (; aPIt != aPLast; aPIt++)
+ aPointAttributesSet.insert(*aPIt);
+
+ std::set<AttributePtr> aRefsAttributes = theFeature->lastResult()->data()->refsToMe();
+ std::set<AttributePtr> aFRefsList = theFeature->data()->refsToMe();
+ aRefsAttributes.insert(aFRefsList.begin(), aFRefsList.end());
+
+ std::set<AttributePtr>::const_iterator aIt;
+ for (aIt = aRefsAttributes.cbegin(); aIt != aRefsAttributes.cend(); ++aIt) {
+ AttributePtr anAttr = (*aIt);
+ FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttr->owner());
+ if (!anAttrFeature->isMacro() && // <- skip reference from Trim or Split feature
+ anAttr.get() && anAttr->attributeType() == ModelAPI_AttributeRefAttr::typeId()) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
+ if (!aRefAttr->isObject()) { // find attributes referenced to feature point attributes
+ AttributePtr anAttrInRef = aRefAttr->attr();
+ if (anAttrInRef.get() &&
+ aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) {
+ if (theRefs.find(anAttrInRef) != theRefs.end())
+ theRefs[anAttrInRef].push_back(aRefAttr);
+ else {
+ std::list<AttributePtr> anAttrList;
+ anAttrList.push_back(aRefAttr);
+ theRefs[anAttrInRef] = anAttrList;
+ }
+ }
+ }
+ else { // find attributes referenced to feature itself
+ theRefsToFeature.push_back(anAttr);
+ }
+ }
+ }
+}
+
+GeomShapePtr SketchPlugin_SegmentationTools::getSubShape(
+ SketchPlugin_Feature* theFeature,
+ const std::string& theObjectAttributeId,
+ const std::string& thePointAttributeId,
+ std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
+ std::map<ObjectPtr, GeomAlgoAPI_ShapeTools::PointToRefsMap>& theObjectToPoints)
+{
+ GeomShapePtr aBaseShape;
+
+ AttributeReferencePtr anObjectAttr = theFeature->reference(theObjectAttributeId);
+ ObjectPtr aBaseObject = anObjectAttr->value();
+ if (!aBaseObject.get())
+ return aBaseShape;
+
+ // point on feature
+ AttributePoint2DPtr aPointAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(theFeature->attribute(thePointAttributeId));
+ std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPointAttr->pnt();
+ std::shared_ptr<GeomAPI_Pnt> anAttributePnt =
+ theFeature->sketch()->to3D(anAttributePnt2d->x(), anAttributePnt2d->y());
+
+ if (theCashedShapes.find(aBaseObject) == theCashedShapes.end())
+ fillObjectShapes(theFeature, aBaseObject, theCashedShapes, theObjectToPoints);
+
+ std::shared_ptr<GeomAPI_Pnt> aStartPoint;
+ std::shared_ptr<GeomAPI_Pnt> aSecondPoint;
+ const std::set<GeomShapePtr>& aShapes = theCashedShapes[aBaseObject];
+ std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
+ for (; anIt != aLast; anIt++) {
+ GeomShapePtr aCurrentShape = *anIt;
+ std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
+ if (ModelGeomAlgo_Point2D::isPointOnEdge(aCurrentShape, anAttributePnt, aProjectedPoint)) {
+ if (theFeature->getKind() == SketchPlugin_Split::ID()) {
+ // for Split operation collect start and end points of the shape
+ if (aCurrentShape->shapeType() == GeomAPI_Shape::EDGE) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aCurrentShape));
+ aStartPoint = anEdge->firstPoint();
+ aSecondPoint = anEdge->lastPoint();
+ }
+ }
+ else
+ aBaseShape = aCurrentShape;
+ break;
+ }
+ }
+
+ if (!aStartPoint.get() || !aSecondPoint.get())
+ return aBaseShape;
+
+ FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
+ if (anObjectAttr->isInitialized() && aBaseFeature.get() && aPointAttr->isInitialized()) {
+ ResultPtr aResult = aBaseFeature->lastResult();
+ GeomShapePtr aResultShape = aResult->shape();
+ std::list<std::shared_ptr<GeomAPI_Pnt> > aPoints;
+
+ aPoints.push_back(aStartPoint);
+ aPoints.push_back(aSecondPoint);
+
+ std::set<std::shared_ptr<GeomAPI_Shape> > aSplitShapes;
+ GeomAlgoAPI_ShapeTools::splitShape_p(aResultShape, aPoints, aSplitShapes);
+ aBaseShape = GeomAlgoAPI_ShapeTools::findShape(aPoints, aSplitShapes);
+ }
+ return aBaseShape;
+}
+
+void SketchPlugin_SegmentationTools::fillObjectShapes(
+ SketchPlugin_Feature* theOpFeature,
+ const ObjectPtr& theObject,
+ std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
+ std::map<ObjectPtr, GeomAlgoAPI_ShapeTools::PointToRefsMap>& theObjectToPoints)
+{
+ SketchPlugin_Sketch* aSketch = theOpFeature->sketch();
+
+ GeomAlgoAPI_ShapeTools::PointToRefsMap aPoints;
+ std::set<GeomShapePtr> aShapes;
+
+ std::set<AttributePoint2DPtr > aRefAttributes;
+ // current feature
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
+ std::set<ResultPtr> anEdgeShapes;
+ // edges on feature
+ ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
+ if (!anEdgeShapes.empty()) {
+ GeomShapePtr aFeatureShape = (*anEdgeShapes.begin())->shape();
+
+ // coincidences to the feature
+ ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(),
+ aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
+ // layed on feature coincidences to divide it on several shapes
+ std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+
+ ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(),
+ aX->dir(), aY, aPoints);
+
+ if (theOpFeature->getKind() == SketchPlugin_Trim::ID()) {
+ // collect all intersection points with other edges for Trim operation only
+ std::list<FeaturePtr> aFeatures;
+ for (int i = 0; i < aSketch->numberOfSubs(); i++) {
+ FeaturePtr aFeature = aSketch->subFeature(i);
+ if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
+ aFeatures.push_back(aFeature);
+ }
+ ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPoints);
+ }
+
+ if (!aPoints.empty())
+ GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPoints, aShapes);
+ }
+ theObjectToPoints[theObject] = aPoints;
+ theCashedShapes[theObject] = aShapes;
+}
+
+void SketchPlugin_SegmentationTools::updateRefAttConstraints(
+ const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
+ const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes)
+{
+#if defined DEBUG_SPLIT || defined DEBUG_TRIM
+ std::cout << "updateRefAttConstraints" << std::endl;
+#endif
+
+ std::set<std::pair<AttributePtr, AttributePtr> >::const_iterator
+ anIt = theModifiedAttributes.begin(), aLast = theModifiedAttributes.end();
+ for (; anIt != aLast; anIt++) {
+ AttributePtr anAttribute = anIt->first;
+ AttributePtr aNewAttribute = anIt->second;
+
+ // not found in references
+ if (!aNewAttribute.get() ||
+ theBaseRefAttributes.find(anAttribute) == theBaseRefAttributes.end())
+ continue;
+ std::list<AttributePtr> aRefAttributes = theBaseRefAttributes.at(anAttribute);
+ std::list<AttributePtr>::const_iterator aRefIt = aRefAttributes.begin(),
+ aRLast = aRefAttributes.end();
+
+ for (; aRefIt != aRLast; aRefIt++) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
+ if (aRefAttr.get()) {
+ aRefAttr->setAttr(aNewAttribute);
+#ifdef DEBUG_SPLIT
+ FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->owner());
+ std::cout << " -" << getFeatureInfo(aFeature) << std::endl;
+#endif
+ }
+ }
+ }
+}
+
+void SketchPlugin_SegmentationTools::updateFeaturesAfterOperation(
+ const std::set<FeaturePtr>& theFeaturesToUpdate)
+{
+ std::set<FeaturePtr>::const_iterator anIt = theFeaturesToUpdate.begin(),
+ aLast = theFeaturesToUpdate.end();
+ for (; anIt != aLast; anIt++) {
+ FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
+ std::string aRefFeatureKind = aRefFeature->getKind();
+ if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) {
+ std::shared_ptr<SketchPlugin_ConstraintLength> aLenghtFeature =
+ std::dynamic_pointer_cast<SketchPlugin_ConstraintLength>(*anIt);
+ if (aLenghtFeature.get()) {
+ std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
+ ModelAPI_AttributeDouble>(aLenghtFeature->attribute(SketchPlugin_Constraint::VALUE()));
+ double aValue;
+ if (aLenghtFeature->computeLenghtValue(aValue) && aValueAttr.get())
+ aValueAttr->setValue(aValue);
+ }
+ }
+ }
+}
+
+AISObjectPtr SketchPlugin_SegmentationTools::getAISObject(
+ AISObjectPtr thePrevious,
+ SketchPlugin_Feature* theOpFeature,
+ const std::string& thePreviewObjectAttrName,
+ const std::string& thePreviewPointAttrName,
+ const std::string& theSelectedObjectAttrName,
+ const std::string& theSelectedPointAttrName)
+{
+#if defined DEBUG_SPLIT || defined DEBUG_TRIM_METHODS
+ std::cout << "getAISObject: " << theOpFeature->data()->name() << std::endl;
+#endif
+
+ AISObjectPtr anAIS = thePrevious;
+
+ std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
+ std::map<ObjectPtr, std::set<GeomShapePtr> > aCashedShapes;
+ std::map<ObjectPtr, GeomAlgoAPI_ShapeTools::PointToRefsMap> aObjectToPoints;
+ GeomShapePtr aPreviewShape = getSubShape(theOpFeature,
+ thePreviewObjectAttrName, thePreviewPointAttrName, aCashedShapes, aObjectToPoints);
+ if (aPreviewShape.get())
+ aShapes.push_back(aPreviewShape);
+ GeomShapePtr aSelectedShape = getSubShape(theOpFeature,
+ theSelectedObjectAttrName, theSelectedPointAttrName, aCashedShapes, aObjectToPoints);
+ if (aSelectedShape.get())
+ aShapes.push_back(aSelectedShape);
+
+ if (aShapes.empty())
+ return AISObjectPtr();
+
+ GeomShapePtr aBaseShape = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
+ if (!aBaseShape.get())
+ return AISObjectPtr();
+
+ if (aBaseShape.get()) {
+ if (!anAIS)
+ anAIS = AISObjectPtr(new GeomAPI_AISObject);
+ anAIS->createShape(aBaseShape);
+
+ std::vector<int> aColor;
+ aColor = Config_PropManager::color("Visualization", "operation_remove_feature_color");
+ double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH();
+ int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
+ anAIS->setColor(aColor[0], aColor[1], aColor[2]);
+ // width when there is not base object should be extened in several points
+ // in order to see this preview over highlight
+ anAIS->setWidth(aWidth+4);
+ anAIS->setLineStyle(aLineStyle);
+ }
+ else
+ anAIS = AISObjectPtr();
+ return anAIS;
+}
#include <ModelAPI_Feature.h>
#include <ModelAPI_Attribute.h>
#include <ModelAPI_AttributeRefAttr.h>
+#include <GeomAPI_Shape.h>
#include <GeomDataAPI_Point2D.h>
+#include <GeomAlgoAPI_ShapeTools.h>
+
+#include <list>
+#include <map>
+
+class GeomAPI_AISObject;
class SketchPlugin_Constraint;
class SketchPlugin_Feature;
GeomPnt2dPtr flyoutPointCoordinates(const std::shared_ptr<SketchPlugin_Constraint>& theConstraint);
}; // namespace SketchPlugin_Tools
+namespace SketchPlugin_SegmentationTools
+{
+ /// Returns geom point attribute of the feature bounds. It processes line or arc.
+ /// For circle/ellipse feature, the result attributes are null
+ /// \param theFeature a source feature
+ /// \param theStartPointAttr an out attribute to start point
+ /// \param theEndPointAttr an out attribute to end point
+ void getFeaturePoints(const FeaturePtr& theFeature,
+ std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
+ std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
+
+ /// Obtains references to feature point attributes and to feature,
+ /// e.g. for feature line: 1st container is
+ /// <1st line point, list<entity_a in distance, entity_b in parallel> >
+ /// <2nd line point, list<> >
+ /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
+ /// \param theFeature an investigated feature
+ /// \param theRefs a container of list of referenced attributes
+ /// \param theRefsToFeature references to the feature result
+ void getRefAttributes(const FeaturePtr& theFeature,
+ std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
+ std::list<AttributePtr>& theRefsToFeature);
+
+ /// Obtains a part of shape selected/highlighted in the viewer for Split/Trim operation
+ /// \param[in] theFeature Split/Trim feature
+ /// \param[in] theObjectAttributeId name of attribute containing selected object
+ /// \param[in] thePointAttributeId name of attribute containing point selected on the object
+ GeomShapePtr getSubShape(
+ SketchPlugin_Feature* theFeature,
+ const std::string& theObjectAttributeId,
+ const std::string& thePointAttributeId,
+ std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
+ std::map<ObjectPtr, GeomAlgoAPI_ShapeTools::PointToRefsMap>& theObjectToPoints);
+
+ /// Fulfill an internal containers by shapes obtained from the parameter object
+ /// Shapes are results of Split/Trim operation by points coincident to shape of the object
+ /// \param theOpFeture an operation feature (Split/Trim)
+ /// \param theObject a source object (will be splitted)
+ void fillObjectShapes(
+ SketchPlugin_Feature* theOpFeature,
+ const ObjectPtr& theObject,
+ std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
+ std::map<ObjectPtr, GeomAlgoAPI_ShapeTools::PointToRefsMap>& theObjectToPoints);
+
+ /// AIS object for selected/highlighted part of splitting/triming feature
+ /// \param[in] thePrevious previous presentation
+ /// \param[in] theOpFeture an operation feature (Split/Trim)
+ std::shared_ptr<GeomAPI_AISObject> getAISObject(std::shared_ptr<GeomAPI_AISObject> thePrevious,
+ SketchPlugin_Feature* theOpFeature,
+ const std::string& thePreviewObjectAttrName,
+ const std::string& thePreviewPointAttrName,
+ const std::string& theSelectedObjectAttrName,
+ const std::string& theSelectedPointAttrName);
+
+ /// Move constraints from attribute of base feature to attribute after modification
+ /// \param theBaseRefAttributes container of references to the attributes of base feature
+ /// \param theModifiedAttributes container of attributes placed instead of base attributes
+ /// at the same place
+ void updateRefAttConstraints(
+ const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
+ const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes);
+
+ /// Updates line length if it exist in the list
+ /// \param theFeaturesToUpdate a constraint index
+ void updateFeaturesAfterOperation(const std::set<FeaturePtr>& theFeaturesToUpdate);
+
+}; // namespace SketchPlugin_SegmentationTools
+
#endif // SKETCHPLUGIN_TOOLS_H_
\ No newline at end of file
#include <GeomAPI_XY.h>
#include <GeomDataAPI_Point2D.h>
#include <GeomAlgoAPI_ShapeTools.h>
-#include <GeomAlgoAPI_CompoundBuilder.h>
#include <ModelAPI_AttributeReference.h>
#include <ModelAPI_AttributeString.h>
#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Point.h>
-#include <SketchPlugin_Projection.h>
-#include <SketchPlugin_Tools.h>
#include <ModelAPI_EventReentrantMessage.h>
std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
anAttributePnt2d->y());
- if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
+ if (myCashedShapes.find(aBaseObject) == myCashedShapes.end()) {
+ SketchPlugin_SegmentationTools::fillObjectShapes(
+ this, aBaseObject, myCashedShapes, myObjectToPoints);
+ }
const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
if (!aShapes.empty()) {
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
ObjectPtr aBaseObject = aBaseObjectAttr->value();
- if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
- fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
+ if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end()) {
+ SketchPlugin_SegmentationTools::fillObjectShapes(
+ this, aBaseObject, myCashedShapes, myObjectToPoints);
+ }
bool aFound = false;
- const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
- for (PointToRefsMap::const_iterator aPointIt = aRefsMap.begin();
+ const GeomAlgoAPI_ShapeTools::PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
+ for (GeomAlgoAPI_ShapeTools::PointToRefsMap::const_iterator aPointIt = aRefsMap.begin();
aPointIt != aRefsMap.end() && !aFound; aPointIt++) {
if (aPointIt->first->isEqual(thePoint)) {
const std::pair<std::list<AttributePoint2DPtr >,
// find references(attributes and features) to the base feature
std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
std::list<AttributePtr> aRefsToFeature;
- getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature);
+ SketchPlugin_SegmentationTools::getRefAttributes(
+ aBaseFeature, aBaseRefAttributes, aRefsToFeature);
#ifdef DEBUG_TRIM
std::cout << "---- getRefAttributes ----" << std::endl;
std::map<AttributePtr, std::list<AttributePtr> >::const_iterator
restoreCurrentFeature();
// constraints to end points of trim feature
- if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
- fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
+ if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end()) {
+ SketchPlugin_SegmentationTools::fillObjectShapes(
+ this, aBaseObject, myCashedShapes, myObjectToPoints);
+ }
// create coincidence to objects, intersected the base object
- const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
+ const GeomAlgoAPI_ShapeTools::PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
for (std::set<AttributePoint2DPtr>::const_iterator anIt = aFurtherCoincidences.begin(),
aLast = aFurtherCoincidences.end();
anIt != aLast; anIt++) {
continue;
std::pair<std::list<AttributePoint2DPtr >, std::list<ObjectPtr > > anInfo;
- for (PointToRefsMap::const_iterator aRefIt = aRefsMap.begin(); aRefIt != aRefsMap.end();
- aRefIt++)
+ for (GeomAlgoAPI_ShapeTools::PointToRefsMap::const_iterator aRefIt = aRefsMap.begin();
+ aRefIt != aRefsMap.end(); aRefIt++)
{
if (aRefIt->first->isEqual(aPoint)) {
anInfo = aRefIt->second;
}
}
- updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes, aFeaturesToDelete);
+ SketchPlugin_SegmentationTools::updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes);
// Wait all constraints being created, then send update events
static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
- updateFeaturesAfterTrim(aFeaturesToUpdate);
+ SketchPlugin_SegmentationTools::updateFeaturesAfterOperation(aFeaturesToUpdate);
// Send events to update the sub-features by the solver.
if(isUpdateFlushed) {
std::shared_ptr<GeomAPI_Pnt2d> aPoint = aMessage->clickedPoint();
if (anObject.get() && aPoint.get()) {
- if (myCashedShapes.find(anObject) == myCashedShapes.end())
- fillObjectShapes(anObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
+ if (myCashedShapes.find(anObject) == myCashedShapes.end()) {
+ SketchPlugin_SegmentationTools::fillObjectShapes(
+ this, anObject, myCashedShapes, myObjectToPoints);
+ }
const std::set<GeomShapePtr>& aShapes = myCashedShapes[anObject];
if (aShapes.size() > 1) {
std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
- GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
+ GeomShapePtr aSelectedShape = SketchPlugin_SegmentationTools::getSubShape(this,
+ SELECTED_OBJECT(), SELECTED_POINT(), myCashedShapes, myObjectToPoints);
#ifdef DEBUG_TRIM_METHODS
if (!aSelectedShape.get())
std::cout << "Set empty selected object" << std::endl;
// get shape of the feature of the attribute
FeaturePtr anAttributeFeature = ModelAPI_Feature::feature(aRefAttr->object());
anAttributeFeature->execute(); // the modified value should be applyed to recompute shape
- PointToRefsMap aPointToAttributeOrObject;
+ GeomAlgoAPI_ShapeTools::PointToRefsMap aPointToAttributeOrObject;
std::list<FeaturePtr> aFeatures;
aFeatures.push_back(anAttributeFeature);
ModelGeomAlgo_Point2D::getPointsIntersectedShape(aTangentFeature, aFeatures,
AISObjectPtr SketchPlugin_Trim::getAISObject(AISObjectPtr thePrevious)
{
-#ifdef DEBUG_TRIM_METHODS
- std::cout << "SketchPlugin_Trim::getAISObject: " << data()->name() << std::endl;
-#endif
-
- AISObjectPtr anAIS = thePrevious;
-
- std::list<std::shared_ptr<GeomAPI_Shape> > aShapes;
- GeomShapePtr aPreviewShape = getSubShape(PREVIEW_OBJECT(), PREVIEW_POINT());
- if (aPreviewShape.get())
- aShapes.push_back(aPreviewShape);
- GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
- if (aSelectedShape.get())
- aShapes.push_back(aSelectedShape);
-
- if (aShapes.empty())
- return AISObjectPtr();
-
- GeomShapePtr aBaseShape = GeomAlgoAPI_CompoundBuilder::compound(aShapes);
- if (!aBaseShape.get())
- return AISObjectPtr();
-
- if (aBaseShape.get()) {
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createShape(aBaseShape);
-
- std::vector<int> aColor;
- aColor = Config_PropManager::color("Visualization", "operation_remove_feature_color");
- double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH();
- int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
- anAIS->setColor(aColor[0], aColor[1], aColor[2]);
- // width when there is not base object should be extened in several points
- // in order to see this preview over highlight
- anAIS->setWidth(aWidth+4);
- anAIS->setLineStyle(aLineStyle);
- }
- else
- anAIS = AISObjectPtr();
-
- return anAIS;
-}
-
-GeomShapePtr SketchPlugin_Trim::getSubShape(const std::string& theObjectAttributeId,
- const std::string& thePointAttributeId)
-{
- GeomShapePtr aBaseShape;
-
- AttributeReferencePtr anObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(theObjectAttributeId));
- ObjectPtr aBaseObject = anObjectAttr->value();
- if (!aBaseObject.get())
- return aBaseShape;
-
- // point on feature
- AttributePoint2DPtr aPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(thePointAttributeId));
- std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPointAttr->pnt();
- std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
- anAttributePnt2d->y());
-
- if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
-
- const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
- if (!aShapes.empty()) {
- std::set<GeomShapePtr>::const_iterator anIt = aShapes.begin(), aLast = aShapes.end();
- for (; anIt != aLast; anIt++) {
- GeomShapePtr aShape = *anIt;
- std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
- if (ModelGeomAlgo_Point2D::isPointOnEdge(aShape, anAttributePnt, aProjectedPoint))
- aBaseShape = aShape;
- }
- }
- return aBaseShape;
-}
-
-void SketchPlugin_Trim::getFeaturePoints(const FeaturePtr& theFeature,
- AttributePoint2DPtr& theStartPointAttr,
- AttributePoint2DPtr& theEndPointAttr)
-{
- std::string aFeatureKind = theFeature->getKind();
- std::string aStartAttributeName, anEndAttributeName;
- if (aFeatureKind == SketchPlugin_Line::ID()) {
- aStartAttributeName = SketchPlugin_Line::START_ID();
- anEndAttributeName = SketchPlugin_Line::END_ID();
- }
- else if (aFeatureKind == SketchPlugin_Arc::ID()) {
- aStartAttributeName = SketchPlugin_Arc::START_ID();
- anEndAttributeName = SketchPlugin_Arc::END_ID();
- }
- if (!aStartAttributeName.empty() && !anEndAttributeName.empty()) {
- theStartPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theFeature->attribute(aStartAttributeName));
- theEndPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- theFeature->attribute(anEndAttributeName));
- }
+ return SketchPlugin_SegmentationTools::getAISObject(thePrevious,
+ this, PREVIEW_OBJECT(), PREVIEW_POINT(), SELECTED_OBJECT(), SELECTED_POINT());
}
void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
}
}
-void SketchPlugin_Trim::getRefAttributes(const FeaturePtr& theFeature,
- std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
- std::list<AttributePtr>& theRefsToFeature)
-{
- theRefs.clear();
-
- std::list<AttributePtr> aPointAttributes =
- theFeature->data()->attributes(GeomDataAPI_Point2D::typeId());
- std::set<AttributePtr> aPointAttributesSet;
-
- std::list<AttributePtr>::const_iterator aPIt =
- aPointAttributes.begin(), aPLast = aPointAttributes.end();
- for (; aPIt != aPLast; aPIt++)
- aPointAttributesSet.insert(*aPIt);
-
- std::set<AttributePtr> aRefsAttributes = getFeatureResult(theFeature)->data()->refsToMe();
- std::set<AttributePtr> aFRefsList = theFeature->data()->refsToMe();
- aRefsAttributes.insert(aFRefsList.begin(), aFRefsList.end());
-
- std::set<AttributePtr>::const_iterator aIt;
- for (aIt = aRefsAttributes.cbegin(); aIt != aRefsAttributes.cend(); ++aIt) {
- AttributePtr anAttr = (*aIt);
- FeaturePtr anAttrFeature = ModelAPI_Feature::feature(anAttr->owner());
- if (anAttrFeature.get() != this &&
- anAttr.get() && anAttr->attributeType() == ModelAPI_AttributeRefAttr::typeId()) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttr);
- if (!aRefAttr->isObject()) { /// find attributes referenced to feature point attributes
- AttributePtr anAttrInRef = aRefAttr->attr();
- if (anAttrInRef.get() &&
- aPointAttributesSet.find(anAttrInRef) != aPointAttributesSet.end()) {
- if (theRefs.find(anAttrInRef) != theRefs.end())
- theRefs[anAttrInRef].push_back(aRefAttr);
- else {
- std::list<AttributePtr> anAttrList;
- anAttrList.push_back(aRefAttr);
- theRefs[anAttrInRef] = anAttrList;
- }
- }
- }
- else { /// find attributes referenced to feature itself
- theRefsToFeature.push_back(anAttr);
- }
- }
- }
-}
-
-void SketchPlugin_Trim::updateRefAttConstraints(
- const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
- const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
- std::set<FeaturePtr>& theFeaturesToDelete)
-{
-#ifdef DEBUG_TRIM
- std::cout << "SketchPlugin_Trim::updateRefAttConstraints" << std::endl;
-#endif
-
- std::set<std::pair<AttributePtr, AttributePtr> >::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())
- continue;
- std::list<AttributePtr> aRefAttributes = theBaseRefAttributes.at(anAttribute);
- std::list<AttributePtr>::const_iterator aRefIt = aRefAttributes.begin(),
- aRLast = aRefAttributes.end();
-
- AttributePtr aNewAttribute = anIt->second;
- if (aNewAttribute.get()) {
- for (; aRefIt != aRLast; aRefIt++) {
- AttributeRefAttrPtr aRefAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
- if (aRefAttr.get()) {
- aRefAttr->setAttr(aNewAttribute);
- }
- }
- }
- }
-}
-
void SketchPlugin_Trim::removeReferencesToAttribute(const AttributePtr& theAttribute,
std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes)
{
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
}
-void SketchPlugin_Trim::updateFeaturesAfterTrim(const std::set<FeaturePtr>& theFeaturesToUpdate)
-{
- std::set<FeaturePtr>::const_iterator anIt = theFeaturesToUpdate.begin(),
- aLast = theFeaturesToUpdate.end();
- for (; anIt != aLast; anIt++) {
- FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(*anIt);
- std::string aRefFeatureKind = aRefFeature->getKind();
- if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID()) {
- std::shared_ptr<SketchPlugin_ConstraintLength> aLenghtFeature =
- std::dynamic_pointer_cast<SketchPlugin_ConstraintLength>(*anIt);
- if (aLenghtFeature.get()) {
- std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
- ModelAPI_AttributeDouble>(aLenghtFeature->attribute(SketchPlugin_Constraint::VALUE()));
- double aValue;
- if (aLenghtFeature->computeLenghtValue(aValue) && aValueAttr.get())
- aValueAttr->setValue(aValue);
- }
- }
- }
-}
-
FeaturePtr SketchPlugin_Trim::trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
/// points of trim
AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
- getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
+ SketchPlugin_SegmentationTools::getFeaturePoints(
+ aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
std::shared_ptr<GeomAPI_Pnt2d> aStartFeaturePoint = aStartPointAttrOfBase->pnt();
std::shared_ptr<GeomAPI_Pnt2d> aLastFeaturePoint = anEndPointAttrOfBase->pnt();
/// points of trim
AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
- getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
+ SketchPlugin_SegmentationTools::getFeaturePoints(
+ aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
std::shared_ptr<GeomAPI_Pnt2d> aStartArcPoint = aStartPointAttrOfBase->pnt();
std::shared_ptr<GeomAPI_Pnt2d> aLastArcPoint = anEndPointAttrOfBase->pnt();
return aResult;
}
-
-//********************************************************************
-void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject,
- const ObjectPtr& theSketch,
- std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
- std::map<ObjectPtr, PointToRefsMap>& theObjectToPoints)
-{
- PointToRefsMap aPointsInfo;
-
- std::set<std::shared_ptr<GeomAPI_Shape> > aShapes;
- std::map<std::shared_ptr<GeomAPI_Pnt>,
- std::list< AttributePoint2DPtr > > aPointToAttributes;
- std::map<std::shared_ptr<GeomAPI_Pnt>,
- std::list< ObjectPtr > > aPointToObjects;
-
- std::set<AttributePoint2DPtr > aRefAttributes;
- // current feature
- FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
- std::set<ResultPtr> anEdgeShapes;
- // edges on feature
- ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
- if (!anEdgeShapes.empty()) {
- GeomShapePtr aFeatureShape = (*anEdgeShapes.begin())->shape();
-
- // coincidences to the feature
- ModelGeomAlgo_Point2D::getPointsOfReference(aFeature, SketchPlugin_ConstraintCoincidence::ID(),
- aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
- // layed on feature coincidences to divide it on several shapes
- std::shared_ptr<ModelAPI_Data> aData = theSketch->data();
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomAPI_Dir> aY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
-
- ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(),
- aX->dir(), aY, aPointsInfo);
-
- std::list<FeaturePtr> aFeatures;
- CompositeFeaturePtr aSketchComposite =
- std::dynamic_pointer_cast<ModelAPI_CompositeFeature>(theSketch);
- for (int i = 0; i < aSketchComposite->numberOfSubs(); i++) {
- FeaturePtr aFeature = aSketchComposite->subFeature(i);
- if (aFeature.get() && aFeature->getKind() != SketchPlugin_Projection::ID())
- aFeatures.push_back(aFeature);
- }
- ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);
-
- GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes);
- }
- theObjectToPoints[theObject] = aPointsInfo;
- theCashedShapes[theObject] = aShapes;
-}
#define SketchPlugin_Trim_H_
#include "SketchPlugin.h"
+#include <SketchPlugin_Tools.h>
-#include "GeomAPI_IPresentable.h"
+#include <GeomAPI_IPresentable.h>
#include <ModelAPI_IReentrant.h>
#include <SketchPlugin_Sketch.h>
/// Apply information of the message to current object. It fills selected point and object
virtual std::string processEvent(const std::shared_ptr<Events_Message>& theMessage);
- typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
- std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
- std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
-
- static void fillObjectShapes(const std::shared_ptr<ModelAPI_Object>& theObject,
- const std::shared_ptr<ModelAPI_Object>& theSketch,
- std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> >& theCashedShapes,
- std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap>& theObjectToPoints);
-
private:
bool setCoincidenceToAttribute(const AttributePtr& theAttribute,
const std::set<std::shared_ptr<GeomDataAPI_Point2D> >& theFurtherCoincidences,
/// \param theFeature a feature that can be set into the attribute
bool moveTangency(const AttributePtr& theAttribute, const FeaturePtr& theFeature);
- GeomShapePtr getSubShape(const std::string& theObjectAttributeId,
- const std::string& thePointAttributeId);
-
- /// Returns geom point attribute of the feature bounds. It processes line or arc.
- /// For circle feature, the result attributes are null
- /// \param theFeature a source feature
- /// \param theStartPointAttr an out attribute to start point
- /// \param theStartPointAttr an out attribute to end point
- void getFeaturePoints(const FeaturePtr& theFeature,
- std::shared_ptr<GeomDataAPI_Point2D>& theStartPointAttr,
- std::shared_ptr<GeomDataAPI_Point2D>& theEndPointAttr);
-
/// Obtains those constraints of the feature that should be modified. output maps contain
/// point of coincidence and attribute id to be modified after split
/// \param theFeaturesToDelete [out] constrains that will be deleted after split
void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
std::set<FeaturePtr>& theFeaturesToUpdate);
- /// Obtains references to feature point attributes and to feature,
- /// e.g. for feature line: 1st container is
- /// <1st line point, list<entity_a in distance, entity_b in parallel> >
- /// <2nd line point, list<> >
- /// for feature circle 2nd container is <entity_a in Radius, entity_b in equal, ...>
- /// \param theFeature an investigated feature
- /// \param theRefs a container of list of referenced attributes
- void getRefAttributes(const FeaturePtr& theFeature,
- std::map<AttributePtr, std::list<AttributePtr> >& theRefs,
- std::list<AttributePtr>& theRefsToFeature);
-
- /// Move constraints from attribute of base feature to attribute after modification
- /// \param theBaseRefAttributes container of references to the attributes of base feature
- /// \param theModifiedAttributes container of attributes placed instead of base attributes
- /// at the same place
- void updateRefAttConstraints(
- const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
- const std::set<std::pair<AttributePtr, AttributePtr> >& theModifiedAttributes,
- std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete);
-
/// Remove references constraints from attribute of base feature refer to the given attribute
/// \param theAttribute an attribute
/// \param theModifiedAttributes modifiable container of attributes
void removeReferencesToAttribute(const AttributePtr& theAttribute,
std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes);
- /// Updates line length if it exist in the list
- /// \param theFeaturesToUpdate a constraints container
- void updateFeaturesAfterTrim(const std::set<FeaturePtr>& theFeaturesToUpdate);
-
/// Make the base object is splitted by the point attributes
/// \param theBaseRefAttributes container of references to the attributes of base feature
/// \param thePoints a list of points where coincidences will be build
private:
std::map<std::shared_ptr<ModelAPI_Object>, std::set<GeomShapePtr> > myCashedShapes;
- std::map<std::shared_ptr<ModelAPI_Object>, PointToRefsMap> myObjectToPoints;
+ std::map<std::shared_ptr<ModelAPI_Object>,
+ GeomAlgoAPI_ShapeTools::PointToRefsMap> myObjectToPoints;
};
#endif
if (!anAttrFeature)
return aValid;
- std::string aKind = anAttrFeature->getKind();
- if (aKind == SketchPlugin_Line::ID() ||
- aKind == SketchPlugin_Arc::ID() ||
- aKind == SketchPlugin_Circle::ID()) {
-
- std::set<ResultPtr> anEdgeShapes;
- ModelGeomAlgo_Shape::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
- if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
- return aValid;
-
- // coincidences to the feature
- std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
- ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature,
- SketchPlugin_ConstraintCoincidence::ID(),
- aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
-
- GeomShapePtr anAttrShape = (*anEdgeShapes.begin())->shape();
- std::shared_ptr<SketchPlugin_Feature> aSFeature =
- std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
- SketchPlugin_Sketch* aSketch = aSFeature->sketch();
-
- std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
- std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
- aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
- std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
- aData->attribute(SketchPlugin_Sketch::NORM_ID()));
- std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
-
- typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
- std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
- std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
- PointToRefsMap aPointsInfo;
-
- ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
- aX->dir(), aDirY, aPointsInfo);
- int aCoincidentToFeature = (int)aPointsInfo.size();
- if (aKind == SketchPlugin_Circle::ID())
- aValid = aCoincidentToFeature >= 2;
- else
- aValid = aCoincidentToFeature >= 1;
- }
+ std::set<ResultPtr> anEdgeShapes;
+ ModelGeomAlgo_Shape::shapesOfType(anAttrFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
+ if (anEdgeShapes.empty() || anEdgeShapes.size() > 1 /*there case has not existed yet*/)
+ return aValid;
+
+ // coincidences to the feature
+ std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
+ ModelGeomAlgo_Point2D::getPointsOfReference(anAttrFeature,
+ SketchPlugin_ConstraintCoincidence::ID(),
+ aRefAttributes, SketchPlugin_Point::ID(), SketchPlugin_Point::COORD_ID());
+
+ GeomShapePtr anAttrShape = (*anEdgeShapes.begin())->shape();
+ std::shared_ptr<SketchPlugin_Feature> aSFeature =
+ std::dynamic_pointer_cast<SketchPlugin_Feature>(anAttrFeature);
+ SketchPlugin_Sketch* aSketch = aSFeature->sketch();
+
+ std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
+ std::shared_ptr<GeomDataAPI_Point> aC = std::dynamic_pointer_cast<GeomDataAPI_Point>(
+ aData->attribute(SketchPlugin_Sketch::ORIGIN_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aX = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::DIRX_ID()));
+ std::shared_ptr<GeomDataAPI_Dir> aNorm = std::dynamic_pointer_cast<GeomDataAPI_Dir>(
+ aData->attribute(SketchPlugin_Sketch::NORM_ID()));
+ std::shared_ptr<GeomAPI_Dir> aDirY(new GeomAPI_Dir(aNorm->dir()->cross(aX->dir())));
+
+ typedef std::map<std::shared_ptr<GeomAPI_Pnt>,
+ std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
+ std::list<std::shared_ptr<ModelAPI_Object> > > > PointToRefsMap;
+ PointToRefsMap aPointsInfo;
+
+ ModelGeomAlgo_Point2D::getPointsInsideShape(anAttrShape, aRefAttributes, aC->pnt(),
+ aX->dir(), aDirY, aPointsInfo);
+ int aCoincidentToFeature = (int)aPointsInfo.size();
+ if (anAttrFeature->getKind() == SketchPlugin_Circle::ID() ||
+ anAttrFeature->getKind() == SketchPlugin_Ellipse::ID())
+ aValid = aCoincidentToFeature >= 2;
+ else
+ aValid = aCoincidentToFeature >= 1;
return aValid;
}
if (!aSketchFeature.get() || aSketchFeature->isCopy())
return aValid;
- std::string aKind = aBaseFeature->getKind();
- if (aKind != SketchPlugin_Line::ID() &&
- aKind != SketchPlugin_Arc::ID() &&
- aKind != SketchPlugin_Circle::ID())
- return aValid;
-
// point on feature
AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
aTrimFeature->data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
std::map<ObjectPtr, std::map<std::shared_ptr<GeomAPI_Pnt>,
std::pair<std::list<std::shared_ptr<GeomDataAPI_Point2D> >,
std::list<std::shared_ptr<ModelAPI_Object> > > > > anObjectToPoints;
- SketchPlugin_Trim::fillObjectShapes(aBaseObject, aSketch->data()->owner(),
- aCashedShapes, anObjectToPoints);
+ SketchPlugin_SegmentationTools::fillObjectShapes(
+ aTrimFeature.get(), aBaseObject, aCashedShapes, anObjectToPoints);
const std::set<GeomShapePtr>& aShapes = aCashedShapes[aBaseObject];
return aShapes.size() > 1;