}
}
-void PartSet_Module::onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape)
+void PartSet_Module::onVertexSelected()
{
ModuleBase_Operation* aOperation = myWorkshop->currentOperation();
if (aOperation->id().toStdString() == SketchPlugin_Line::ID()) {
aWgt->setWorkshop(aWorkshop);
aWgt->setSketch(mySketchMgr->activeSketch());
- connect(aWgt, SIGNAL(vertexSelected(ObjectPtr, const TopoDS_Shape&)),
- this, SLOT(onVertexSelected(ObjectPtr, const TopoDS_Shape&)));
+ connect(aWgt, SIGNAL(vertexSelected()), this, SLOT(onVertexSelected()));
theModelWidgets.append(aWgt);
return aWgt->getControl();
virtual void registerFilters();
private slots:
- void onVertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+ void onVertexSelected();
private:
aFeature->execute();
}
+std::shared_ptr<GeomDataAPI_Point2D> PartSet_Tools::
+ findAttributePoint(CompositeFeaturePtr theSketch, double theX, double theY,
+ double theTolerance, const QList<FeaturePtr>& theIgnore)
+{
+ std::shared_ptr<GeomAPI_Pnt2d> aClickedPoint = std::shared_ptr<GeomAPI_Pnt2d>(
+ new GeomAPI_Pnt2d(theX, theY));
+
+ std::list<std::shared_ptr<ModelAPI_Attribute> > anAttiributes;
+ for (int i = 0; i < theSketch->numberOfSubs(); i++) {
+ FeaturePtr aFeature = theSketch->subFeature(i);
+ if (!theIgnore.contains(aFeature)) {
+ anAttiributes = aFeature->data()->attributes(GeomDataAPI_Point2D::type());
+
+ std::list<std::shared_ptr<ModelAPI_Attribute> >::const_iterator anIt;
+ for (anIt = anAttiributes.cbegin(); anIt != anAttiributes.cend(); ++anIt) {
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ double x = aCurPoint->x();
+ double y = aCurPoint->y();
+ if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < theTolerance)) {
+ return aCurPoint;
+ }
+ }
+ }
+ }
+ return std::shared_ptr<GeomDataAPI_Point2D>();
+}
+
+
void PartSet_Tools::setConstraints(CompositeFeaturePtr theSketch, FeaturePtr theFeature,
const std::string& theAttribute, double theClickedX,
double theClickedY)
aLast = anAttiributes.end();
std::shared_ptr<GeomDataAPI_Point2D> aFPoint;
for (; anIt != aLast && !aFPoint; anIt++) {
- std::shared_ptr<GeomDataAPI_Point2D> aCurPoint = std::dynamic_pointer_cast<
- GeomDataAPI_Point2D>(*anIt);
- if (aCurPoint && aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())
+ std::shared_ptr<GeomDataAPI_Point2D> aCurPoint =
+ std::dynamic_pointer_cast<GeomDataAPI_Point2D>(*anIt);
+ if (aCurPoint && (aCurPoint->pnt()->distance(aClickedPoint) < Precision::Confusion())) {
aFPoint = aCurPoint;
+ break;
+ }
}
if (aFPoint)
PartSet_Tools::createConstraint(theSketch, aFPoint, aFeaturePoint);
static std::shared_ptr<ModelAPI_Document> document();
+ static std::shared_ptr<GeomDataAPI_Point2D> findAttributePoint(CompositeFeaturePtr theSketch,
+ double theX, double theY, double theTolerance, const QList<FeaturePtr>& theIgnore = QList<FeaturePtr>());
+
/// Returns a point attribute of the feature by the coordinates if it is
/// \param theFeature the feature
/// \param theX the horizontal coordinate
void PartSet_WidgetPoint2D::onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent)
{
XGUI_Selection* aSelection = myWorkshop->selector()->selection();
- NCollection_List<TopoDS_Shape> aShapes;
- std::list<ObjectPtr> aObjects;
- aSelection->selectedShapes(aShapes, aObjects);
- if (aShapes.Extent() > 0) {
- TopoDS_Shape aShape = aShapes.First();
- double aX, aY;
- if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
- setPoint(aX, aY);
-
- PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
- emit vertexSelected(aObjects.front(), aShape);
- emit focusOutWidget(this);
- return;
- }
- }
+ // TODO: This fragment doesn't work because bug in OCC Viewer. It can be used after fixing.
+ //NCollection_List<TopoDS_Shape> aShapes;
+ //std::list<ObjectPtr> aObjects;
+ //aSelection->selectedShapes(aShapes, aObjects);
+ //if (aShapes.Extent() > 0) {
+ // TopoDS_Shape aShape = aShapes.First();
+ // double aX, aY;
+ // if (getPoint2d(theWnd->v3dView(), aShape, aX, aY)) {
+ // setPoint(aX, aY);
+
+ // PartSet_Tools::setConstraints(mySketch, feature(), attributeID(),aX, aY);
+ // emit vertexSelected(aObjects.front(), aShape);
+ // emit focusOutWidget(this);
+ // return;
+ // }
+ //}
+ // End of Bug dependent fragment
+
// A case when point is taken from mouse event
gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWnd->v3dView());
double aX, anY;
- PartSet_Tools::convertTo2D(aPoint, mySketch, theWnd->v3dView(), aX, anY);
+ Handle(V3d_View) aView = theWnd->v3dView();
+ PartSet_Tools::convertTo2D(aPoint, mySketch, aView, aX, anY);
setPoint(aX, anY);
+ std::shared_ptr<GeomDataAPI_Point2D> aFeaturePoint = std::dynamic_pointer_cast<
+ GeomDataAPI_Point2D>(feature()->data()->attribute(attributeID()));
+ QList<FeaturePtr> aIgnore;
+ aIgnore.append(feature());
+
+ double aTolerance = aView->Convert(4);
+ std::shared_ptr<GeomDataAPI_Point2D> aAttrPnt =
+ PartSet_Tools::findAttributePoint(mySketch, aX, anY, aTolerance, aIgnore);
+ if (aAttrPnt.get() != NULL) {
+
+ PartSet_Tools::createConstraint(mySketch, aAttrPnt, aFeaturePoint);
+ emit vertexSelected();
+ }
emit focusOutWidget(this);
}
/// Signal about selection of an existing vertex from an object
/// \param theObject - the selected object
/// \param theShape - the selected shape
- void vertexSelected(ObjectPtr theObject, const TopoDS_Shape& theShape);
+ void vertexSelected();
protected slots:
void onMouseRelease(ModuleBase_IViewWindow* theWnd, QMouseEvent* theEvent);