#endif
SketchPlugin_Sketch* aSketch = sketch();
- if (!aSketch)
+ if (!aSketch) {
+ setError("Error: Sketch object is empty.");
return;
+ }
// Check the base objects are initialized.
AttributeReferencePtr aBaseObjectAttr = std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
return;
}
ObjectPtr aBaseObject = aBaseObjectAttr->value();
- if (!aBaseObject.get())
+ if (!aBaseObject.get()) {
+ setError("Error: Base object is not initialized.");
return;
+ }
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
/// Remove reference of this feature to feature used in preview, it is not necessary anymore
std::shared_ptr<GeomAPI_Pnt2d> aStartShapePoint2d = convertPoint(aStartShapePoint);
std::shared_ptr<GeomAPI_Pnt2d> aLastShapePoint2d = convertPoint(aLastShapePoint);
- std::set<FeaturePtr> aFeaturesToDelete;
- getConstraints(aFeaturesToDelete);
+ std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
+ getConstraints(aFeaturesToDelete, aFeaturesToUpdate);
std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
std::list<AttributePtr> aRefsToFeature;
ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_DELETED));
+ updateFeaturesAfterTrim(aFeaturesToUpdate);
+
// Send events to update the sub-features by the solver.
if(isUpdateFlushed) {
Events_Loop::loop()->setFlushed(anUpdateEvent, true);
#ifdef DEBUG_TRIM_METHODS
std::cout << "SketchPlugin_Trim::processEvent:" << data()->name() << std::endl;
#endif
-
std::string aFilledAttributeName;
std::shared_ptr<ModelAPI_EventReentrantMessage> aMessage =
std::shared_ptr<GeomAPI_Pnt2d> aPoint = aMessage->clickedPoint();
if (anObject.get() && aPoint.get()) {
- std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
- std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
- std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
- data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
- aRefSelectedAttr->setValue(anObject);
- aRefPreviewAttr->setValue(anObject);
-
- std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
- std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
- std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
- aPointSelectedAttr->setValue(aPoint);
- aPointPreviewAttr->setValue(aPoint);
-
- Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
-
- GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
-#ifdef DEBUG_TRIM_METHODS
- if (!aSelectedShape.get())
- std::cout << "Set empty selected object" << std::endl;
- else
- std::cout << "Set shape with ShapeType: " << aSelectedShape->shapeTypeStr() << std::endl;
-#endif
- aFilledAttributeName = SketchPlugin_Trim::SELECTED_OBJECT();
+ if (myCashedShapes.find(anObject) == myCashedShapes.end())
+ fillObjectShapes(anObject, sketch()->data()->owner(), myCashedShapes, myObjectToPoints);
+ const std::set<GeomShapePtr>& aShapes = myCashedShapes[anObject];
+ if (aShapes.size() > 1) {
+ std::shared_ptr<ModelAPI_AttributeReference> aRefSelectedAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+ data()->attribute(SketchPlugin_Trim::SELECTED_OBJECT()));
+ std::shared_ptr<ModelAPI_AttributeReference> aRefPreviewAttr =
+ std::dynamic_pointer_cast<ModelAPI_AttributeReference>(
+ data()->attribute(SketchPlugin_Trim::PREVIEW_OBJECT()));
+ aRefSelectedAttr->setValue(anObject);
+ aRefPreviewAttr->setValue(anObject);
+
+ std::shared_ptr<GeomDataAPI_Point2D> aPointSelectedAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ data()->attribute(SketchPlugin_Trim::SELECTED_POINT()));
+ std::shared_ptr<GeomDataAPI_Point2D> aPointPreviewAttr =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
+ data()->attribute(SketchPlugin_Trim::PREVIEW_POINT()));
+ aPointSelectedAttr->setValue(aPoint);
+ aPointPreviewAttr->setValue(aPoint);
+
+ Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
+
+ GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
+ #ifdef DEBUG_TRIM_METHODS
+ if (!aSelectedShape.get())
+ std::cout << "Set empty selected object" << std::endl;
+ else
+ std::cout << "Set shape with ShapeType: " << aSelectedShape->shapeTypeStr() << std::endl;
+ #endif
+ aFilledAttributeName = SketchPlugin_Trim::SELECTED_OBJECT();
+ }
}
}
return aFilledAttributeName;
}
}
-void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete)
+void SketchPlugin_Trim::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
+ std::set<FeaturePtr>& theFeaturesToUpdate)
{
std::shared_ptr<ModelAPI_Data> aData = data();
aRefFeatureKind == SketchPlugin_MultiTranslation::ID() ||
aRefFeatureKind == SketchPlugin_ConstraintMiddle::ID())
theFeaturesToDelete.insert(aRefFeature);
+ else if (aRefFeatureKind == SketchPlugin_ConstraintLength::ID())
+ theFeaturesToUpdate.insert(aRefFeature);
}
}
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,
(aBaseFeature->attribute(aModifiedAttribute)));
// equal Radius constraint for arcs
- anNewFeature->execute(); // we need the created arc result to set equal constraint
createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
getFeatureResult(aBaseFeature),
getFeatureResult(anNewFeature));
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 (need to calculate arc parameters before sending Update)
aFeature->data()->blockSendAttributeUpdated(aWasBlocked);
#ifdef DEBUG_TRIM