From 8cb8a4f0900b8527fdb9aeb9f05cc3ef6d877dc9 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 26 Apr 2017 18:55:47 +0300 Subject: [PATCH] Implementation of a task "Show centers of external circular objects in current sketcher" --- src/GeomAPI/GeomAPI_Vertex.h | 3 + src/PartSet/PartSet_CenterPrs.cpp | 8 ++- src/PartSet/PartSet_CenterPrs.h | 29 +++++++-- src/PartSet/PartSet_ExternalPointsMgr.cpp | 71 ++++++++++++++++------- src/PartSet/PartSet_ExternalPointsMgr.h | 15 ++++- src/PartSet/PartSet_Tools.cpp | 25 ++++++++ src/PartSet/PartSet_Tools.h | 8 +++ src/PartSet/PartSet_WidgetPoint2d.cpp | 32 +++++++++- src/XGUI/XGUI_Tools.cpp | 4 +- 9 files changed, 163 insertions(+), 32 deletions(-) diff --git a/src/GeomAPI/GeomAPI_Vertex.h b/src/GeomAPI/GeomAPI_Vertex.h index c5f0dfe27..60cfca5c1 100644 --- a/src/GeomAPI/GeomAPI_Vertex.h +++ b/src/GeomAPI/GeomAPI_Vertex.h @@ -38,5 +38,8 @@ public: bool isEqual(const std::shared_ptr theVert) const; }; +//! Pointer on the object +typedef std::shared_ptr GeomVertexPtr; + #endif diff --git a/src/PartSet/PartSet_CenterPrs.cpp b/src/PartSet/PartSet_CenterPrs.cpp index b45c2e5e7..9f7f66249 100644 --- a/src/PartSet/PartSet_CenterPrs.cpp +++ b/src/PartSet/PartSet_CenterPrs.cpp @@ -12,10 +12,12 @@ IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point) PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject, - const GeomShapePtr& theEdge, - const gp_Pnt& theCenter) + const GeomEdgePtr& theEdge, + const gp_Pnt& theCenter, + ModelAPI_AttributeSelection::CenterType theType) : AIS_Point(new Geom_CartesianPoint(theCenter)), myObject(theObject), - myEdge(theEdge) + myEdge(theEdge), + myCenterType(theType) { } \ No newline at end of file diff --git a/src/PartSet/PartSet_CenterPrs.h b/src/PartSet/PartSet_CenterPrs.h index f1067eaf0..f9cf9232f 100644 --- a/src/PartSet/PartSet_CenterPrs.h +++ b/src/PartSet/PartSet_CenterPrs.h @@ -8,7 +8,8 @@ #define PartSet_CenterPrs_H #include -#include +#include +#include #include #include @@ -16,22 +17,38 @@ DEFINE_STANDARD_HANDLE(PartSet_CenterPrs, AIS_Point) +/** +* \ingroup GUI +* A presentation class for displaying of centers of external curcular objects in a sketch +*/ class PartSet_CenterPrs: public AIS_Point { public: /// Constructor - /// \param theResult a result object + /// \param theObject an object with circular edge + /// \param theEdge a circular edge + /// \param theCenter a center point of the circular edge + /// \param theType a type of the center Standard_EXPORT PartSet_CenterPrs(const ObjectPtr& theObject, - const GeomShapePtr& theEdge, - const gp_Pnt& theCenter); + const GeomEdgePtr& theEdge, + const gp_Pnt& theCenter, + ModelAPI_AttributeSelection::CenterType theType); + /// Returns an Object which contains the circular edge ObjectPtr object() const { return myObject; } - GeomShapePtr edge() const { return myEdge; } + + /// Returns a circular edge shape + GeomEdgePtr edge() const { return myEdge; } + + /// Returns type of the center + ModelAPI_AttributeSelection::CenterType centerType() const { return myCenterType; } DEFINE_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point) + private: ObjectPtr myObject; - GeomShapePtr myEdge; + GeomEdgePtr myEdge; + ModelAPI_AttributeSelection::CenterType myCenterType; }; #endif diff --git a/src/PartSet/PartSet_ExternalPointsMgr.cpp b/src/PartSet/PartSet_ExternalPointsMgr.cpp index b638cbcd5..b0faeb447 100644 --- a/src/PartSet/PartSet_ExternalPointsMgr.cpp +++ b/src/PartSet/PartSet_ExternalPointsMgr.cpp @@ -22,6 +22,7 @@ #include #include #include +#include PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop, const CompositeFeaturePtr& theSketch) @@ -29,8 +30,9 @@ PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWo { XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); XGUI_Displayer* aDisplayer = aWorkshop->displayer(); - connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjctPtr)), + connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjectPtr)), SLOT(onDisplayObject(ObjectPtr, AISObjectPtr))); + connect(aDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)), SLOT(onEraseObject(ObjectPtr, AISObjectPtr))); @@ -43,6 +45,9 @@ PartSet_ExternalPointsMgr::~PartSet_ExternalPointsMgr() if (myPresentations.isEmpty()) return; XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + if (!aWorkshop) + return; + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); QMapIterator aIt(myPresentations); while (aIt.hasNext()) { @@ -108,48 +113,55 @@ QList> PartSet_ExternalPointsMgr::findCirc void PartSet_ExternalPointsMgr::updateCenterPresentations() { + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); // Return if there is no plane defined - if (!plane().get()) + if (!plane().get()) { + connect(aWorkshop->selector(), SIGNAL(selectionChanged()), + SLOT(onSelectionChanged())); return; - - XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + } XGUI_Displayer* aDisplayer = aWorkshop->displayer(); QList> aEdgesPrs = findCircularEdgesInPlane(); foreach(std::shared_ptr aPrs, aEdgesPrs) { - GeomAPI_Edge aEdge(aPrs->shape()); - if (aEdge.isArc() || aEdge.isCircle()) { - GeomCirclePtr aCircle = aEdge.circle(); + GeomEdgePtr aEdge(new GeomAPI_Edge(aPrs->shape())); + ListOfAIS aList; + if (aEdge->isArc() || aEdge->isCircle()) { + GeomCirclePtr aCircle = aEdge->circle(); GeomPointPtr aCenter = aCircle->center(); Handle(PartSet_CenterPrs) aCentPrs = - new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aCenter->impl()); + new PartSet_CenterPrs(aPrs->object(), aEdge, aCenter->impl(), + ModelAPI_AttributeSelection::CIRCLE_CENTER); AISObjectPtr anAIS(new GeomAPI_AISObject()); anAIS->setImpl(new Handle(AIS_InteractiveObject)(aCentPrs)); - aDisplayer->displayAIS(anAIS, false); - ListOfAIS aList; aList.append(anAIS); - myPresentations[aPrs->object()] = aList; - } else if (aEdge.isEllipse()) { - GeomEllipsePtr aEllipse = aEdge.ellipse(); + } else if (aEdge->isEllipse()) { + GeomEllipsePtr aEllipse = aEdge->ellipse(); GeomPointPtr aF1 = aEllipse->firstFocus(); GeomPointPtr aF2 = aEllipse->secondFocus(); Handle(PartSet_CenterPrs) aF1Prs = - new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF1->impl()); + new PartSet_CenterPrs(aPrs->object(), aEdge, aF1->impl(), + ModelAPI_AttributeSelection::ELLIPSE_FIRST_FOCUS); Handle(PartSet_CenterPrs) aF2Prs = - new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF2->impl()); + new PartSet_CenterPrs(aPrs->object(), aEdge, aF2->impl(), + ModelAPI_AttributeSelection::ELLIPSE_SECOND_FOCUS); - ListOfAIS aList; AISObjectPtr anAIS1(new GeomAPI_AISObject()); anAIS1->setImpl(new Handle(AIS_InteractiveObject)(aF1Prs)); - aDisplayer->displayAIS(anAIS1, false); aList.append(anAIS1); AISObjectPtr anAIS2(new GeomAPI_AISObject()); anAIS2->setImpl(new Handle(AIS_InteractiveObject)(aF2Prs)); - aDisplayer->displayAIS(anAIS2, false); aList.append(anAIS2); + } + if (myPresentations.contains(aPrs->object())) + myPresentations[aPrs->object()].append(aList); + else myPresentations[aPrs->object()] = aList; + foreach(AISObjectPtr anAIS, aList) { + aDisplayer->displayAIS(anAIS, false); + aDisplayer->activateAIS(anAIS->impl(), TopAbs_VERTEX, false); } } } @@ -166,7 +178,16 @@ void PartSet_ExternalPointsMgr::onDisplayObject(ObjectPtr theObj, AISObjectPtr t void PartSet_ExternalPointsMgr::onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS) { - updateCenterPresentations(); + if (myPresentations.contains(theObj)) { + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + ListOfAIS aList = myPresentations[theObj]; + foreach(AISObjectPtr aAIS, aList) { + aDisplayer->eraseAIS(aAIS, false); + } + myPresentations.remove(theObj); + aDisplayer->updateViewer(); + } } @@ -177,4 +198,14 @@ bool PartSet_ExternalPointsMgr::isSketchObject(const ObjectPtr& theRes) const return false; CompositeFeaturePtr aComp = ModelAPI_Tools::compositeOwner(aFeature); return aComp == mySketch; -} \ No newline at end of file +} + +void PartSet_ExternalPointsMgr::onSelectionChanged() +{ + if (plane().get()) { + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + disconnect(aWorkshop->selector(), SIGNAL(selectionChanged()), + this, SLOT(onSelectionChanged())); + updateCenterPresentations(); + } +} diff --git a/src/PartSet/PartSet_ExternalPointsMgr.h b/src/PartSet/PartSet_ExternalPointsMgr.h index 718902afb..8ced4b403 100644 --- a/src/PartSet/PartSet_ExternalPointsMgr.h +++ b/src/PartSet/PartSet_ExternalPointsMgr.h @@ -33,7 +33,7 @@ public: virtual ~PartSet_ExternalPointsMgr(); -private slots: +public slots: /** * A slot which processes display of object * \param theObj the displayed object @@ -48,6 +48,9 @@ private slots: */ void onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS); + // Called on selection changed + void onSelectionChanged(); + private: /** * Returns list of presentations which have displayed shapes with circular edges @@ -62,14 +65,24 @@ private: /// Returns plane of the current sketch GeomPlanePtr plane() const; + /** + * Checks that the given object is an object of the current sketch + * \param theRes an object to check + * \return True if the given object is a sub-object of the current sketch + */ bool isSketchObject(const ObjectPtr& theRes) const; private: + /// Workshop ModuleBase_IWorkshop* myWorkshop; + + /// Current sketch CompositeFeaturePtr mySketch; + /// Type for list of created AIS objects typedef QList ListOfAIS; + /// Map of created AIS objects QMap myPresentations; }; diff --git a/src/PartSet/PartSet_Tools.cpp b/src/PartSet/PartSet_Tools.cpp index 6550c7767..bb204073b 100755 --- a/src/PartSet/PartSet_Tools.cpp +++ b/src/PartSet/PartSet_Tools.cpp @@ -889,3 +889,28 @@ bool PartSet_Tools::isAuxiliarySketchEntity(const ObjectPtr& theObject) return isAuxiliaryFeature; } + + +ResultPtr PartSet_Tools::createFixedByExternalCenter(const ObjectPtr& theObject, + const std::shared_ptr& theEdge, + ModelAPI_AttributeSelection::CenterType theType, + const CompositeFeaturePtr& theSketch, + bool theTemporary) +{ + FeaturePtr aMyFeature = theSketch->addFeature(SketchPlugin_Point::ID()); + + if (aMyFeature) { + DataPtr aData = aMyFeature->data(); + AttributeSelectionPtr anAttr = + std::dynamic_pointer_cast + (aData->attribute(SketchPlugin_SketchEntity::EXTERNAL_ID())); + + ResultPtr aRes = std::dynamic_pointer_cast(theObject); + if (anAttr.get() && aRes.get()) { + anAttr->setValueCenter(aRes, theEdge, theType, theTemporary); + aMyFeature->execute(); + return aMyFeature->lastResult(); + } + } + return ResultPtr(); +} diff --git a/src/PartSet/PartSet_Tools.h b/src/PartSet/PartSet_Tools.h index 1429f9d29..8d9dce122 100755 --- a/src/PartSet/PartSet_Tools.h +++ b/src/PartSet/PartSet_Tools.h @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -265,6 +266,13 @@ public: * \return boolean result */ static bool isAuxiliarySketchEntity(const ObjectPtr& theObject); + + static ResultPtr createFixedByExternalCenter(const ObjectPtr& theObject, + const std::shared_ptr& theEdge, + ModelAPI_AttributeSelection::CenterType theType, + const CompositeFeaturePtr& theSketch, + bool theTemporary = false); + }; #endif diff --git a/src/PartSet/PartSet_WidgetPoint2d.cpp b/src/PartSet/PartSet_WidgetPoint2d.cpp index 56b1e9852..9d3345e1d 100644 --- a/src/PartSet/PartSet_WidgetPoint2d.cpp +++ b/src/PartSet/PartSet_WidgetPoint2d.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -62,6 +63,7 @@ #include #include #include +#include #include #include @@ -564,6 +566,7 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo if (!aFirstValue.get() && myPreSelected.get()) { aFirstValue = myPreSelected; } + // if we have selection and use it if (aFirstValue.get() && isValidSelectionCustom(aFirstValue) && aFirstValue->shape().get()) { /// Trihedron Axis may be selected, but shape is empty @@ -679,7 +682,34 @@ void PartSet_WidgetPoint2D::mouseReleased(ModuleBase_IViewWindow* theWindow, QMo } } } - // End of Bug dependent fragment + // The selection could be a center of an external circular object + else if (aFirstValue.get() && (!aFirstValue->interactive().IsNull())) { + Handle(PartSet_CenterPrs) aAIS = Handle(PartSet_CenterPrs)::DownCast(aFirstValue->interactive()); + if (!aAIS.IsNull()) { + gp_Pnt aPntComp = aAIS->Component()->Pnt(); + GeomVertexPtr aVertPtr(new GeomAPI_Vertex(aPntComp.X(), aPntComp.Y(), aPntComp.Z())); + TopoDS_Shape aShape = aVertPtr->impl(); + + ResultPtr aFixedObject = PartSet_Tools::findFixedObjectByExternal(aShape, aAIS->object(), mySketch); + if (!aFixedObject.get()) + aFixedObject = PartSet_Tools::createFixedByExternalCenter(aAIS->object(), aAIS->edge(), + aAIS->centerType(), mySketch); + if (aFixedObject.get()) + setConstraintToObject(aFixedObject); + // fignal updated should be flushed in order to visualize possible created + // external objects e.g. selection of trihedron axis when input end arc point + updateObject(feature()); + + double aX, aY; + if (getPoint2d(aView, aShape, aX, aY)) { + // do not create a constraint to the point, which already used by the feature + // if the feature contains the point, focus is not switched + setPoint(aX, aY); + } + emit vertexSelected(); // it stops the reentrant operation + emit focusOutWidget(this); + } + } else { // A case when point is taken from mouse event gp_Pnt aPoint = PartSet_Tools::convertClickToPoint(theEvent->pos(), theWindow->v3dView()); diff --git a/src/XGUI/XGUI_Tools.cpp b/src/XGUI/XGUI_Tools.cpp index cd310eef0..e057f860e 100644 --- a/src/XGUI/XGUI_Tools.cpp +++ b/src/XGUI/XGUI_Tools.cpp @@ -151,7 +151,9 @@ bool canRename(const ObjectPtr& theObject, const QString& theName) XGUI_Workshop* workshop(ModuleBase_IWorkshop* theWorkshop) { XGUI_ModuleConnector* aConnector = dynamic_cast(theWorkshop); - return aConnector->workshop(); + if (aConnector) + return aConnector->workshop(); + return 0; } } -- 2.39.2