#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 <ModelAPI_Session.h>
#include <ModelAPI_AttributeDouble.h>
+#include <ModelGeomAlgo_Shape.h>
+
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_ConstraintMiddle.h>
#include <SketchPlugin_Circle.h>
static const double PI = 3.141592653589793238463;
static const std::string OPERATION_HIGHLIGHT_COLOR() { return "128, 0, 0"; }
+static const std::string OPERATION_REMOVE_FEATURE_COLOR() { return "255, 174, 201"; }
SketchPlugin_Trim::SketchPlugin_Trim()
{
void SketchPlugin_Trim::initAttributes()
{
- data()->addAttribute(SketchPlugin_Trim::BASE_OBJECT(), ModelAPI_AttributeReference::typeId());
- data()->addAttribute(ENTITY_POINT(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(SketchPlugin_Trim::SELECTED_OBJECT(),
+ ModelAPI_AttributeReference::typeId());
+ data()->addAttribute(SELECTED_POINT(), GeomDataAPI_Point2D::typeId());
+
+ data()->addAttribute(PREVIEW_POINT(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(PREVIEW_OBJECT(), ModelAPI_AttributeReference::typeId());
+
+ data()->attribute(PREVIEW_POINT())->setIsArgument(false);
+ data()->attribute(SELECTED_POINT())->setIsArgument(false);
+ data()->attribute(PREVIEW_OBJECT())->setIsArgument(false);
+
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_POINT());
+ ModelAPI_Session::get()->validators()->registerNotObligatory(getKind(), PREVIEW_OBJECT());
}
-void SketchPlugin_Trim::findShapePoints(std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
+void SketchPlugin_Trim::findShapePoints(const std::string& theObjectAttributeId,
+ const std::string& thePointAttributeId,
+ std::shared_ptr<GeomAPI_Pnt>& aStartPoint,
std::shared_ptr<GeomAPI_Pnt>& aLastPoint)
{
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+ data()->attribute(theObjectAttributeId));
ObjectPtr aBaseObject = aBaseObjectAttr->value();
AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(ENTITY_POINT()));
+ data()->attribute(thePointAttributeId));
std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
anAttributePnt2d->y());
if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject);
+ fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
if (!aShapes.empty()) {
if (aBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aBaseShape));
- aStartPoint = anEdge->lastPoint();
- aLastPoint = anEdge->firstPoint();
+ //GeomAPI_Shape::Orientation anOrientation = anEdge->orientation();
+ //if (anOrientation == GeomAPI_Shape::REVERSED) {
+ aStartPoint = anEdge->lastPoint();
+ aLastPoint = anEdge->firstPoint();
+ //}
+ //else {
+ //aStartPoint = anEdge->firstPoint();
+ //aLastPoint = anEdge->lastPoint();
+ //}
}
}
}
}
#ifdef DEBUG_TRIM
std::cout << "<findShapePoints> => "
- << "Start Point: ["
- << aStartPoint->x() << ", " << aStartPoint->y() << ", " << aStartPoint->z() << "]"
- << "Last Point: ["
- << aLastPoint->x() << ", " << aLastPoint->y() << ", " << aLastPoint->z() << "]"
- << std::endl;
+ << std::endl << "Attribute point: "
+ << anAttributePnt->x() << ", " << anAttributePnt->y() << ", " << anAttributePnt->z() << "]"
+ << std::endl << "Start Point: ["
+ << aStartPoint->x() << ", " << aStartPoint->y() << ", " << aStartPoint->z() << "]"
+ << std::endl << "Last Point: ["
+ << aLastPoint->x() << ", " << aLastPoint->y() << ", " << aLastPoint->z() << "]"
+ << std::endl;
#endif
}
std::shared_ptr<GeomAPI_Pnt2d> aPoint;
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+ data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
ObjectPtr aBaseObject = aBaseObjectAttr->value();
if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
- return aPoint;
+ fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
bool aFound = false;
const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
aFound = true;
}
else {
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- aPoint = thePoint->to2D(aPlane);
+ aPoint = sketch()->to2D(thePoint);
aFound = true;
}
}
}
if (!aFound) {
- // returns an end of the shape to define direction of split if feature's attribute participates
- std::shared_ptr<GeomAPI_Pln> aPlane = sketch()->plane();
- aPoint = thePoint->to2D(aPlane);
+ // returns an end of the shape to define direction of split if feature's attribute
+ // participates
+ aPoint = sketch()->to2D(thePoint);
}
return aPoint;
}
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+ data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
if(!aBaseObjectAttr->isInitialized()) {
setError("Error: Base object is not initialized.");
return;
return;
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
+ /// 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(SketchPlugin_Trim::PREVIEW_OBJECT()));
+ aPreviewObjectAttr->setValue(ResultPtr());
+
/// points of trim
std::shared_ptr<GeomAPI_Pnt> aStartShapePoint, aLastShapePoint;
- findShapePoints(aStartShapePoint, aLastShapePoint);
+#ifdef DEBUG_TRIM
+ std::cout << " Base Feature: " << aBaseFeature->data()->name() << std::endl;
+#endif
+ findShapePoints(SELECTED_OBJECT(), SELECTED_POINT(), aStartShapePoint, aLastShapePoint);
+
std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint2d = convertPoint(aLastShapePoint);
- std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
- getConstraints(aFeaturesToDelete, aFeaturesToUpdate);
+ std::set<FeaturePtr> aFeaturesToDelete;
+ getConstraints(aFeaturesToDelete);
std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
std::list<AttributePtr> aRefsToFeature;
getRefAttributes(aBaseFeature, aBaseRefAttributes, aRefsToFeature);
+#ifdef DEBUG_TRIM
+ std::cout << "---- getRefAttributes ----" << std::endl;
+ std::map<AttributePtr, std::list<AttributePtr> >::const_iterator
+ aRefIt = aBaseRefAttributes.begin(), aRefLast = aBaseRefAttributes.end();
+ std::cout << std::endl << "References to attributes of base feature [" <<
+ aBaseRefAttributes.size() << "]" << std::endl;
+ for (; aRefIt != aRefLast; aRefIt++) {
+ AttributePtr aBaseAttr = aRefIt->first;
+ std::list<AttributePtr> aRefAttributes = aRefIt->second;
+ std::string aRefsInfo;
+ std::list<AttributePtr>::const_iterator aRefAttrIt = aRefAttributes.begin(),
+ aRefAttrLast = aRefAttributes.end();
+ for (; aRefAttrIt != aRefAttrLast; aRefAttrIt++) {
+ if (!aRefsInfo.empty())
+ aRefsInfo.append(",");
+ AttributePtr aRAttr = *aRefAttrIt;
+ aRefsInfo.append(aRAttr->id());
+ FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner());
+ aRefsInfo.append("(" + aRFeature->name() + ") ");
+ }
+ std::shared_ptr<GeomDataAPI_Point2D> aPointAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aBaseAttr);
+ std::cout << aPointAttr->id().c_str() <<
+ ": " << "[" << aRefAttributes.size() << "] " << aRefsInfo << std::endl;
+ }
+ std::cout << std::endl;
+ std::cout << std::endl << "References to base feature [" <<
+ aRefsToFeature.size() << "]" << std::endl;
+ std::list<AttributePtr>::const_iterator aRefAttrIt = aRefsToFeature.begin(),
+ aRefAttrLast = aRefsToFeature.end();
+ std::string aRefsInfo;
+ for (; aRefAttrIt != aRefAttrLast; aRefAttrIt++) {
+ if (!aRefsInfo.empty())
+ aRefsInfo.append(",");
+ AttributePtr aRAttr = *aRefAttrIt;
+ aRefsInfo.append(aRAttr->id());
+ FeaturePtr aRFeature = ModelAPI_Feature::feature(aRAttr->owner());
+ aRefsInfo.append("(" + aRFeature->name() + ") ");
+ }
+ std::cout << "[" << aRefsToFeature.size() << "] " << aRefsInfo << std::endl;
+ std::cout << "---- getRefAttributes:end ----" << std::endl;
+#endif
+ // coincidence to result points
+ // find coincidences to the base object, it should be used when attribute is found
+ // in myObjectToPoints
+ //std::map<AttributePtr, FeaturePtr> aCoincidencesToBaseFeature;
+ //getCoincidencesToObject(aBaseObject, aCoincidencesToBaseFeature);
std::set<AttributePoint2DPtr> aFurtherCoincidences;
- std::set<FeaturePtr> aCreatedFeatures;
std::set<std::pair<AttributePtr, AttributePtr>> aModifiedAttributes;
const std::string& aKind = aBaseFeature->getKind();
+ FeaturePtr aReplacingFeature;
if (aKind == SketchPlugin_Circle::ID()) {
- trimCircle(aStartShapePoint2d, aLastShapePoint2d,
- aFurtherCoincidences, aCreatedFeatures, aModifiedAttributes);
- updateRefFeatureConstraints(getFeatureResult(aBaseFeature), aRefsToFeature);
+ aReplacingFeature = trimCircle(aStartShapePoint2d, aLastShapePoint2d,
+ aFurtherCoincidences, aModifiedAttributes);
aFeaturesToDelete.insert(aBaseFeature);
- // as circle is removed, temporary fill this attribute
+ // as circle is removed, erase it from dependencies(arguments) of this feature
+ // otherwise Trim feature will be removed with the circle before
+ // this operation is finished
aBaseObjectAttr->setObject(ResultPtr());
}
else if (aKind == SketchPlugin_Line::ID()) {
- trimLine(aStartShapePoint2d, aLastShapePoint2d,
- aFurtherCoincidences, aCreatedFeatures, aModifiedAttributes);
+ trimLine(aStartShapePoint2d, aLastShapePoint2d, aBaseRefAttributes,
+ aFurtherCoincidences, aModifiedAttributes);
}
else if (aKind == SketchPlugin_Arc::ID()) {
- trimArc(aStartShapePoint2d, aLastShapePoint2d,
- aFurtherCoincidences, aCreatedFeatures, aModifiedAttributes);
+ trimArc(aStartShapePoint2d, aLastShapePoint2d, aBaseRefAttributes,
+ aFurtherCoincidences, aModifiedAttributes);
}
- // coincidence to result points
+ // constraints to end points of trim feature
+ if (myObjectToPoints.find(aBaseObject) == myObjectToPoints.end())
+ fillObjectShapes(aBaseObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
+
+ // create coincidence to objects, intersected the base object
const PointToRefsMap& aRefsMap = myObjectToPoints.at(aBaseObject);
- std::set<AttributePoint2DPtr>::const_iterator anIt = aFurtherCoincidences.begin(),
- aLast = aFurtherCoincidences.end();
- for (; anIt != aLast; anIt++) {
+ for (std::set<AttributePoint2DPtr>::const_iterator anIt = aFurtherCoincidences.begin(),
+ aLast = aFurtherCoincidences.end();
+ anIt != aLast; anIt++) {
AttributePoint2DPtr aPointAttribute = (*anIt);
std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
+#ifdef DEBUG_TRIM
+ std::cout << "<compare Points> => " << std::endl
+ << "aPoint2d: [" << aPoint2d->x() << ", " << aPoint2d->y() << "]" << std::endl;
+ if (aStartShapePoint2d.get())
+ std::cout << "Start Point: [" << aStartShapePoint2d->x() << ", " << aStartShapePoint2d->y()
+ << "]" << std::endl;
+ if (aLastShapePoint2d.get())
+ std::cout << "Last Point: [" << aLastShapePoint2d->x() << ", " << aLastShapePoint2d->y()
+ << "]" << std::endl;
+#endif
+
std::shared_ptr<GeomAPI_Pnt> aPoint;
if (aStartShapePoint2d.get() && aPoint2d->isEqual(aStartShapePoint2d))
aPoint = aStartShapePoint;
break;
}
}
- const std::list<AttributePoint2DPtr >& anAttributes = anInfo.first;
- for (std::list<AttributePoint2DPtr>::const_iterator anAttrIt = anAttributes.begin();
- anAttrIt != anAttributes.end(); anAttrIt++) {
- createConstraint(SketchPlugin_ConstraintCoincidence::ID(), aPointAttribute, *anAttrIt);
- }
-
const std::list<ObjectPtr>& anObjects = anInfo.second;
for (std::list<ObjectPtr>::const_iterator anObjectIt = anObjects.begin();
anObjectIt != anObjects.end(); anObjectIt++) {
- createConstraint(SketchPlugin_ConstraintCoincidence::ID(), aPointAttribute, *anObjectIt);
+ createConstraintToObject(SketchPlugin_ConstraintCoincidence::ID(), aPointAttribute,
+ *anObjectIt);
}
}
+ // move constraints from base feature to replacing feature: ignore coincidences to feature
+ // if attributes of coincidence participated in split
+ ResultPtr aReplacingResult;
+ if (aReplacingFeature.get()) {
+ aReplacingFeature->execute(); // need it to obtain result
+ aReplacingResult = getFeatureResult(aReplacingFeature);
+ }
+ for(std::list<AttributePtr>::const_iterator anIt = aRefsToFeature.begin(),
+ aLast = aRefsToFeature.end();
+ anIt != aLast; anIt++) {
+ AttributePtr anAttribute = *anIt;
+
+ //if (replaceCoincidenceAttribute(anAttribute, aModifiedAttributes))
+ // continue;
+
+ if (setCoincidenceToAttribute(anAttribute, aFurtherCoincidences))
+ continue;
+
+ if (aReplacingResult.get()) {
+ AttributeRefAttrPtr aRefAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
+ if (aRefAttr.get())
+ aRefAttr->setObject(aReplacingResult);
+ else {
+ AttributeReferencePtr aReferenceAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(anAttribute);
+ if (aReferenceAttr.get())
+ aReferenceAttr->setObject(aReplacingResult);
+ }
+ }
+ }
+
+ updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes, aFeaturesToDelete);
+
// Wait all constraints being created, then send update events
static Events_ID anUpdateEvent = Events_Loop::eventByName(EVENT_OBJECT_UPDATED);
bool isUpdateFlushed = Events_Loop::loop()->isFlushed(anUpdateEvent);
if (isUpdateFlushed)
Events_Loop::loop()->setFlushed(anUpdateEvent, false);
- updateRefAttConstraints(aBaseRefAttributes, aModifiedAttributes, aFeaturesToDelete);
-
// delete constraints
#ifdef DEBUG_TRIM
- std::cout << "remove features and references:" << std::endl;
- std::set<FeaturePtr>::const_iterator aDIt = aFeaturesToDelete.begin(),
- aDLast = aFeaturesToDelete.end();
- for (; aDIt != aDLast; aDIt++) {
- //std::cout << getFeatureInfo(*aDIt, false) << std::endl;
- //std::cout << std::endl;
+ if (aFeaturesToDelete.size() > 0) {
+ std::cout << "after SPlit: removeFeaturesAndReferences: " << std::endl;
+ std::string aValue;
+ for (std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin();
+ anIt != aFeaturesToDelete.end(); anIt++) {
+ FeaturePtr aFeature = *anIt;
+ std::cout << aFeature->data()->name() << std::endl;
+ }
}
#endif
ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
#endif
}
+bool SketchPlugin_Trim::setCoincidenceToAttribute(const AttributePtr& theAttribute,
+ const std::set<AttributePoint2DPtr>& theFurtherCoincidences)
+{
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theAttribute->owner());
+ if (aFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+ return false;
+
+ AttributePoint2DPtr aRefPointAttr = SketchPlugin_ConstraintCoincidence::getPoint(aFeature);
+ if (!aRefPointAttr.get())
+ return false;
+ std::shared_ptr<GeomAPI_Pnt2d> aRefPnt2d = aRefPointAttr->pnt();
+
+ std::set<AttributePoint2DPtr>::const_iterator anIt = theFurtherCoincidences.begin(),
+ aLast = theFurtherCoincidences.end();
+ bool aFoundPoint = false;
+ for (; anIt != aLast && !aFoundPoint; anIt++) {
+ AttributePoint2DPtr aPointAttribute = (*anIt);
+ std::shared_ptr<GeomAPI_Pnt2d> aPoint2d = aPointAttribute->pnt();
+ if (aPoint2d->isEqual(aRefPnt2d)) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ theAttribute);
+ if (aRefAttr.get()) {
+ aRefAttr->setAttr(aPointAttribute);
+ aFoundPoint = true;
+ }
+ }
+ }
+ return aFoundPoint;
+}
+
+bool SketchPlugin_Trim::replaceCoincidenceAttribute(const AttributePtr& theCoincidenceAttribute,
+ const std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
+{
+ FeaturePtr aCoincidenceFeature = ModelAPI_Feature::feature(theCoincidenceAttribute->owner());
+ if (aCoincidenceFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+ return false;
+
+ AttributeRefAttrPtr aCAttrA = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aCoincidenceFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ AttributeRefAttrPtr aCAttrB = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aCoincidenceFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ AttributePtr aCAttrRefA = aCAttrA->attr();
+ AttributePtr aCAttrRefB = aCAttrB->attr();
+
+ bool isProcessed = false;
+ for (std::set<std::pair<AttributePtr, AttributePtr>>::const_iterator
+ anIt = theModifiedAttributes.begin(); anIt != theModifiedAttributes.end(); anIt++) {
+ AttributePtr anAttributeBefore = anIt->first;
+ if (anAttributeBefore == aCAttrRefA) {
+ aCAttrA->setAttr(anIt->second);
+ isProcessed = true;
+ }
+ if (anAttributeBefore == aCAttrRefB) {
+ aCAttrB->setAttr(anIt->second);
+ isProcessed = true;
+ }
+ }
+ return isProcessed;
+}
+
bool SketchPlugin_Trim::isMacro() const
{
return true;
AISObjectPtr SketchPlugin_Trim::getAISObject(AISObjectPtr thePrevious)
{
AISObjectPtr anAIS = thePrevious;
- // feature for trim
- AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
- ObjectPtr aBaseObject = aBaseObjectAttr->value();
+
+ 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 anAIS;
- FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
+ return aBaseShape;
// point on feature
AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(ENTITY_POINT()));
+ data()->attribute(thePointAttributeId));
std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
anAttributePnt2d->y());
if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject);
+ 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 aBaseShape = *anIt;
+ GeomShapePtr aShape = *anIt;
std::shared_ptr<GeomAPI_Pnt> aProjectedPoint;
- if (ModelGeomAlgo_Point2D::isPointOnEdge(aBaseShape, anAttributePnt, aProjectedPoint)) {
- if (aBaseShape) {
- if (!anAIS)
- anAIS = AISObjectPtr(new GeomAPI_AISObject);
- anAIS->createShape(aBaseShape);
-
- std::shared_ptr<ModelAPI_AttributeBoolean> anAuxiliaryAttr =
- aBaseFeature->data()->boolean(SketchPlugin_SketchEntity::AUXILIARY_ID());
-
- bool isConstruction = anAuxiliaryAttr.get() != NULL && anAuxiliaryAttr->value();
-
- std::vector<int> aColor;
- aColor = Config_PropManager::color("Visualization", "operation_highlight_color",
- OPERATION_HIGHLIGHT_COLOR());
- double aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH();
- int aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE();
- if (isConstruction) {
- aWidth = SketchPlugin_SketchEntity::SKETCH_LINE_WIDTH_AUXILIARY();
- aLineStyle = SketchPlugin_SketchEntity::SKETCH_LINE_STYLE_AUXILIARY();
- }
- anAIS->setColor(aColor[0], aColor[1], aColor[2]);
- // modification of width should be replaced to value 1 after highlight problem is fixed
- anAIS->setWidth(aWidth + 2);//1);
- anAIS->setLineStyle(aLineStyle);
- break;
- }
- }
+ if (ModelGeomAlgo_Point2D::isPointOnEdge(aShape, anAttributePnt, aProjectedPoint))
+ aBaseShape = aShape;
}
}
-
- return anAIS;
+ return aBaseShape;
}
void SketchPlugin_Trim::getFeaturePoints(const FeaturePtr& theFeature,
}
}
-void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
- std::set<FeaturePtr>& theFeaturesToUpdate)
+void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete)
{
std::shared_ptr<ModelAPI_Data> aData = data();
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- aData->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+ aData->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
aRefFeatureKind == SketchPlugin_MultiTranslation::ID() ||
aRefFeatureKind == SketchPlugin_ConstraintMiddle::ID())
theFeaturesToDelete.insert(aRefFeature);
- else if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID())
- theFeaturesToUpdate.insert(aRefFeature);
- else if (aRefFeatureKind == SketchPlugin_ConstraintTangent::ID()) {
- if (aBaseFeature->getKind() == SketchPlugin_Circle::ID()) /// TEMPORARY limitaion
- /// until tangency between arc and line is implemented
- theFeaturesToDelete.insert(aRefFeature);
- else {
- std::string anAttributeToBeModified;
- AttributePoint2DPtr aTangentPoint;
- ObjectPtr aResult1 = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_A())->object();
- ObjectPtr aResult2 = aRefFeature->refattr(SketchPlugin_Constraint::ENTITY_B())->object();
- if (aResult1.get() && aResult2.get()) {
- FeaturePtr aCoincidenceFeature =
- SketchPlugin_ConstraintCoincidence::findCoincidenceFeature
- (ModelAPI_Feature::feature(aResult1),
- ModelAPI_Feature::feature(aResult2));
- // get the point not lying on the splitting feature
- for (int i = 0; i < CONSTRAINT_ATTR_SIZE; ++i) {
- AttributeRefAttrPtr aRefAttr = aCoincidenceFeature->refattr(
- SketchPlugin_Trim::BASE_OBJECT());
- if (!aRefAttr || aRefAttr->isObject())
- continue;
- AttributePoint2DPtr aPoint =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(aRefAttr->attr());
- if (!aPoint)
- continue;
- if (aPoint->owner() != aBaseFeature) {
- aTangentPoint = aPoint;
- break;
- }
- }
- }
- if (aTangentPoint.get()) {
- // collect tangent feaures
- }
- else /// there is not coincident point between tangent constraint
- theFeaturesToDelete.insert(aRefFeature);
- }
- }
}
}
}
}
-void SketchPlugin_Trim::updateRefFeatureConstraints(
- const ResultPtr& theFeatureBaseResult,
- const std::list<AttributePtr>& theRefsToFeature)
+/*void SketchPlugin_Trim::getCoincidencesToObject(const ObjectPtr& theObject,
+ std::map<AttributePtr, FeaturePtr>& theCoincidencesToBaseFeature)
{
- std::list<AttributePtr>::const_iterator anIt = theRefsToFeature.begin(),
- aLast = theRefsToFeature.end();
- for (; anIt != aLast; anIt++) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*anIt);
- if (aRefAttr.get())
- aRefAttr->setObject(theFeatureBaseResult);
+ const std::set<AttributePtr>& aRefsList = theObject->data()->refsToMe();
+ std::set<AttributePtr>::const_iterator aIt;
+ for (aIt = aRefsList.cbegin(); aIt != aRefsList.cend(); ++aIt) {
+ std::shared_ptr<ModelAPI_Attribute> aAttr = (*aIt);
+ FeaturePtr aRefFeature = std::dynamic_pointer_cast<ModelAPI_Feature>(aAttr->owner());
+ if (aRefFeature->getKind() != SketchPlugin_ConstraintCoincidence::ID())
+ continue;
+ AttributePtr anAttribute;
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+ (aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ if (aRefAttr->isObject() && aRefAttr->object() == theObject)
+ {
+ anAttribute = aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_B());
+ }
+ else {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>
+ (aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ if (aRefAttr->isObject() && aRefAttr->object() == theObject)
+ anAttribute = aRefFeature->attribute(SketchPlugin_Constraint::ENTITY_A());
+ }
+ if (!anAttribute.get())
+ continue;
+
+ aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(anAttribute);
+ if (aRefAttr->isObject())
+ continue; // one of attributes of coincidence contains link to an attribute
+
+ anAttribute = aRefAttr->attr();
+ if (anAttribute.get())
+ {
+ theCoincidencesToBaseFeature[anAttribute] = aRefFeature;
+ }
}
-}
+}*/
void SketchPlugin_Trim::updateRefAttConstraints(
const std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
aRLast = aRefAttributes.end();
AttributePtr aNewAttribute = anIt->second;
- for (; aRefIt != aRLast; aRefIt++) {
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
- if (aRefAttr.get()) {
- if (aNewAttribute.get())
- aRefAttr->setAttr(aNewAttribute);
- else
- theFeaturesToDelete.insert(ModelAPI_Feature::feature(aRefAttr->owner()));
-#ifdef DEBUG_TRIM
- //FeaturePtr aFeature = ModelAPI_Feature::feature(aRefAttr->owner());
- //std::cout << " -" << getFeatureInfo(aFeature) << std::endl;
-#endif
+ 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)
+{
+ /// not found in references
+ if (theBaseRefAttributes.find(theAttribute) == theBaseRefAttributes.end())
+ return;
+
+ std::list<AttributePtr> aRefAttributes = theBaseRefAttributes.at(theAttribute);
+ std::list<AttributePtr>::const_iterator aRefIt = aRefAttributes.begin(),
+ aRLast = aRefAttributes.end();
+
+ std::set<FeaturePtr> aFeaturesToDelete;
+ for (; aRefIt != aRLast; aRefIt++) {
+ AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(*aRefIt);
+ if (aRefAttr.get()) {
+ aFeaturesToDelete.insert(ModelAPI_Feature::feature(aRefAttr->owner()));
+ }
+ }
+
+#ifdef DEBUG_TRIM
+ // delete constraints
+ if (aFeaturesToDelete.size() > 0) {
+ std::cout << "removeReferencesToAttribute: " << std::endl;
+ std::string aValue;
+ for (std::set<FeaturePtr>::const_iterator anIt = aFeaturesToDelete.begin();
+ anIt != aFeaturesToDelete.end(); anIt++) {
+ FeaturePtr aFeature = *anIt;
+ std::cout << aFeature->data()->name() << std::endl;
+ }
+ }
+#endif
+ ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+}
+
void SketchPlugin_Trim::trimLine(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
- std::set<AttributePoint2DPtr>& thePoints,
- std::set<FeaturePtr>& theCreatedFeatures,
+ const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
+ std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
+ std::set<AttributePoint2DPtr>& thePoints,
std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
{
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+ data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
ObjectPtr aBaseObject = aBaseObjectAttr->value();
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
else
aPoint = aStartShapePoint.get() ? aStartShapePoint : aLastShapePoint;
+ // it is important to delete references before the feature modification because
+ // if deletion will be after the feature modification, solver returns the feature back
+ removeReferencesToAttribute(aBaseFeature->attribute(aModifiedAttribute),
+ theBaseRefAttributes);
+
fillPointAttribute(aBaseFeature->attribute(aModifiedAttribute), aPoint);
- theModifiedAttributes.insert(
- std::make_pair(aBaseFeature->attribute(aModifiedAttribute), AttributePtr()));
+ //theModifiedAttributes.insert(
+ // std::make_pair(aBaseFeature->attribute(aModifiedAttribute), AttributePtr()));
thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aBaseFeature->attribute(aModifiedAttribute)));
}
else {
- // result is two lines: start line point - start shape point, last shape point - last line point
+ // result is two lines: start line point - start shape point,
+ // last shape point - last line point
// create second line
FeaturePtr anNewFeature = createLineFeature(aBaseFeature, aLastShapePoint, aLastFeaturePoint);
thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
}
void SketchPlugin_Trim::trimArc(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
- const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
- std::set<AttributePoint2DPtr>& thePoints,
- std::set<FeaturePtr>& theCreatedFeatures,
+ const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
+ std::map<AttributePtr, std::list<AttributePtr> >& theBaseRefAttributes,
+ std::set<AttributePoint2DPtr>& thePoints,
std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
{
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+ data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
ObjectPtr aBaseObject = aBaseObjectAttr->value();
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
#ifdef DEBUG_TRIM
std::cout << "Arranged points (to build split between 1st and 2nd points:" << std::endl;
if (aStartShapePoint.get())
- std::cout << "Start point: [" << aStartShapePoint->x() << ", " <<
+ std::cout << "Start shape point: [" << aStartShapePoint->x() << ", " <<
aStartShapePoint->y() << "]" << std::endl;
- std::cout << "1st point: [" << aStartArcPoint->x() << ", " <<
+ std::cout << "Start arc attribute point: [" << aStartArcPoint->x() << ", " <<
aStartArcPoint->y() << "]" << std::endl;
if (aLastShapePoint.get())
- std::cout << "2st point: [" << aLastShapePoint->x() << ", " <<
+ std::cout << "Last shape point: [" << aLastShapePoint->x() << ", " <<
aLastShapePoint->y() << "]" << std::endl;
- std::cout << "End point: [" << aLastArcPoint->x() << ", " <<
+ std::cout << "Last arc attribute point: [" << aLastArcPoint->x() << ", " <<
aLastArcPoint->y() << "]" << std::endl;
#endif
else
aPoint = aStartShapePoint.get() ? aStartShapePoint : aLastShapePoint;
+ removeReferencesToAttribute(aBaseFeature->attribute(aModifiedAttribute),
+ theBaseRefAttributes);
+
fillPointAttribute(aBaseFeature->attribute(aModifiedAttribute), aPoint);
- theModifiedAttributes.insert(
- std::make_pair(aBaseFeature->attribute(aModifiedAttribute), AttributePtr()));
thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
(aBaseFeature->attribute(aModifiedAttribute)));
(aBaseFeature->attribute(aModifiedAttribute)));
// equal Radius constraint for arcs
+ anArcFeature->execute(); // we need the created arc result to set equal constraint
createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
getFeatureResult(aBaseFeature),
getFeatureResult(anArcFeature));
createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
aBaseFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
anArcFeature->attribute(SketchPlugin_Arc::CENTER_ID()));
+
+ std::cout << "Created arc on points:" << std::endl;
+ std::cout << "Start shape point: [" << aStartShapePoint->x() << ", " <<
+ aStartShapePoint->y() << "]" << std::endl;
+
}
}
-void SketchPlugin_Trim::trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
+FeaturePtr SketchPlugin_Trim::trimCircle(const std::shared_ptr<GeomAPI_Pnt2d>& theStartShapePoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theLastShapePoint,
std::set<AttributePoint2DPtr>& thePoints,
- std::set<FeaturePtr>& theCreatedFeatures,
std::set<std::pair<AttributePtr, AttributePtr>>& theModifiedAttributes)
{
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
+ data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
ObjectPtr aBaseObject = aBaseObjectAttr->value();
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
/// points of trim
- AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
- getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
+ //AttributePoint2DPtr aStartPointAttrOfBase, anEndPointAttrOfBase;
+ //getFeaturePoints(aBaseFeature, aStartPointAttrOfBase, anEndPointAttrOfBase);
/// trim feature
FeaturePtr anArcFeature = createArcFeature(aBaseFeature, theStartShapePoint, theLastShapePoint);
+ // arc created by trim of circle is always correct, that means that it is not inversed
+ anArcFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(false);
theModifiedAttributes.insert(
std::make_pair(aBaseFeature->attribute(SketchPlugin_Circle::CENTER_ID()),
(anArcFeature->attribute(SketchPlugin_Arc::START_ID())));
thePoints.insert(std::dynamic_pointer_cast<GeomDataAPI_Point2D>
(anArcFeature->attribute(SketchPlugin_Arc::END_ID())));
+
+ return anArcFeature;
}
void SketchPlugin_Trim::arrangePointsOnLine(const AttributePoint2DPtr& theStartPointAttr,
std::shared_ptr<GeomAPI_Pnt2d> aCenter = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
theArc->attribute(SketchPlugin_Arc::CENTER_ID()))->pnt();
- bool isReversed = theArc->boolean(SketchPlugin_Arc::INVERSED_ID())->value();
+ bool isReversed = theArc->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
// collect directions to each point
std::shared_ptr<GeomAPI_Dir2d> aStartDir(
aModifiedAttribute->setValue(thePoint);
#ifdef DEBUG_TRIM
- std::cout << "<fillPointAttribute> => Pnt2d - [" << thePoint->x() << ", "
- << thePoint->y() << "]" << std::endl;
+ FeaturePtr aFeature = ModelAPI_Feature::feature(theModifiedAttribute->owner());
+ std::cout << "<fillPointAttribute[" << aFeature->data()->name() << ": " <<
+ theModifiedAttribute->id() <<
+ "]> => Pnt2d - [" << thePoint->x() << ", " << thePoint->y() << "]" << std::endl;
#endif
}
}
const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint)
{
+#ifdef DEBUG_TRIM
+ std::cout << "---- createLineFeature ---" << std::endl;
+#endif
+
FeaturePtr aFeature;
SketchPlugin_Sketch* aSketch = sketch();
if (!aSketch || !theBaseFeature.get())
aFeature->execute(); // to obtain result
+#ifdef DEBUG_TRIM
+ std::cout << "---- createLineFeature:end ---" << std::endl;
+#endif
+
return aFeature;
}
-
FeaturePtr SketchPlugin_Trim::createArcFeature(const FeaturePtr& theBaseFeature,
const std::shared_ptr<GeomAPI_Pnt2d>& theFirstPoint,
const std::shared_ptr<GeomAPI_Pnt2d>& theSecondPoint)
if (aCenterAttributeId.empty())
return aFeature;
+#ifdef DEBUG_TRIM
+ std::cout << "---- createArcFeature ---" << std::endl;
+#endif
+
aFeature = aSketch->addFeature(SketchPlugin_Arc::ID());
// update fillet arc: make the arc correct for sure, so, it is not needed to process
// the "attribute updated"
// by arc; moreover, it may cause cyclicity in hte mechanism of updater
bool aWasBlocked = aFeature->data()->blockSendAttributeUpdated(true);
- aFeature->string(SketchPlugin_Arc::ARC_TYPE())->setValue(
- SketchPlugin_Arc::ARC_TYPE_CENTER_START_END());
-
fillAttribute(aFeature->attribute(SketchPlugin_Arc::CENTER_ID()),
theBaseFeature->attribute(aCenterAttributeId));
fillPointAttribute(aFeature->attribute(SketchPlugin_Arc::START_ID()), theFirstPoint);
/// fill referersed state of created arc as it is on the base arc
if (theBaseFeature->getKind() == SketchPlugin_Arc::ID()) {
- bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->value();
- aFeature->boolean(SketchPlugin_Arc::INVERSED_ID())->setValue(aReversed);
+ bool aReversed = theBaseFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->value();
+ aFeature->boolean(SketchPlugin_Arc::REVERSED_ID())->setValue(aReversed);
}
- aFeature->execute(); // to obtain result
+ //aFeature->execute(); // to obtain result
aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
+ #ifdef DEBUG_TRIM
+ std::cout << "---- createArcFeature:end ---" << std::endl;
+ #endif
+
return aFeature;
}
return aConstraint;
}
-FeaturePtr SketchPlugin_Trim::createConstraint(const std::string& theConstraintId,
+FeaturePtr SketchPlugin_Trim::createConstraintToObject(const std::string& theConstraintId,
const AttributePtr& theFirstAttribute,
const ObjectPtr& theSecondObject)
{
}
//********************************************************************
-bool SketchPlugin_Trim::useGraphicIntersection() const
-{
- return true;
-}
-
-//********************************************************************
-void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject)
+void SketchPlugin_Trim::fillObjectShapes(const ObjectPtr& theObject,
+ const ObjectPtr& theSketch,
+ std::map<ObjectPtr, std::set<GeomShapePtr> >& theCashedShapes,
+ std::map<ObjectPtr, PointToRefsMap>& theObjectToPoints)
{
PointToRefsMap aPointsInfo;
FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
std::set<ResultPtr> anEdgeShapes;
// edges on feature
- ModelAPI_Tools::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
+ ModelGeomAlgo_Shape::shapesOfType(aFeature, GeomAPI_Shape::EDGE, anEdgeShapes);
if (!anEdgeShapes.empty()) {
GeomShapePtr aFeatureShape = (*anEdgeShapes.begin())->shape();
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
- SketchPlugin_Sketch* aSketch = sketch();
- std::shared_ptr<ModelAPI_Data> aData = aSketch->data();
+ //SketchPlugin_Sketch* aSketch = sketch();
+ 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>(
ModelGeomAlgo_Point2D::getPointsInsideShape(aFeatureShape, aRefAttributes, aC->pnt(),
aX->dir(), aY, aPointsInfo);
- // intersection points
- if (useGraphicIntersection()) {
- std::list<FeaturePtr> aFeatures;
- for (int i = 0; i < aSketch->numberOfSubs(); i++) {
- FeaturePtr aFeature = aSketch->subFeature(i);
- if (aFeature.get())
- aFeatures.push_back(aFeature);
- }
- ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, 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())
+ aFeatures.push_back(aFeature);
}
- GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes);
- }
- myObjectToPoints[theObject] = aPointsInfo;
- myCashedShapes[theObject] = aShapes;
-}
+ ModelGeomAlgo_Point2D::getPointsIntersectedShape(aFeature, aFeatures, aPointsInfo);
-//********************************************************************
-void SketchPlugin_Trim::attributeChanged(const std::string& theID)
-{
- //data()->addAttribute(SketchPlugin_Trim::BASE_OBJECT(), ModelAPI_AttributeReference::typeId());
- if (theID == SketchPlugin_Trim::BASE_OBJECT()) {
- bool isValidAttribute = false;
- // feature for trim
- AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::BASE_OBJECT()));
- ObjectPtr aBaseObject = aBaseObjectAttr->value();
- if (aBaseObject.get()) {
- FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
- // point on feature
- AttributePoint2DPtr aPoint = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(ENTITY_POINT()));
- std::shared_ptr<GeomAPI_Pnt2d> anAttributePnt2d = aPoint->pnt();
- std::shared_ptr<GeomAPI_Pnt> anAttributePnt = sketch()->to3D(anAttributePnt2d->x(),
- anAttributePnt2d->y());
-
- if (myCashedShapes.find(aBaseObject) == myCashedShapes.end())
- fillObjectShapes(aBaseObject);
-
- const std::set<GeomShapePtr>& aShapes = myCashedShapes[aBaseObject];
- isValidAttribute = !aShapes.empty();
-
- if (!isValidAttribute) {
- bool aWasBlocked = data()->blockSendAttributeUpdated(true);
- aBaseObjectAttr->setValue(ObjectPtr());
- data()->blockSendAttributeUpdated(aWasBlocked);
- }
- }
+ GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPointsInfo, aShapes);
}
+ theObjectToPoints[theObject] = aPointsInfo;
+ theCashedShapes[theObject] = aShapes;
}