#include <GeomDataAPI_Point2D.h>
#include <GeomDataAPI_Point.h>
+#include <GeomAPI_Edge.h>
+#include <GeomAPI_Pnt2d.h>
#include <GeomAlgoAPI_ShapeTools.h>
#include <ModelGeomAlgo_Point2D.h>
}
//********************************************************************
-bool PartSet_WidgetSubShapeSelector::setSelectionCustom(const ModuleBase_ViewerPrsPtr& thePrs)
+bool PartSet_WidgetSubShapeSelector::setSelection(
+ QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
+ const bool theToValidate)
{
- bool aResult = ModuleBase_WidgetSelector::setSelectionCustom(thePrs);
-
- //if (aResult)
- //GeomShapePtr aBaseShape = *anIt;
- // myCurrentSubShape->setShape(aBaseShape);
-
- FeaturePtr aFeature = feature();
- AttributePoint2DPtr anAPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
- AttributePoint2DPtr aBPointAttr = std::dynamic_pointer_cast<GeomDataAPI_Point2D>(
- aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
-
+ bool aResult = ModuleBase_WidgetShapeSelector::setSelection(theValues, theToValidate);
+
+ if (aResult && !theToValidate) {
+ ObjectPtr aBaseObject = myCurrentSubShape->object();
+ GeomShapePtr aBaseShape = myCurrentSubShape->shape();
+
+ if (aBaseShape->shapeType() == GeomAPI_Shape::EDGE) {
+ std::shared_ptr<GeomAPI_Edge> anEdge(new GeomAPI_Edge(aBaseShape));
+
+ std::shared_ptr<GeomAPI_Pln> aSketchPlane = PartSet_Tools::sketchPlane(mySketch);
+ std::shared_ptr<GeomAPI_Pnt> aFirstPnt = anEdge->firstPoint();
+ std::shared_ptr<GeomAPI_Pnt> aLastPnt = anEdge->lastPoint();
+ std::shared_ptr<GeomAPI_Pnt2d> aFirstPnt2D = aFirstPnt->to2D(aSketchPlane);
+ std::shared_ptr<GeomAPI_Pnt2d> aLastPnt2D = aLastPnt->to2D(aSketchPlane);
+
+ /// find the points in feature attributes
+ FeaturePtr aBaseFeature = ModelAPI_Feature::feature(aBaseObject);
+ std::list<AttributePtr> a2DPointAttributes = aBaseFeature->data()->attributes(
+ GeomDataAPI_Point2D::typeId());
+ std::list<AttributePtr>::const_iterator anIt = a2DPointAttributes.begin(),
+ aLast = a2DPointAttributes.end();
+ std::shared_ptr<GeomDataAPI_Point2D> aFirstPointAttr, aLastPointAttr;
+ for (; anIt != aLast; anIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ if (aFirstPnt2D->isEqual(anAttributePoint->pnt()))
+ aFirstPointAttr = anAttributePoint;
+ else if (aLastPnt2D->isEqual(anAttributePoint->pnt()))
+ aLastPointAttr = anAttributePoint;
+ }
+ /// find the points in coincident features
+ if (!aFirstPointAttr.get() || !aLastPointAttr.get()) {
+ std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes = myCashedReferences[aBaseObject];
+ std::set<std::shared_ptr<GeomDataAPI_Point2D> >::const_iterator aRefIt = aRefAttributes.begin(),
+ aRefLast = aRefAttributes.end();
+ for (; aRefIt != aRefLast; aRefIt++) {
+ std::shared_ptr<GeomDataAPI_Point2D> anAttributePoint = *aRefIt;
+ if (!aFirstPointAttr.get() && aFirstPnt2D->isEqual(anAttributePoint->pnt()))
+ aFirstPointAttr = anAttributePoint;
+ if (!aLastPointAttr.get() && aLastPnt2D->isEqual(anAttributePoint->pnt()))
+ aLastPointAttr = anAttributePoint;
+ if (aFirstPointAttr.get() && aLastPointAttr.get())
+ break;
+ }
+ }
- //GeomDataAPI_Point2D anAPointAttr = aFeature->attribute(SketchPlugin_Constraint::ENTITY_A())
- //data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId());
- //data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId());
+ FeaturePtr aFeature = feature();
+ AttributeRefAttrPtr anAPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aFeature->attribute(SketchPlugin_Constraint::ENTITY_A()));
+ AttributeRefAttrPtr aBPointAttr = std::dynamic_pointer_cast<ModelAPI_AttributeRefAttr>(
+ aFeature->attribute(SketchPlugin_Constraint::ENTITY_B()));
+ anAPointAttr->setAttr(aFirstPointAttr);
+ aBPointAttr->setAttr(aLastPointAttr);
+ }
+ }
return aResult;
}
void PartSet_WidgetSubShapeSelector::fillObjectShapes(const ObjectPtr& theObject)
{
std::set<std::shared_ptr<GeomAPI_Shape> > aShapes;
+ std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
// current feature
FeaturePtr aFeature = ModelAPI_Feature::feature(theObject);
GeomShapePtr aFeatureShape = *anEdgeShapes.begin();
// coincidences to the feature
- std::set<std::shared_ptr<GeomDataAPI_Point2D> > aRefAttributes;
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
GeomAlgoAPI_ShapeTools::splitShape(aFeatureShape, aPoints, aShapes);
}
myCashedShapes[theObject] = aShapes;
+ myCashedReferences[theObject] = aRefAttributes;
}
//********************************************************************
#include <PartSet_MouseProcessor.h>
#include <ModelAPI_CompositeFeature.h>
+#include <GeomDataAPI_Point2D.h>
#include <QObject>
/// \param theValues a list of presentations
virtual void getHighlighted(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues);
- /// Fills the attribute with the value of the selected owner
- /// \param thePrs a selected owner
- virtual bool setSelectionCustom(const std::shared_ptr<ModuleBase_ViewerPrs>& thePrs);
+ /// Set the given wrapped value to the current widget
+ /// This value should be processed in the widget according to the needs
+ /// The method is called by the current operation to process the operation preselection.
+ /// It is redefined to fill attributes responsible for the sub selection
+ /// \param theValues the wrapped selection values
+ /// \param theToValidate a flag on validation of the values
+ virtual bool setSelection(QList<std::shared_ptr<ModuleBase_ViewerPrs>>& theValues,
+ const bool theToValidate);
protected:
/// Checks the widget validity. By default, it returns true.
protected:
std::shared_ptr<ModuleBase_ViewerPrs> myCurrentSubShape;
std::map<ObjectPtr, std::set<GeomShapePtr> > myCashedShapes;
+ std::map<ObjectPtr, std::set<AttributePoint2DPtr> > myCashedReferences;
/// Pointer to a sketch
CompositeFeaturePtr mySketch;
//#include <ModelAPI_AttributeDouble.h>
#include <ModelAPI_AttributeReference.h>
//#include <ModelAPI_AttributeRefList.h>
-//#include <ModelAPI_AttributeRefAttrList.h>
+#include <ModelAPI_AttributeRefAttr.h>
//#include <ModelAPI_Data.h>
//#include <ModelAPI_Events.h>
//#include <ModelAPI_Session.h>
void SketchPlugin_ConstraintSplit::initAttributes()
{
data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeReference::typeId());
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), GeomDataAPI_Point2D::typeId());
- data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), GeomDataAPI_Point2D::typeId());
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttr::typeId());
+ data()->addAttribute(SketchPlugin_Constraint::ENTITY_B(), ModelAPI_AttributeRefAttr::typeId());
//data()->addAttribute(SketchPlugin_Constraint::VALUE(), ModelAPI_AttributeDouble::typeId());
//data()->addAttribute(SketchPlugin_Constraint::ENTITY_A(), ModelAPI_AttributeRefAttrList::typeId());