From b4cfc26da3cf899b06f7a52718e160ea88b01251 Mon Sep 17 00:00:00 2001 From: vsv Date: Wed, 26 Apr 2017 14:35:32 +0300 Subject: [PATCH] External points manager object created --- src/GeomAPI/GeomAPI_Circ.h | 3 + src/GeomAPI/GeomAPI_Pln.h | 3 + src/PartSet/CMakeLists.txt | 5 + src/PartSet/PartSet_CenterPrs.cpp | 21 +++ src/PartSet/PartSet_CenterPrs.h | 37 +++++ src/PartSet/PartSet_ExternalPointsMgr.cpp | 180 ++++++++++++++++++++++ src/PartSet/PartSet_ExternalPointsMgr.h | 76 +++++++++ src/PartSet/PartSet_SketcherMgr.cpp | 10 +- src/PartSet/PartSet_SketcherMgr.h | 3 + 9 files changed, 337 insertions(+), 1 deletion(-) create mode 100644 src/PartSet/PartSet_CenterPrs.cpp create mode 100644 src/PartSet/PartSet_CenterPrs.h create mode 100644 src/PartSet/PartSet_ExternalPointsMgr.cpp create mode 100644 src/PartSet/PartSet_ExternalPointsMgr.h diff --git a/src/GeomAPI/GeomAPI_Circ.h b/src/GeomAPI/GeomAPI_Circ.h index 686b42ede..ace1b64b5 100644 --- a/src/GeomAPI/GeomAPI_Circ.h +++ b/src/GeomAPI/GeomAPI_Circ.h @@ -64,5 +64,8 @@ class GeomAPI_Circ : public GeomAPI_Interface double& theParameter) const; }; +//! Pointer on the object +typedef std::shared_ptr GeomCirclePtr; + #endif diff --git a/src/GeomAPI/GeomAPI_Pln.h b/src/GeomAPI/GeomAPI_Pln.h index 704c2a0ce..247bee78f 100644 --- a/src/GeomAPI/GeomAPI_Pln.h +++ b/src/GeomAPI/GeomAPI_Pln.h @@ -81,5 +81,8 @@ class GeomAPI_Pln : public GeomAPI_Interface std::shared_ptr intersect(const std::shared_ptr thePlane) const; }; +//! Pointer on the object +typedef std::shared_ptr GeomPlanePtr; + #endif diff --git a/src/PartSet/CMakeLists.txt b/src/PartSet/CMakeLists.txt index 8dee08d11..3ab77b28b 100644 --- a/src/PartSet/CMakeLists.txt +++ b/src/PartSet/CMakeLists.txt @@ -39,6 +39,8 @@ SET(PROJECT_HEADERS PartSet_WidgetSketchCreator.h PartSet_WidgetSketchLabel.h PartSet_WidgetSubShapeSelector.h + PartSet_CenterPrs.h + PartSet_ExternalPointsMgr.h ) SET(PROJECT_MOC_HEADERS @@ -58,6 +60,7 @@ SET(PROJECT_MOC_HEADERS PartSet_WidgetSketchCreator.h PartSet_WidgetSketchLabel.h PartSet_WidgetSubShapeSelector.h + PartSet_ExternalPointsMgr.h ) SET(PROJECT_SOURCES @@ -86,6 +89,8 @@ SET(PROJECT_SOURCES PartSet_WidgetSketchCreator.cpp PartSet_WidgetSketchLabel.cpp PartSet_WidgetSubShapeSelector.cpp + PartSet_CenterPrs.cpp + PartSet_ExternalPointsMgr.cpp ) SET(PROJECT_RESOURCES diff --git a/src/PartSet/PartSet_CenterPrs.cpp b/src/PartSet/PartSet_CenterPrs.cpp new file mode 100644 index 000000000..b45c2e5e7 --- /dev/null +++ b/src/PartSet/PartSet_CenterPrs.cpp @@ -0,0 +1,21 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_CenterPrs.cpp +// Created: 25 April 2017 +// Author: Vitaly SMETANNIKOV + +#include "PartSet_CenterPrs.h" + +#include + + +IMPLEMENT_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point) + +PartSet_CenterPrs::PartSet_CenterPrs(const ObjectPtr& theObject, + const GeomShapePtr& theEdge, + const gp_Pnt& theCenter) + : AIS_Point(new Geom_CartesianPoint(theCenter)), + myObject(theObject), + myEdge(theEdge) +{ +} \ No newline at end of file diff --git a/src/PartSet/PartSet_CenterPrs.h b/src/PartSet/PartSet_CenterPrs.h new file mode 100644 index 000000000..f1067eaf0 --- /dev/null +++ b/src/PartSet/PartSet_CenterPrs.h @@ -0,0 +1,37 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_CenterPrs.h +// Created: 25 April 2017 +// Author: Vitaly SMETANNIKOV + +#ifndef PartSet_CenterPrs_H +#define PartSet_CenterPrs_H + +#include +#include + +#include +#include +#include + +DEFINE_STANDARD_HANDLE(PartSet_CenterPrs, AIS_Point) + +class PartSet_CenterPrs: public AIS_Point +{ +public: + /// Constructor + /// \param theResult a result object + Standard_EXPORT PartSet_CenterPrs(const ObjectPtr& theObject, + const GeomShapePtr& theEdge, + const gp_Pnt& theCenter); + + ObjectPtr object() const { return myObject; } + GeomShapePtr edge() const { return myEdge; } + + DEFINE_STANDARD_RTTIEXT(PartSet_CenterPrs, AIS_Point) +private: + ObjectPtr myObject; + GeomShapePtr myEdge; +}; + +#endif diff --git a/src/PartSet/PartSet_ExternalPointsMgr.cpp b/src/PartSet/PartSet_ExternalPointsMgr.cpp new file mode 100644 index 000000000..b638cbcd5 --- /dev/null +++ b/src/PartSet/PartSet_ExternalPointsMgr.cpp @@ -0,0 +1,180 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_ExternalPointsMgr.cpp +// Created: 26 April 2017 +// Author: Vitaly SMETANNIKOV + +#include "PartSet_ExternalPointsMgr.h" +#include "PartSet_CenterPrs.h" +#include "PartSet_Tools.h" + +#include + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include +#include + +PartSet_ExternalPointsMgr::PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop, + const CompositeFeaturePtr& theSketch) + : QObject(theWorkshop), myWorkshop(theWorkshop), mySketch(theSketch) +{ + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + connect(aDisplayer, SIGNAL(objectDisplayed(ObjectPtr, AISObjctPtr)), + SLOT(onDisplayObject(ObjectPtr, AISObjectPtr))); + connect(aDisplayer, SIGNAL(beforeObjectErase(ObjectPtr, AISObjectPtr)), + SLOT(onEraseObject(ObjectPtr, AISObjectPtr))); + + updateCenterPresentations(); +} + + +PartSet_ExternalPointsMgr::~PartSet_ExternalPointsMgr() +{ + if (myPresentations.isEmpty()) + return; + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + QMapIterator aIt(myPresentations); + while (aIt.hasNext()) { + aIt.next(); + ListOfAIS aAISList = aIt.value(); + foreach (AISObjectPtr aAIS, aAISList) { + aDisplayer->eraseAIS(aAIS, false); + } + } +} + + +//****************************************************** +QList> PartSet_ExternalPointsMgr::findCircularEdgesInPlane() +{ + QList> aResult; + XGUI_Workshop* aWorkshop = XGUI_Tools::workshop(myWorkshop); + XGUI_Displayer* aDisplayer = aWorkshop->displayer(); + QObjectPtrList aDispObjects = aDisplayer->displayedObjects(); + + std::shared_ptr aPlane = plane(); + foreach(ObjectPtr aObj, aDispObjects) { + if (myPresentations.contains(aObj)) + continue; + + // Do not process objects of the current sketch + if (isSketchObject(aObj)) + continue; + + ResultPtr aResObj = std::dynamic_pointer_cast(aObj); + if (aResObj.get()) { + GeomShapePtr aShape = aResObj->shape(); + if (aShape.get()) { + GeomAPI_ShapeExplorer aExplorer(aShape, GeomAPI_Shape::EDGE); + for(; aExplorer.more(); aExplorer.next()) { + GeomShapePtr aEdgeShape = aExplorer.current(); + GeomAPI_Edge anEdge(aEdgeShape); + if ((anEdge.isCircle() || anEdge.isArc() || anEdge.isEllipse()) && + anEdge.isInPlane(aPlane)) { + bool isContains = false; + // Check that edge is not already used. + // It is possible that the same edge will be taken from different faces + foreach(std::shared_ptr aPrs, aResult) { + GeomAPI_Edge aUsedEdge(aPrs->shape()); + if (aUsedEdge.isEqual(aEdgeShape)) { + isContains = true; + break; + } + } + if (!isContains) { + std::shared_ptr + aPrs(new ModuleBase_ViewerPrs(aResObj, aEdgeShape)); + aResult.append(aPrs); + } + } + } + } + } + } + return aResult; +} + + +void PartSet_ExternalPointsMgr::updateCenterPresentations() +{ + // Return if there is no plane defined + if (!plane().get()) + 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(); + GeomPointPtr aCenter = aCircle->center(); + Handle(PartSet_CenterPrs) aCentPrs = + new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aCenter->impl()); + + 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(); + GeomPointPtr aF1 = aEllipse->firstFocus(); + GeomPointPtr aF2 = aEllipse->secondFocus(); + Handle(PartSet_CenterPrs) aF1Prs = + new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF1->impl()); + Handle(PartSet_CenterPrs) aF2Prs = + new PartSet_CenterPrs(aPrs->object(), aPrs->shape(), aF2->impl()); + + 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); + myPresentations[aPrs->object()] = aList; + } + } +} + +std::shared_ptr PartSet_ExternalPointsMgr::plane() const +{ + return PartSet_Tools::sketchPlane(mySketch); +} + +void PartSet_ExternalPointsMgr::onDisplayObject(ObjectPtr theObj, AISObjectPtr theAIS) +{ + updateCenterPresentations(); +} + +void PartSet_ExternalPointsMgr::onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS) +{ + updateCenterPresentations(); +} + + +bool PartSet_ExternalPointsMgr::isSketchObject(const ObjectPtr& theRes) const +{ + FeaturePtr aFeature = ModelAPI_Feature::feature(theRes); + if (!aFeature.get()) + return false; + CompositeFeaturePtr aComp = ModelAPI_Tools::compositeOwner(aFeature); + return aComp == mySketch; +} \ No newline at end of file diff --git a/src/PartSet/PartSet_ExternalPointsMgr.h b/src/PartSet/PartSet_ExternalPointsMgr.h new file mode 100644 index 000000000..718902afb --- /dev/null +++ b/src/PartSet/PartSet_ExternalPointsMgr.h @@ -0,0 +1,76 @@ +// Copyright (C) 2014-20xx CEA/DEN, EDF R&D + +// File: PartSet_ExternalPointsMgr.h +// Created: 26 April 2017 +// Author: Vitaly SMETANNIKOV + +#ifndef PartSet_ExternalPointsMgr_H +#define PartSet_ExternalPointsMgr_H + + +#include +#include +#include +#include + +#include +#include + +class ModuleBase_ViewerPrs; +class ModuleBase_IWorkshop; + + +/** +* \ingroup Modules +* A class to manage display of presentations of center points of circular +* edges outside of a current sketcher +*/ +class PartSet_ExternalPointsMgr: public QObject +{ + Q_OBJECT +public: + PartSet_ExternalPointsMgr(ModuleBase_IWorkshop* theWorkshop, const CompositeFeaturePtr& theSketch); + + virtual ~PartSet_ExternalPointsMgr(); + +private slots: + /** + * A slot which processes display of object + * \param theObj the displayed object + * \param theAIS its presentation + */ + void onDisplayObject(ObjectPtr theObj, AISObjectPtr theAIS); + + /** + * A slot which processes erase of object + * \param theObj the displayed object + * \param theAIS its presentation + */ + void onEraseObject(ObjectPtr theObj, AISObjectPtr theAIS); + +private: + /** + * Returns list of presentations which have displayed shapes with circular edges + * (circles, arcs) which are in pane of of the given sketch + * \param theSketch - the sketch + */ + QList> findCircularEdgesInPlane(); + + /// Creates presentations of centers + void updateCenterPresentations(); + + /// Returns plane of the current sketch + GeomPlanePtr plane() const; + + bool isSketchObject(const ObjectPtr& theRes) const; + +private: + ModuleBase_IWorkshop* myWorkshop; + CompositeFeaturePtr mySketch; + + typedef QList ListOfAIS; + + QMap myPresentations; +}; + +#endif \ No newline at end of file diff --git a/src/PartSet/PartSet_SketcherMgr.cpp b/src/PartSet/PartSet_SketcherMgr.cpp index 9f8e4cf21..4fe035efd 100755 --- a/src/PartSet/PartSet_SketcherMgr.cpp +++ b/src/PartSet/PartSet_SketcherMgr.cpp @@ -12,6 +12,7 @@ #include "PartSet_WidgetSketchLabel.h" #include "PartSet_WidgetEditor.h" #include "PartSet_ResultSketchPrs.h" +#include "PartSet_ExternalPointsMgr.h" #include #include @@ -138,7 +139,7 @@ PartSet_SketcherMgr::PartSet_SketcherMgr(PartSet_Module* theModule) : QObject(theModule), myModule(theModule), myIsEditLaunching(false), myIsDragging(false), myDragDone(false), myIsMouseOverWindow(false), myIsMouseOverViewProcessed(true), myPreviousUpdateViewerEnabled(true), - myIsPopupMenuActive(false) + myIsPopupMenuActive(false), myExternalPointsMgr(0) { ModuleBase_IWorkshop* anIWorkshop = myModule->workshop(); ModuleBase_IViewer* aViewer = anIWorkshop->viewer(); @@ -985,6 +986,8 @@ void PartSet_SketcherMgr::startSketch(ModuleBase_Operation* theOperation) // plane filter if (aPln.get()) aConnector->activateModuleSelectionModes(); + + myExternalPointsMgr = new PartSet_ExternalPointsMgr(myModule->workshop(), myCurrentSketch); } void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) @@ -994,6 +997,11 @@ void PartSet_SketcherMgr::stopSketch(ModuleBase_Operation* theOperation) myIsConstraintsShown[PartSet_Tools::Dimensional] = true; myIsConstraintsShown[PartSet_Tools::Expressions] = false; + if (myExternalPointsMgr) { + delete myExternalPointsMgr; + myExternalPointsMgr = 0; + } + XGUI_ModuleConnector* aConnector = dynamic_cast(myModule->workshop()); DataPtr aData = myCurrentSketch->data(); diff --git a/src/PartSet/PartSet_SketcherMgr.h b/src/PartSet/PartSet_SketcherMgr.h index b1ab8cb4c..078901ca5 100644 --- a/src/PartSet/PartSet_SketcherMgr.h +++ b/src/PartSet/PartSet_SketcherMgr.h @@ -36,6 +36,7 @@ class ModuleBase_ModelWidget; class ModuleBase_Operation; class XGUI_OperationMgr; class XGUI_Workshop; +class PartSet_ExternalPointsMgr; class AIS_InteractiveObject; @@ -418,6 +419,8 @@ private: bool myPreviousUpdateViewerEnabled; QMap myIsConstraintsShown; + + PartSet_ExternalPointsMgr* myExternalPointsMgr; }; -- 2.39.2