return true;
}
+bool SketchPlugin_ConstraintLength::computeLenghtValue(double& theValue)
+{
+ bool aResult = false;
+ std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
+ std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
+ if (getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) {
+ theValue = aPoint1->distance(aPoint2);
+ aResult = true;
+ }
+ return aResult;
+}
+
bool SketchPlugin_ConstraintLength::getPoints(
std::shared_ptr<GeomAPI_Pnt>& thePoint1, std::shared_ptr<GeomAPI_Pnt>& thePoint2,
std::shared_ptr<GeomDataAPI_Point2D>& theStartPoint,
std::shared_ptr<ModelAPI_AttributeDouble> aValueAttr = std::dynamic_pointer_cast<
ModelAPI_AttributeDouble>(attribute(SketchPlugin_Constraint::VALUE()));
if (!aValueAttr->isInitialized()) { // only if it is not initialized, try to compute the current value
- std::shared_ptr<GeomAPI_Pnt> aPoint1, aPoint2;
- std::shared_ptr<GeomDataAPI_Point2D> aStartPoint, anEndPoint;
- if (getPoints(aPoint1, aPoint2, aStartPoint, anEndPoint)) {
- double aLength = aPoint1->distance(aPoint2);
+ double aLength;
+ if (computeLenghtValue(aLength))
aValueAttr->setValue(aLength);
- }
}
} else if (theID == SketchPlugin_Constraint::FLYOUT_VALUE_PNT() && !myFlyoutUpdate) {
myFlyoutUpdate = true;
#include <ModelAPI_Validator.h>
#include <ModelAPI_Session.h>
+#include <ModelAPI_AttributeDouble.h>
#include <SketchPlugin_Line.h>
#include <SketchPlugin_Arc.h>
#include <SketchPlugin_ConstraintEqual.h>
#include <SketchPlugin_ConstraintParallel.h>
#include <SketchPlugin_ConstraintTangent.h>
+#include <SketchPlugin_ConstraintLength.h>
#include <SketchPlugin_ConstraintMirror.h>
#include <SketchPlugin_MultiRotation.h>
#include <SketchPlugin_MultiTranslation.h>
// Find feature constraints
FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObjectAttr->value());
ResultPtr aBaseFeatureResult = getFeatureResult(aBaseFeature);
-
- std::set<FeaturePtr> aFeaturesToDelete;
+ std::set<FeaturePtr> aFeaturesToDelete, aFeaturesToUpdate;
std::map<FeaturePtr, IdToPointPair> aTangentFeatures;
std::map<FeaturePtr, IdToPointPair> aCoincidenceToFeature;
- //std::map<FeaturePtr, IdToPointPair> aCoincidenceToPoint;
- getConstraints(aFeaturesToDelete, aTangentFeatures, aCoincidenceToFeature);//, aCoincidenceToPoint);
+ getConstraints(aFeaturesToDelete, aFeaturesToUpdate, aTangentFeatures, aCoincidenceToFeature);
std::map<AttributePtr, std::list<AttributePtr> > aBaseRefAttributes;
getRefAttributes(aBaseFeature, aBaseRefAttributes);
}
}
- /*if (!aCoincidenceToPoint.empty()) {
- std::cout << std::endl;
- std::cout << "Coincidences to points on base feature[" << aCoincidenceToPoint.size() << "]: " << std::endl;
- std::map<FeaturePtr, IdToPointPair>::const_iterator anIt = aCoincidenceToPoint.begin(),
- aLast = aCoincidenceToPoint.end();
- for (int i = 1; anIt != aLast; anIt++, i++) {
- FeaturePtr aFeature = (*anIt).first;
- std::string anAttributeId = (*anIt).second.first;
- std::shared_ptr<GeomDataAPI_Point2D> aPointAttr = (*anIt).second.second;
-
- std::cout << i << "-" << getFeatureInfo(aFeature) << std::endl;
- std::cout << " -Attribute to correct:" << anAttributeId << std::endl;
- std::cout << " -Point attribute:" << ModelGeomAlgo_Point2D::getPointAttributeInfo(aPointAttr) << 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;
// coincidence to feature
updateCoincidenceConstraintsToFeature(aCoincidenceToFeature, aFurtherCoincidences,
aFeatureResults);
- // coincidence to points
- //updateCoincidenceConstraintsToFeature(aCoincidenceToPoint, aFurtherCoincidences,
- // std::set<ResultPtr>());
// tangency
updateTangentConstraintsToFeature(aTangentFeatures, aFurtherCoincidences);
#endif
ModelAPI_Tools::removeFeaturesAndReferences(aFeaturesToDelete);
+#ifdef DEBUG_SPLIT
+ std::cout << "update features after split:" << std::endl;
+ std::set<FeaturePtr>::const_iterator anUIt = aFeaturesToUpdate.begin(),
+ anULast = aFeaturesToUpdate.end();
+ for (; anUIt != anULast; anUIt++) {
+ std::cout << getFeatureInfo(*anUIt, false) << std::endl;
+ std::cout << std::endl;
+ }
+#endif
+ updateFeaturesAfterSplit(aFeaturesToUpdate);
+
// Send events to update the sub-features by the solver.
if(isUpdateFlushed) {
Events_Loop::loop()->setFlushed(anUpdateEvent, true);
}
void SketchPlugin_ConstraintSplit::getConstraints(std::set<FeaturePtr>& theFeaturesToDelete,
+ std::set<FeaturePtr>& theFeaturesToUpdate,
std::map<FeaturePtr, IdToPointPair>& theTangentFeatures,
- std::map<FeaturePtr, IdToPointPair>& theCoincidenceToFeature/*,
- std::map<FeaturePtr, IdToPointPair>& theCoincidenceToPoint*/)
+ std::map<FeaturePtr, IdToPointPair>& theCoincidenceToFeature)
{
std::shared_ptr<ModelAPI_Data> aData = data();
aRefFeatureKind == SketchPlugin_MultiRotation::ID() ||
aRefFeatureKind == SketchPlugin_MultiTranslation::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
theFeaturesToDelete.insert(aRefFeature); /// until tangency between arc and line is implemented
if (isToFeature)
theCoincidenceToFeature[aRefFeature] = std::make_pair(anAttributeToBeModified,
aCoincidentPoint);
- //else
- //theCoincidenceToPoint[aRefFeature] = std::make_pair(anAttributeToBeModified,
- // aCoincidentPoint);
}
else
theFeaturesToDelete.insert(aRefFeature); /// this case should not happen
return aConstraint;
}
+void SketchPlugin_ConstraintSplit::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_ConstraintSplit::getFeatureResult(
const std::shared_ptr<ModelAPI_Feature>& theFeature)
{
/// 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
+ /// \param theFeaturesToUpdate [out] constrains that will be updated after split
/// \param theTangentFeatures [out] tangent feature to be connected to new feature
/// \param theCoincidenceToFeature [out] coincidence to feature to be connected to new feature
/// \param theCoincidenceToPoint [out] coincidence to point be connected to new feature
void getConstraints(std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToDelete,
+ std::set<std::shared_ptr<ModelAPI_Feature>>& theFeaturesToUpdate,
std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theTangentFeatures,
std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToFeature/*,
std::map<std::shared_ptr<ModelAPI_Feature>, IdToPointPair>& theCoincidenceToPoint*/);
const std::shared_ptr<ModelAPI_Object>& theFirstObject,
const std::shared_ptr<ModelAPI_Object>& theSecondObject);
+ /// Add feature coincidence constraint between given attributes
+ /// \param theFeaturesToUpdate a constraint index
+ void updateFeaturesAfterSplit(const std::set<FeaturePtr>& theFeaturesToUpdate);
+
/// Result result of the feature to build constraint with. For arc, circle it is an edge result.
/// \param theFeature a feature
/// \return result object