#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
#include <SketchPlugin_Point.h>
+#include <SketchPlugin_Tools.h>
#include <ModelGeomAlgo_Point2D.h>
#include <ModelAPI_EventReentrantMessage.h>
//#define CREATE_CONSTRAINTS
-#define DEBUG_SPLIT
#ifdef DEBUG_SPLIT
#include <iostream>
#endif
//}
//aBaseShape = aShape;
-#ifdef DEBUG_TRIM_METHODS
+#ifdef DEBUG_SPLIT
if (!aSelectedShape.get())
std::cout << "Set empty selected object" << std::endl;
else
std::string SketchPlugin_Split::processEvent(const std::shared_ptr<Events_Message>& theMessage)
{
-#ifdef DEBUG_TRIM_METHODS
- std::cout << "SketchPlugin_Trim::processEvent:" << data()->name() << std::endl;
+#ifdef DEBUG_SPLIT
+ std::cout << "SketchPlugin_Split::processEvent:" << data()->name() << std::endl;
#endif
std::string aFilledAttributeName;
Events_Loop::loop()->flush(Events_Loop::eventByName(EVENT_OBJECT_UPDATED));
GeomShapePtr aSelectedShape = getSubShape(SELECTED_OBJECT(), SELECTED_POINT());
- #ifdef DEBUG_TRIM_METHODS
+ if (aSelectedShape.get()) {
+ aFilledAttributeName = SELECTED_OBJECT();
+ }
+ else {
+ // #2480 - sub shape is not initialized when split sketch
+ // If restarted operation use some selection on the shape that is split and
+ // result selectiona can not participate in new split(checked shape above is null),
+ // reset filled values of selection set in this method above
+ aRefSelectedAttr->setValue(ResultPtr());
+ aRefPreviewAttr->setValue(ResultPtr());
+ }
+ #ifdef DEBUG_SPLIT
if (!aSelectedShape.get())
std::cout << "Set empty selected object" << std::endl;
else
std::cout << "Set shape with ShapeType: " << aSelectedShape->shapeTypeStr() << std::endl;
#endif
- aFilledAttributeName = SELECTED_OBJECT();
}
}
}
return anAIS;
}
return AISObjectPtr();*/
-#ifdef DEBUG_TRIM_METHODS
- std::cout << "SketchPlugin_Trim::getAISObject: " << data()->name() << std::endl;
+#ifdef DEBUG_SPLIT
+ std::cout << "SketchPlugin_Split::getAISObject: " << data()->name() << std::endl;
#endif
AISObjectPtr anAIS = thePrevious;
}
if (aFeaturePointAttribute.get()) {
// create new constraint and remove the current
- aCoincFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aCoincFeature = SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
aFeaturePointAttribute, aCoincFeature->refattr(aSecondAttribute)->attr());
theFeaturesToDelete.insert(aCIt->first);
// create new coincidences to split feature points
for (; aSFIt != aSFLast; aSFIt++) {
AttributePoint2DPtr aSFAttribute = *aSFIt;
if (aCoincPnt->isEqual(aSFAttribute->pnt())) {
- createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
aSFAttribute, aCoincFeature->refattr(aSecondAttribute)->attr());
}
}
aFeature->attribute(SketchPlugin_Line::END_ID())));
anNewFeature = aFeature;
}
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theSplitFeature->attribute(SketchPlugin_Line::END_ID()),
aFeature->attribute(SketchPlugin_Line::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()),
aFirstPointAttrOfSplit);
theBaseFeatureModified->execute(); // to update result
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Line::END_ID()),
theSplitFeature->attribute(SketchPlugin_Line::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
#ifdef CREATE_CONSTRAINTS
// additional constraints between split and base features
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintParallel::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theSplitFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintParallel::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theSplitFeature));
theCreatedFeatures.insert(aConstraintFeature);
if (theAfterFeature.get()) {
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintParallel::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theAfterFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintParallel::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theAfterFeature));
theCreatedFeatures.insert(aConstraintFeature);
}
#endif
aFeature->attribute(SketchPlugin_Arc::END_ID())));
anNewFeature = aFeature;
}
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theSplitFeature->attribute(SketchPlugin_Arc::END_ID()),
aFeature->attribute(SketchPlugin_Arc::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
fillAttribute(theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()),
aFirstPointAttrOfSplit);
theBaseFeatureModified->execute(); // to update result
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()),
theSplitFeature->attribute(SketchPlugin_Arc::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
// additional constraints between split and base features
#ifdef CREATE_CONSTRAINTS
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theSplitFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintEqual::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theSplitFeature));
theCreatedFeatures.insert(aConstraintFeature);
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(aBaseFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintTangent::ID(),
+ getFeatureResult(theSplitFeature),
+ getFeatureResult(aBaseFeature));
theCreatedFeatures.insert(aConstraintFeature);
if (theAfterFeature.get()) {
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintEqual::ID(),
- getFeatureResult(aBaseFeature),
- getFeatureResult(theAfterFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintEqual::ID(),
+ getFeatureResult(aBaseFeature),
+ getFeatureResult(theAfterFeature));
theCreatedFeatures.insert(aConstraintFeature);
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(theAfterFeature));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintTangent::ID(),
+ getFeatureResult(theSplitFeature),
+ getFeatureResult(theAfterFeature));
theCreatedFeatures.insert(aConstraintFeature);
}
#endif
(theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID())));
// additional constraints between split and base features
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Arc::END_ID()),
theSplitFeature->attribute(SketchPlugin_Arc::END_ID()));
theCreatedFeatures.insert(aConstraintFeature);
- aConstraintFeature = createConstraint(SketchPlugin_ConstraintCoincidence::ID(),
+ aConstraintFeature = SketchPlugin_Tools::createConstraintAttrAttr(sketch(),
+ SketchPlugin_ConstraintCoincidence::ID(),
theBaseFeatureModified->attribute(SketchPlugin_Arc::START_ID()),
theSplitFeature->attribute(SketchPlugin_Arc::START_ID()));
theCreatedFeatures.insert(aConstraintFeature);
#ifdef CREATE_CONSTRAINTS
- aConstraintFeature = createConstraintForObjects(SketchPlugin_ConstraintTangent::ID(),
- getFeatureResult(theSplitFeature),
- getFeatureResult(theBaseFeatureModified));
+ aConstraintFeature = SketchPlugin_Tools::createConstraint(sketch(),
+ SketchPlugin_ConstraintTangent::ID(),
+ getFeatureResult(theSplitFeature),
+ getFeatureResult(theBaseFeatureModified));
theCreatedFeatures.insert(aConstraintFeature);
#endif
return anNewFeature;
return aFeature;
}
-FeaturePtr SketchPlugin_Split::createConstraint(const std::string& theConstraintId,
- const AttributePtr& theFirstAttribute,
- const AttributePtr& theSecondAttribute)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setAttr(theFirstAttribute);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setAttr(theSecondAttribute);
-
- return aConstraint;
-}
-
-FeaturePtr SketchPlugin_Split::createConstraintForObjects(
- const std::string& theConstraintId,
- const ObjectPtr& theFirstObject,
- const ObjectPtr& theSecondObject)
-{
- FeaturePtr aConstraint = sketch()->addFeature(theConstraintId);
- AttributeRefAttrPtr aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_A()));
- aRefAttr->setObject(theFirstObject);
-
- aRefAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
- aConstraint->attribute(SketchPlugin_Constraint::ENTITY_B()));
- aRefAttr->setObject(theSecondObject);
-
- return aConstraint;
-}
-
void SketchPlugin_Split::updateFeaturesAfterSplit(
const std::set<FeaturePtr>& theFeaturesToUpdate)
{